org.codehaus.modello.generator.database.sql
public class SqlBuilder extends Object
Version: $Revision: 149 $
Constructor Summary | |
---|---|
SqlBuilder() |
Method Summary | |
---|---|
void | alterColumn(Table table, Column column, boolean add)
Generates the alter statement to add or modify a single column on a table.
|
protected boolean | columnsDiffer(Column desired, Column current)
Helper method to determine if two column specifications represent
different types. |
void | createColumn(Table table, Column column)
Outputs the DDL to add a column to a table. |
void | createDatabase(Database database)
Outputs the DDL required to drop and recreate the database |
void | createDatabase(Database database, boolean dropTable)
Outputs the DDL required to drop and recreate the database |
void | createTable(Table table)
Outputs the DDL to create the table along with any constraints |
void | dropColumn(Table table, Column column)
Generates the statement to drop an column from a table.
|
void | dropDatabase(Database database)
Outputs the DDL required to drop the database |
void | dropIndex(Table table, Index index)
Generates the statement to drop an index from the database. |
void | dropTable(Table table)
Outputs the DDL to drop the table |
String | getIndent() |
protected String | getNativeType(Column column) |
protected String | getSqlType(Column column) |
Writer | getWriter() |
boolean | isForeignKeyConstraintsNamed()
Returns whether foreign key constraints should be named when they are embedded inside
a create table clause.
|
boolean | isForeignKeysEmbedded() |
boolean | isIndexesEmbedded() |
boolean | isPrimaryKeyEmbedded() |
protected void | print(String text)
Prints some text |
protected void | printAutoIncrementColumn(Table table, Column column)
Outputs the fact that this column is an auto increment column. |
protected void | printComment(String text)
Prints an SQL comment to the current stream |
protected void | printEndOfStatement()
Prints the end of statement text, which is typically a semi colon followed by
a carriage return |
protected void | printIndent()
Prints the indentation used to indent SQL |
protected void | println()
Prints a new line |
protected void | println(String text)
Prints some text then a newline |
protected void | printNotNullable()
Prints that a column is not nullable |
protected void | printNullable()
Prints that a column is nullable |
void | setAlterTableForDrop(boolean alterTableForDrop)
Whether an ALTER TABLE statement is necessary when dropping indexes
or constraints. |
void | setForeignKeyConstraintsNamed(boolean foreignKeyConstraintsNamed)
Sets whether foreign key constraints should be named when they are embedded inside
a create table clause.
|
void | setForeignKeysEmbedded(boolean foreignKeysEmbedded)
Sets whether the foreign key constraints are embedded in the create
table clause or as a seperate alter table statements.
|
void | setIndent(String indent)
Sets the indentation used to indent the SQL |
void | setIndexesEmbedded(boolean indexesEmbedded)
Sets whether the indexes are embedded in the create
table clause or as seperate statements.
|
void | setPrimaryKeyEmbedded(boolean primaryKeyEmbedded)
Sets whether the primary key constraint is embedded in the create
table clause or as a seperate alter table.
|
void | setWriter(Writer writer)
Sets the writer used to print the DDL to |
protected boolean | shouldGeneratePrimaryKeys(List primaryKeyColumns) |
void | tableComment(Table table)
Outputs a comment for the table |
boolean | useAlterTableForDrop()
Whether an ALTER TABLE statement is necessary when dropping indexes
or constraints. |
protected void | writeAlterHeader(Table table)
Generates the first part of the ALTER TABLE statement including the
table name.
|
protected void | writeColumnTypes(Table table)
Writes the column types for a table |
protected void | writeEmbeddedIndexes(Table table)
Writes the indexes embedded within the create table statement. not
yet implemented |
protected void | writeForeignKeyAlterTable(Table table, ForeignKey key) |
protected void | writeForeignKeys(Table table)
Writes the foreign key constraints inside a create table () clause. |
protected void | writeForeignKeysAlterTable(Table table)
Writes the foreign key constraints as an AlterTable clause. |
protected void | writeForeignReferences(ForeignKey key)
Writes a list of foreign references for the given key |
protected void | writeIndex(Table table, Index index)
Writes one index for a table |
protected void | writeIndexes(Table table)
Writes the indexes. |
protected void | writeLocalReferences(ForeignKey key)
Writes a list of local references for the givek key |
protected void | writePrimaryKeys(Table table)
Writes the primary key constraints inside a create table () clause. |
protected void | writePrimaryKeysAlterTable(Table table)
Writes the primary key constraints as an AlterTable clause. |
protected void | writePrimaryKeyStatement(List primaryKeyColumns)
Writes the 'PRIMARY KEY(A,B,...,N)' statement |
Parameters: table The table the index is on column The column to drop add true if the column is new, false if it is to be changed
Throws: IOException if the statement cannot be written
Parameters: desired First column to compare current Second column to compare
Returns: true if the columns differ
Parameters: table The table the index is on column The column to drop
Throws: IOException if the statement cannot be written
alterTableForDrop
property is checked to determine what
style of drop is generated.
Parameters: table The table the index is on index The index to drop
Throws: IOException if the statement cannot be written
See Also: SqlBuilder
Returns: the indentation used to indent the SQL
Returns: the full SQL type string including the size
Returns: the Writer used to print the DDL to
Returns: boolean
Returns: whether the foreign key constraints are embedded in the create table clause or as a seperate alter table statements. The default is false.
Returns: whether the indexes are embedded in the create table clause or as seperate statements. The default is false.
Returns: whether the primary key constraint is embedded in the create table clause or as a seperate alter table. The default is true.
Parameters: alterTableForDrop The new value
Parameters: foreignKeyConstraintsNamed The foreignKeyConstraintsNamed to set
Returns: true if we should generate a primary key constraint for the given primary key columns. By default if there are no primary keys or the column(s) are all auto increment (identity) columns then there is no need to generate a primary key constraint.
Returns: true if ALTER TABLE is required
Parameters: table The table being altered
Throws: IOException if the statement cannot be written