Class AbstractDdlBuilder

java.lang.Object
org.jumpmind.db.platform.AbstractDdlBuilder
All Implemented Interfaces:
IDdlBuilder
Direct Known Subclasses:
AseDdlBuilder, CassandraDdlBuilder, Db2DdlBuilder, DerbyDdlBuilder, FirebirdDdlBuilder, GenericJdbcDdlBuilder, H2DdlBuilder, HanaDdlBuilder, HbaseDdlBuilder, HsqlDb2DdlBuilder, HsqlDbDdlBuilder, InformixDdlBuilder, IngresDdlBuilder, InterbaseDdlBuilder, KafkaDdlBuilder, MsSql2000DdlBuilder, MySqlDdlBuilder, NuoDbDdlBuilder, OracleDdlBuilder, PostgreSqlDdlBuilder, RaimaDdlBuilder, RedshiftDdlBuilder, SqlAnywhereDdlBuilder, SqliteDdlBuilder, VoltDbDdlBuilder

public abstract class AbstractDdlBuilder extends Object implements IDdlBuilder
This class is a collection of Strategy methods for creating the DDL required to create and drop databases and tables. It is hoped that just a single implementation of this class, for each database should make creating DDL for each physical database fairly straightforward. An implementation of this class can always delegate down to some templating technology such as Velocity if it requires. Though often that can be quite complex when attempting to reuse code across many databases. Hopefully only a small amount code needs to be changed on a per database basis.
  • Field Details

    • SIZE_PLACEHOLDER

      protected static final String SIZE_PLACEHOLDER
      The placeholder for the size value in the native type spec.
      See Also:
    • log

      protected final org.slf4j.Logger log
      The Log to which logging calls will be made.
    • databaseInfo

      protected DatabaseInfo databaseInfo
    • delimitedIdentifierModeOn

      protected boolean delimitedIdentifierModeOn
    • caseSensitive

      protected boolean caseSensitive
    • sqlCommentsOn

      protected boolean sqlCommentsOn
    • scriptModeOn

      protected boolean scriptModeOn
    • databaseName

      protected String databaseName
  • Constructor Details

    • AbstractDdlBuilder

      public AbstractDdlBuilder(String databaseName)
      Creates a new sql builder.
  • Method Details

    • getDefaultValueHelper

      public DefaultValueHelper getDefaultValueHelper()
      Returns the default value helper.
      Returns:
      The default value helper
    • getIndent

      public String getIndent()
      Returns the string used to indent the SQL.
      Returns:
      The indentation string
    • setIndent

      public void setIndent(String indent)
      Sets the string used to indent the SQL.
      Parameters:
      indent - The indentation string
    • getValueLocale

      public String getValueLocale()
      Returns the locale that is used for number and date formatting (when printing default values and in generates insert/update/delete statements).
      Returns:
      The locale or null if default formatting is used
    • setValueLocale

      public void setValueLocale(String localeStr)
      Sets the locale that is used for number and date formatting (when printing default values and in generates insert/update/delete statements).
      Parameters:
      localeStr - The new locale or null if default formatting should be used; Format is "language[_country[_variant]]"
    • getValueDateFormat

      protected DateFormat getValueDateFormat()
      Returns the format object for formatting dates in the specified locale.
      Returns:
      The date format object or null if no locale is set
    • setValueDateFormat

      protected void setValueDateFormat(DateFormat format)
      Sets the format object for formatting dates in the specified locale.
      Parameters:
      format - The date format object
    • getValueTimeFormat

      protected DateFormat getValueTimeFormat()
      Returns the format object for formatting times in the specified locale.
      Returns:
      The time format object or null if no locale is set
    • setValueTimeFormat

      protected void setValueTimeFormat(DateFormat format)
      Sets the date format object for formatting times in the specified locale.
      Parameters:
      format - The time format object
    • getValueNumberFormat

      protected NumberFormat getValueNumberFormat()
      Returns the format object for formatting numbers in the specified locale.
      Returns:
      The number format object or null if no locale is set
    • setValueNumberFormat

      protected void setValueNumberFormat(NumberFormat format)
      Returns a new date format object for formatting numbers in the specified locale. Platforms can override this if necessary.
      Parameters:
      format - The number format object
    • addEscapedCharSequence

      protected final void addEscapedCharSequence(String charSequence, String escapedVersion)
      Adds a char sequence that needs escaping, and its escaped version.
      Parameters:
      charSequence - The char sequence
      escapedVersion - The escaped version
    • createTables

      public String createTables(Database database, boolean dropTables)
      Specified by:
      createTables in interface IDdlBuilder
    • createTables

      public void createTables(Database database, boolean dropTables, StringBuilder ddl)
      Outputs the DDL required to drop (if requested) and (re)create all tables in the database model.
    • alterDatabase

      public String alterDatabase(Database currentModel, Database desiredModel, IAlterDatabaseInterceptor... alterDatabaseInterceptors)
      Specified by:
      alterDatabase in interface IDdlBuilder
    • alterTable

      public String alterTable(Table currentTable, Table desiredTable, IAlterDatabaseInterceptor... alterDatabaseInterceptors)
      Specified by:
      alterTable in interface IDdlBuilder
    • mergeOrRemovePlatformTypes

      protected void mergeOrRemovePlatformTypes(Database currentModel, Database desiredModel)
    • alterDatabase

      public void alterDatabase(Database currentModel, Database desiredModel, StringBuilder ddl, IAlterDatabaseInterceptor... alterDatabaseInterceptors)
      Generates the DDL to modify an existing database so the schema matches the specified database schema by using drops, modifications and additions. Database-specific implementations can change aspect of this algorithm by redefining the individual methods that compromise it.
    • isAlterDatabase

      public boolean isAlterDatabase(Database currentModel, Database desiredModel, IAlterDatabaseInterceptor... alterDatabaseInterceptors)
      Specified by:
      isAlterDatabase in interface IDdlBuilder
    • getDetectedChanges

      public List<IModelChange> getDetectedChanges(Database currentModel, Database desiredModel, IAlterDatabaseInterceptor... alterDatabaseInterceptors)
      Specified by:
      getDetectedChanges in interface IDdlBuilder
    • processChanges

      protected void processChanges(Database currentModel, Database desiredModel, List<IModelChange> changes, StringBuilder ddl)
      Processes the changes. The default argument performs several passes:
      1. RemoveForeignKeyChange and RemoveIndexChange come first to allow for e.g. subsequent primary key changes or column removal.
      2. RemoveTableChange comes after the removal of foreign keys and indices.
      3. These are all handled together:
        RemovePrimaryKeyChange
        AddPrimaryKeyChange
        PrimaryKeyChange
        RemoveColumnChange
        AddColumnChange
        ColumnAutoIncrementChange
        ColumnDefaultValueChange
        ColumnRequiredChange
        ColumnDataTypeChange
        ColumnSizeChange
        The reason for this is that the default algorithm rebuilds the table for these changes and thus their order is irrelevant.
      4. AddTableChange
        needs to come after the table removal (so that tables of the same name are removed) and before the addition of foreign keys etc.
      5. AddForeignKeyChange and AddIndexChange come last after table/column/primary key additions or changes.
      6. RemoveTriggerChange come after the tables are completely built.
      7. AddTriggerChange is done last.
    • processChanges

      protected void processChanges(Database currentModel, Database desiredModel, List<IModelChange> changes, StringBuilder ddl, Class<?>[] changeTypes)
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, IModelChange change, StringBuilder ddl)
      This is a fall-through callback which generates a warning because a specific change type wasn't handled.
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, AddTableLoggingChange change, StringBuilder ddl)
      Punt change representing the removal of a foreign key to a database-specific override.
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, RemoveTableLoggingChange change, StringBuilder ddl)
      Punt change representing the removal of a foreign key to a database-specific override.
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, RemoveForeignKeyChange change, StringBuilder ddl)
      Processes the change representing the removal of a foreign key.
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, RemoveIndexChange change, StringBuilder ddl)
      Processes the change representing the removal of an index.
      Parameters:
      currentModel - The current database schema
      desiredModel - The desired database schema
      change - The change object
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, RemoveTableChange change, StringBuilder ddl)
      Processes the change representing the removal of a table.
      Parameters:
      currentModel - The current database schema
      desiredModel - The desired database schema
      change - The change object
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, AddTableChange change, StringBuilder ddl)
      Processes the change representing the addition of a table.
      Parameters:
      currentModel - The current database schema
      desiredModel - The desired database schema
      change - The change object
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, AddForeignKeyChange change, StringBuilder ddl)
      Processes the change representing the addition of a foreign key.
      Parameters:
      currentModel - The current database schema
      desiredModel - The desired database schema
      change - The change object
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, AddIndexChange change, StringBuilder ddl)
      Processes the change representing the addition of an index.
      Parameters:
      currentModel - The current database schema
      desiredModel - The desired database schema
      change - The change object
    • filterChanges

      protected void filterChanges(Collection<IModelChange> changes)
    • processTableStructureChanges

      protected void processTableStructureChanges(Database currentModel, Database desiredModel, Collection<IModelChange> changes, StringBuilder ddl)
      Processes the changes to the structure of tables.
      Parameters:
      currentModel - The current database schema
      desiredModel - The desired database schema
      changes - The change objects
    • findTable

      protected Table findTable(Database currentModel, String tableName)
    • findForeignKey

      protected ForeignKey findForeignKey(Table table, ForeignKey fk)
    • processTableStructureChanges

      protected void processTableStructureChanges(Database currentModel, Database desiredModel, String tableName, List<TableChange> changes, StringBuilder ddl)
      Processes the changes to the structure of a single table. Database-specific implementations might redefine this method, but it is usually sufficient to redefine the #processTableStructureChanges(Database, Database, Table, Table, Map, List) method instead.
    • renameTable

      protected void renameTable(Table sourceTable, Table tempTable, StringBuilder ddl)
    • copy

      protected Database copy(Database currentModel)
    • processTableStructureChanges

      protected void processTableStructureChanges(Database currentModel, Database desiredModel, Table sourceTable, Table targetTable, List<TableChange> changes, StringBuilder ddl)
      Allows database-specific implementations to handle changes in a database specific manner. Any handled change should be applied to the given current model (which is a copy of the real original model) and be removed from the list of changes.
      In the default implementation, all AddPrimaryKeyChange changes are applied via an ALTER TABLE ADD CONSTRAINT statement.
      Parameters:
      currentModel - The current database schema
      desiredModel - The desired database schema
      sourceTable - The original table
      targetTable - The desired table
      changes - The change objects for the target table
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, CopyColumnValueChange change, StringBuilder ddl)
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, RemoveTriggerChange change, StringBuilder ddl)
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, AddTriggerChange change, StringBuilder ddl)
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, RemoveFunctionChange change, StringBuilder ddl)
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, AddFunctionChange change, StringBuilder ddl)
    • replaceDelimiterWithEscapeCharacters

      protected String replaceDelimiterWithEscapeCharacters(String triggerText)
    • writeAlterColumnDataTypeToBigInt

      protected boolean writeAlterColumnDataTypeToBigInt(ColumnDataTypeChange change, StringBuilder ddl)
    • getFullyQualifiedTableNameShorten

      protected String getFullyQualifiedTableNameShorten(Table table)
      The fully qualified table name shorten
    • getTemporaryTableFor

      protected Table getTemporaryTableFor(Table targetTable)
      Creates a temporary table object that corresponds to the given table. Database-specific implementations may redefine this method if e.g. the database directly supports temporary tables. The default implementation simply appends an underscore to the table name and uses that as the table name.
      Parameters:
      targetTable - The target table
      Returns:
      The temporary table
    • getBackupTableFor

      public Table getBackupTableFor(Table sourceTable)
    • createBackupTableFor

      public Table createBackupTableFor(Database model, Table sourceTable, StringBuilder ddl)
    • restoreTableFromBackup

      public void restoreTableFromBackup(Table backupTable, Table targetTable, LinkedHashMap<Column,Column> columnMap, StringBuilder ddl)
    • getTemporaryTableFor

      protected Table getTemporaryTableFor(Table targetTable, String suffix)
    • createTemporaryTable

      protected void createTemporaryTable(Table table, StringBuilder ddl)
      Outputs the DDL to create the given temporary table. Per default this is simply a call to #createTable(Table, Map).
      Parameters:
      table - The table
    • dropTemporaryTable

      protected void dropTemporaryTable(Table table, StringBuilder ddl)
      Outputs the DDL to drop the given temporary table. Per default this is simply a call to #dropTable(Table).
      Parameters:
      table - The table
    • getRealTargetTableFor

      protected Table getRealTargetTableFor(Database targetModel, Table sourceTable, Table targetTable)
      Creates the target table object that differs from the given target table only in the indices. More specifically, only those indices are used that have not changed.
      Parameters:
      targetModel - The target database
      sourceTable - The source table
      targetTable - The target table
      Returns:
      The table
    • writeCopyDataStatement

      public void writeCopyDataStatement(Table sourceTable, Table targetTable, StringBuilder ddl)
      Writes a statement that copies the data from the source to the target table. Note that this copies only those columns that are in both tables. Database-specific implementations might redefine this method though they usually it suffices to redefine the #writeCastExpression(Column, Column) method.
      Parameters:
      sourceTable - The source table
      targetTable - The target table
    • writeCopyDataStatement

      public void writeCopyDataStatement(Table sourceTable, Table targetTable, LinkedHashMap<Column,Column> columnMap, StringBuilder ddl)
    • getCopyDataColumnMapping

      public LinkedHashMap<Column,Column> getCopyDataColumnMapping(Table sourceTable, Table targetTable)
    • getCopyDataColumnOrderedMapping

      public LinkedHashMap<Column,Column> getCopyDataColumnOrderedMapping(Table sourceTable, Table targetTable)
    • writeCastExpression

      protected void writeCastExpression(Column sourceColumn, Column targetColumn, StringBuilder ddl)
      Writes a cast expression that converts the value of the source column to the data type of the target column. Per default, simply the name of the source column is written thereby assuming that any casts happen implicitly.
    • processChange

      protected void processChange(Database currentModel, Database desiredModel, AddPrimaryKeyChange change, StringBuilder ddl)
      Processes the addition of a primary key to a table.
    • findCorrespondingForeignKey

      protected ForeignKey findCorrespondingForeignKey(Table table, ForeignKey fk)
      Searches in the given table for a corresponding foreign key. If the given key has no name, then a foreign key to the same table with the same columns in the same order is searched. If the given key has a name, then the a corresponding key also needs to have the same name, or no name at all, but not a different one.
      Parameters:
      table - The table to search in
      fk - The original foreign key
      Returns:
      The corresponding foreign key if found
    • areEqual

      protected boolean areEqual(String string1, String string2, boolean caseMatters)
      Compares the two strings.
      Parameters:
      string1 - The first string
      string2 - The second string
      caseMatters - Whether case matters in the comparison
      Returns:
      true if the string are equal
    • createTable

      public String createTable(Table table)
      Outputs the DDL to create the table along with any non-external constraints as well as with external primary keys and indices (but not foreign keys).
      Specified by:
      createTable in interface IDdlBuilder
    • createTable

      protected void createTable(Table table, StringBuilder ddl, boolean temporary, boolean recreate)
      Outputs the DDL to create the table along with any non-external constraints as well as with external primary keys and indices (but not foreign keys).
      Parameters:
      recreate - TODO
    • createExternalForeignKeys

      public void createExternalForeignKeys(Database database, StringBuilder ddl)
      Creates the external foreignkey creation statements for all tables in the database.
      Parameters:
      database - The database
    • createExternalForeignKeys

      public void createExternalForeignKeys(Database database, Table table, StringBuilder ddl)
      Creates external foreign key creation statements if necessary.
    • dropTables

      public String dropTables(Database database)
      Specified by:
      dropTables in interface IDdlBuilder
    • dropTables

      public void dropTables(Database database, StringBuilder ddl)
      Outputs the DDL required to drop the database.
    • dropTable

      public void dropTable(Database database, Table table, StringBuilder ddl)
      Outputs the DDL required to drop the given table. This method also drops foreign keys to the table.
    • dropTable

      protected void dropTable(Table table, StringBuilder ddl, boolean temporary, boolean recreate)
      Outputs the DDL to drop the table. Note that this method does not drop foreign keys to this table. Use #dropTable(Database, Table) if you want that.
      Parameters:
      recreate - TODO
    • dropExternalForeignKeys

      public void dropExternalForeignKeys(Table table, StringBuilder ddl)
      Creates external foreign key drop statements.
      Parameters:
      table - The table
    • getInsertSql

      public String getInsertSql(Table table, Map<String,Object> columnValues, boolean genPlaceholders)
      Creates the SQL for inserting an object into the specified table. If values are given then a concrete insert statement is created, otherwise an insert statement usable in a prepared statement is build.
      Parameters:
      table - The table
      columnValues - The columns values indexed by the column names
      genPlaceholders - Whether to generate value placeholders for a prepared statement
      Returns:
      The insertion sql
    • getUpdateSql

      public String getUpdateSql(Table table, Map<String,Object> columnValues, boolean genPlaceholders)
      Creates the SQL for updating an object in the specified table. If values are given then a concrete update statement is created, otherwise an update statement usable in a prepared statement is build.
      Parameters:
      table - The table
      columnValues - Contains the values for the columns to update, and should also contain the primary key values to identify the object to update in case genPlaceholders is false
      genPlaceholders - Whether to generate value placeholders for a prepared statement (both for the pk values and the object values)
      Returns:
      The update sql
    • getDeleteSql

      public String getDeleteSql(Table table, Map<String,Object> pkValues, boolean genPlaceholders)
      Creates the SQL for deleting an object from the specified table. If values are given then a concrete delete statement is created, otherwise an delete statement usable in a prepared statement is build.
      Parameters:
      table - The table
      pkValues - The primary key values indexed by the column names, can be empty
      genPlaceholders - Whether to generate value placeholders for a prepared statement
      Returns:
      The delete sql
    • getValueAsString

      protected String getValueAsString(Column column, Object value)
      Generates the string representation of the given value.
      Parameters:
      column - The column
      value - The value
      Returns:
      The string representation
    • getSelectLastIdentityValues

      public String getSelectLastIdentityValues(Table table)
      Generates the SQL for querying the id that was created in the last insertion operation. This is obviously only useful for pk fields that are auto-incrementing. A database that does not support this, will return null.
      Parameters:
      table - The table
      Returns:
      The sql, or null if the database does not support this
    • fixLastIdentityValues

      public String fixLastIdentityValues(Table table)
      Generates the SQL to execute that sets the current sequence number.
      Parameters:
      table -
      id -
      Returns:
    • writeFixLastIdentityValues

      public void writeFixLastIdentityValues(Table table, StringBuilder ddl)
    • shortenName

      public String shortenName(String name, int desiredLength)
      Generates a version of the name that has at most the specified length.
      Parameters:
      name - The original name
      desiredLength - The desired maximum length
      Returns:
      The shortened version
    • getTableName

      public String getTableName(String tableName)
      Returns the table name. This method takes care of length limitations imposed by some databases.
      Specified by:
      getTableName in interface IDdlBuilder
      Parameters:
      table - The table
      Returns:
      The table name
    • writeTableComment

      protected void writeTableComment(Table table, StringBuilder ddl)
      Outputs a comment for the table.
      Parameters:
      table - The table
    • writeTableAlterStmt

      protected void writeTableAlterStmt(Table table, StringBuilder ddl)
      Generates the first part of the ALTER TABLE statement including the table name.
      Parameters:
      table - The table being altered
    • writeTableCreationStmt

      protected void writeTableCreationStmt(Table table, StringBuilder ddl)
      Writes the table creation statement without the statement end.
    • writeTableCreateOpeningStmt

      protected void writeTableCreateOpeningStmt(Table table, StringBuilder ddl)
      Writes the beginning of the table create statement.
    • writeIdentityGapLimit

      protected void writeIdentityGapLimit(StringBuilder ddl)
      Writes the end of table statement indicating an identity gap maximum value.
    • isSpecifyIdentityGapLimit

      protected static boolean isSpecifyIdentityGapLimit()
      Should the identity gap maximum size be specified in table create statements.
    • getGapLimitSize

      protected static int getGapLimitSize()
      Get the maximum identity gap size from the property.
    • writeTableCreationStmtEnding

      protected void writeTableCreationStmtEnding(Table table, StringBuilder ddl)
      Writes the end of the table creation statement. Per default, only the end of the statement is written, but this can be changed in subclasses.
      Parameters:
      table - The table
    • writeColumns

      protected void writeColumns(Table table, StringBuilder ddl)
      Writes the columns of the given table.
    • getColumnName

      protected String getColumnName(Column column)
      Returns the column name. This method takes care of length limitations imposed by some databases.
      Parameters:
      column - The column
      Returns:
      The column name
    • writeColumnTypeDefaultRequired

      protected void writeColumnTypeDefaultRequired(Table table, Column column, StringBuilder ddl)
    • writeGeneratedColumn

      protected void writeGeneratedColumn(Table table, Column column, StringBuilder ddl)
    • getDefinitionForGeneratedColumn

      protected String getDefinitionForGeneratedColumn(Table table, Column column)
    • getColumnTypeDdl

      public String getColumnTypeDdl(Table table, Column column)
      Specified by:
      getColumnTypeDdl in interface IDdlBuilder
    • writeColumnType

      protected void writeColumnType(Table table, Column column, StringBuilder ddl)
    • writeColumn

      protected void writeColumn(Table table, Column column, StringBuilder ddl)
      Outputs the DDL for the specified column.
    • writeColumnEmbeddedPrimaryKey

      protected void writeColumnEmbeddedPrimaryKey(Table table, Column column, StringBuilder ddl)
    • getSqlType

      public String getSqlType(Column column)
      Returns the full SQL type specification (including size and precision/scale) for the given column.
      Specified by:
      getSqlType in interface IDdlBuilder
      Parameters:
      column - The column
      Returns:
      The full SQL type string including the size
    • hasSize

      protected boolean hasSize(Column column)
    • getSize

      protected Integer getSize(Column column)
    • filterColumnSqlType

      protected void filterColumnSqlType(StringBuilder sqlType)
    • getNativeType

      protected String getNativeType(Column column)
      Returns the database-native type for the given column.
      Parameters:
      column - The column
      Returns:
      The native type
    • getBareNativeType

      protected String getBareNativeType(Column column)
      Returns the bare database-native type for the given column without any size specifies.
      Parameters:
      column - The column
      Returns:
      The native type
    • getNativeDefaultValue

      protected String getNativeDefaultValue(Column column)
      Returns the native default value for the column.
      Parameters:
      column - The column
      Returns:
      The native default value
    • escapeStringValue

      protected String escapeStringValue(String value)
      Escapes the necessary characters in given string value.
      Parameters:
      value - The value
      Returns:
      The corresponding string with the special characters properly escaped
    • isValidDefaultValue

      protected boolean isValidDefaultValue(String defaultSpec, int typeCode)
      Determines whether the given default spec is a non-empty spec that shall be used in a DEFAULT expression. E.g. if the spec is an empty string and the type is a numeric type, then it is no valid default value whereas if it is a string type, then it is valid.
      Parameters:
      defaultSpec - The default value spec
      typeCode - The JDBC type code
      Returns:
      true if the default value spec is valid
    • writeColumnDefaultValueStmt

      protected void writeColumnDefaultValueStmt(Table table, Column column, StringBuilder ddl)
      Prints the default value stmt part for the column.
    • writeColumnDefaultValue

      protected void writeColumnDefaultValue(Table table, Column column, StringBuilder ddl)
      Prints the default value of the column.
    • printDefaultValue

      protected void printDefaultValue(String defaultValue, Column column, StringBuilder ddl)
      Prints the default value of the column.
    • shouldUseQuotes

      protected boolean shouldUseQuotes(String defaultValue, Column column)
    • mapDefaultValue

      public String mapDefaultValue(Object defaultValue, Column column)
      Specified by:
      mapDefaultValue in interface IDdlBuilder
    • writeColumnAutoIncrementStmt

      protected void writeColumnAutoIncrementStmt(Table table, Column column, StringBuilder ddl)
      Prints that the column is an auto increment column.
    • writeColumnAutoUpdateStmt

      protected void writeColumnAutoUpdateStmt(Table table, Column column, StringBuilder ddl)
    • writeColumnNullableStmt

      protected void writeColumnNullableStmt(StringBuilder ddl)
      Prints that a column is nullable.
    • writeColumnNotNullableStmt

      protected void writeColumnNotNullableStmt(StringBuilder ddl)
      Prints that a column is not nullable.
    • writeColumnUniqueStmt

      protected void writeColumnUniqueStmt(StringBuilder ddl)
    • areColumnSizesTheSame

      public boolean areColumnSizesTheSame(Column sourceColumn, Column targetColumn)
      Specified by:
      areColumnSizesTheSame in interface IDdlBuilder
    • areMappedTypesTheSame

      public boolean areMappedTypesTheSame(Column sourceColumn, Column targetColumn)
      Specified by:
      areMappedTypesTheSame in interface IDdlBuilder
    • getForeignKeyName

      public String getForeignKeyName(Table table, ForeignKey fk)
      Returns the name to be used for the given foreign key. If the foreign key has no specified name, this method determines a unique name for it. The name will also be shortened to honor the maximum identifier length imposed by the platform.
      Specified by:
      getForeignKeyName in interface IDdlBuilder
      Parameters:
      table - The table for whith the foreign key is defined
      fk - The foreign key
      Returns:
      The name
    • getConstraintName

      public String getConstraintName(String prefix, Table table, String secondPart, String suffix)
      Returns the constraint name. This method takes care of length limitations imposed by some databases.
      Specified by:
      getConstraintName in interface IDdlBuilder
      Parameters:
      prefix - The constraint prefix, can be null
      table - The table that the constraint belongs to
      secondPart - The second name part, e.g. the name of the constraint column
      suffix - The constraint suffix, e.g. a counter (can be null)
      Returns:
      The constraint name
    • writeEmbeddedPrimaryKeysStmt

      protected void writeEmbeddedPrimaryKeysStmt(Table table, StringBuilder ddl)
      Writes the primary key constraints of the table inside its definition.
      Parameters:
      table - The table
    • writeExternalPrimaryKeysCreateStmt

      protected void writeExternalPrimaryKeysCreateStmt(Table table, Column[] primaryKeyColumns, StringBuilder ddl)
      Writes the primary key constraints of the table as alter table statements.
      Parameters:
      table - The table
      primaryKeyColumns - The primary key columns
    • shouldGeneratePrimaryKeys

      protected boolean shouldGeneratePrimaryKeys(Column[] primaryKeyColumns)
      Determines whether we should generate a primary key constraint for the given primary key columns.
      Parameters:
      primaryKeyColumns - The pk columns
      Returns:
      true if a pk statement should be generated for the columns
    • writePrimaryKeyStmt

      protected void writePrimaryKeyStmt(Table table, Column[] primaryKeyColumns, StringBuilder ddl)
      Writes a primary key statement for the given columns.
      Parameters:
      table - The table
      primaryKeyColumns - The primary columns
    • getIndexName

      public String getIndexName(IIndex index)
      Returns the index name. This method takes care of length limitations imposed by some databases.
      Specified by:
      getIndexName in interface IDdlBuilder
      Parameters:
      index - The index
      Returns:
      The index name
    • writeExternalIndicesCreateStmt

      protected void writeExternalIndicesCreateStmt(Table table, StringBuilder ddl)
      Writes the indexes of the given table.
      Parameters:
      table - The table
    • writeEmbeddedIndicesStmt

      protected void writeEmbeddedIndicesStmt(Table table, StringBuilder ddl)
      Writes the indexes embedded within the create table statement.
    • writeExternalIndexCreateStmt

      protected void writeExternalIndexCreateStmt(Table table, IIndex index, StringBuilder ddl)
      Writes the given index of the table.
    • writeExternalIndexCreate

      protected void writeExternalIndexCreate(Table table, IIndex index, StringBuilder ddl)
    • getFullyQualifiedIndexNameShorten

      protected String getFullyQualifiedIndexNameShorten(Table table, IIndex index)
    • isFullTextIndex

      protected boolean isFullTextIndex(IIndex index)
    • writeEmbeddedIndexCreateStmt

      protected void writeEmbeddedIndexCreateStmt(Table table, IIndex index, StringBuilder ddl)
      Writes the given embedded index of the table.
    • writeExternalIndexDropStmt

      public void writeExternalIndexDropStmt(Table table, IIndex index, StringBuilder ddl)
      Generates the statement to drop a non-embedded index from the database.
    • writeEmbeddedForeignKeysStmt

      protected void writeEmbeddedForeignKeysStmt(Table table, StringBuilder ddl)
      Writes the foreign key constraints inside a create table () clause.
    • writeExternalForeignKeyCreateStmt

      protected void writeExternalForeignKeyCreateStmt(Database database, Table table, ForeignKey key, StringBuilder ddl)
      Writes a single foreign key constraint using a alter table statement.
      Parameters:
      database - The database model
      table - The table
      key - The foreign key
    • writeCascadeAttributesForForeignKey

      protected void writeCascadeAttributesForForeignKey(ForeignKey key, StringBuilder ddl)
    • writeCascadeAttributesForForeignKeyDelete

      protected void writeCascadeAttributesForForeignKeyDelete(ForeignKey key, StringBuilder ddl)
    • writeCascadeAttributesForForeignKeyUpdate

      protected void writeCascadeAttributesForForeignKeyUpdate(ForeignKey key, StringBuilder ddl)
    • writeLocalReferences

      protected void writeLocalReferences(ForeignKey key, StringBuilder ddl)
      Writes a list of local references for the given foreign key.
      Parameters:
      key - The foreign key
    • writeForeignReferences

      protected void writeForeignReferences(ForeignKey key, StringBuilder ddl)
      Writes a list of foreign references for the given foreign key.
      Parameters:
      key - The foreign key
    • writeExternalForeignKeyDropStmt

      protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey, StringBuilder ddl)
      Generates the statement to drop a foreignkey constraint from the database using an alter table statement.
      Parameters:
      table - The table
      foreignKey - The foreign key
    • printComment

      protected void printComment(String text, StringBuilder ddl)
      Prints an SQL comment to the current stream.
      Parameters:
      text - The comment text
    • printStartOfEmbeddedStatement

      protected void printStartOfEmbeddedStatement(StringBuilder ddl)
      Prints the start of an embedded statement.
    • printEndOfStatement

      protected void printEndOfStatement(StringBuilder ddl)
      Prints the end of statement text, which is typically a semi colon followed by a carriage return.
    • println

      protected void println(StringBuilder ddl)
      Prints a newline.
    • getDelimitedIdentifier

      protected String getDelimitedIdentifier(String identifier)
      Returns the delimited version of the identifier (if configured).
      Parameters:
      identifier - The identifier
      Returns:
      The delimited version of the identifier unless the platform is configured to use undelimited identifiers; in that case, the identifier is returned unchanged
    • printIdentifier

      protected void printIdentifier(String identifier, StringBuilder ddl)
      Prints the given identifier. For most databases, this will be a delimited identifier.
      Parameters:
      identifier - The identifier
    • printlnIdentifier

      protected void printlnIdentifier(String identifier, StringBuilder ddl)
      Prints the given identifier followed by a newline. For most databases, this will be a delimited identifier.
      Parameters:
      identifier - The identifier
    • println

      protected void println(String text, StringBuilder ddl)
      Prints some text followed by a newline.
      Parameters:
      text - The text to print
    • printIndent

      protected void printIndent(StringBuilder ddl)
      Prints the characters used to indent SQL.
    • isScriptModeOn

      public boolean isScriptModeOn()
    • setScriptModeOn

      public void setScriptModeOn(boolean scriptModeOn)
    • isSqlCommentsOn

      public boolean isSqlCommentsOn()
    • setSqlCommentsOn

      public void setSqlCommentsOn(boolean sqlCommentsOn)
    • isDelimitedIdentifierModeOn

      public boolean isDelimitedIdentifierModeOn()
      Specified by:
      isDelimitedIdentifierModeOn in interface IDdlBuilder
    • setDelimitedIdentifierModeOn

      public void setDelimitedIdentifierModeOn(boolean delimitedIdentifierModeOn)
      Specified by:
      setDelimitedIdentifierModeOn in interface IDdlBuilder
    • getDatabaseInfo

      public DatabaseInfo getDatabaseInfo()
      Specified by:
      getDatabaseInfo in interface IDdlBuilder
    • setCaseSensitive

      public void setCaseSensitive(boolean caseSensitive)
      Specified by:
      setCaseSensitive in interface IDdlBuilder
    • isCaseSensitive

      public boolean isCaseSensitive()
    • initCteExpression

      public void initCteExpression()
      Specified by:
      initCteExpression in interface IDdlBuilder
    • getTriggerDelimiterReplacementCharacters

      public String getTriggerDelimiterReplacementCharacters()
      Specified by:
      getTriggerDelimiterReplacementCharacters in interface IDdlBuilder
    • setTriggerDelimiterReplacementCharacters

      public void setTriggerDelimiterReplacementCharacters(String triggerDelimiterReplacementCharacters)
      Specified by:
      setTriggerDelimiterReplacementCharacters in interface IDdlBuilder