org.apache.ddlutils.model.Column Java Examples

The following examples show how to use org.apache.ddlutils.model.Column. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MSSqlModelComparator.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Returns all columns that are changed in a way that makes it necessary to recreate foreign keys and
 * indexes using them.
 *  
 * @param sourceTable The source table
 * @param targetTable The target table
 * @return The columns (from the target table)
 */
private List getRelevantChangedColumns(Table sourceTable, Table targetTable)
{
    List result = new ArrayList();

    for (int columnIdx = 0; columnIdx < targetTable.getColumnCount(); columnIdx++)
    {
        Column targetColumn = targetTable.getColumn(columnIdx);
        Column sourceColumn = sourceTable.findColumn(targetColumn.getName(), isCaseSensitive());

        if (sourceColumn != null)
        {
            int targetTypeCode = getPlatformInfo().getTargetJdbcType(targetColumn.getTypeCode());

            if ((targetTypeCode != sourceColumn.getTypeCode()) ||
                ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn))
            {
                result.add(targetColumn);
            }
        }
    }
    return result;
}
 
Example #2
Source File: SybaseBuilder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the SQL to set the default value of the given column.
 * 
 * @param table           The table
 * @param column          The column to change
 * @param newDefaultValue The new default value
 */
public void changeColumnDefaultValue(Table table, Column column, String newDefaultValue) throws IOException
{
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("REPLACE ");
    printIdentifier(getColumnName(column));
    print(" DEFAULT ");
    if (isValidDefaultValue(newDefaultValue, column.getTypeCode()))
    {
        printDefaultValue(newDefaultValue, column.getTypeCode());
    }
    else
    {
        print("NULL");
    }
    printEndOfStatement();
}
 
Example #3
Source File: SapDbPlatform.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the change of the primary key of a table.
 * 
 * @param currentModel The current database schema
 * @param params       The parameters used in the creation of new tables. Note that for existing
 *                     tables, the parameters won't be applied
 * @param change       The change object
 */
public void processChange(Database           currentModel,
                          CreationParameters params,
                          PrimaryKeyChange   change) throws IOException
{
    Table    changedTable     = findChangedTable(currentModel, change);
    String[] newPKColumnNames = change.getNewPrimaryKeyColumns();
    Column[] newPKColumns     = new Column[newPKColumnNames.length];

    for (int colIdx = 0; colIdx < newPKColumnNames.length; colIdx++)
    {
        newPKColumns[colIdx] = changedTable.findColumn(newPKColumnNames[colIdx], isDelimitedIdentifierModeOn());
    }
    
    ((SapDbBuilder)getSqlBuilder()).dropPrimaryKey(changedTable);
    getSqlBuilder().createPrimaryKey(changedTable, newPKColumns);
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}
 
Example #4
Source File: SapDbBuilder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the SQL to set the required status of the given column.
 * 
 * @param table      The table
 * @param column     The column to change
 * @param isRequired Whether the column shall be required
 */
public void changeColumnRequiredStatus(Table table, Column column, boolean isRequired) throws IOException
{
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("COLUMN ");
    printIdentifier(getColumnName(column));
    if (isRequired)
    {
        print(" NOT NULL");
    }
    else
    {
        print(" DEFAULT NULL");
    }
    printEndOfStatement();
}
 
Example #5
Source File: InterbasePlatform.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the addition of a column to a table.
 * 
 * @param currentModel The current database schema
 * @param params       The parameters used in the creation of new tables. Note that for existing
 *                     tables, the parameters won't be applied
 * @param change       The change object
 */
public void processChange(Database           currentModel,
                          CreationParameters params,
                          AddColumnChange    change) throws IOException
{
    Table  changedTable = findChangedTable(currentModel, change);
    Column prevColumn   = null;

    if (change.getPreviousColumn() != null)
    {
        prevColumn = changedTable.findColumn(change.getPreviousColumn(), isDelimitedIdentifierModeOn());
    }
    ((InterbaseBuilder)getSqlBuilder()).insertColumn(currentModel,
                                                     changedTable,
                                                     change.getNewColumn(),
                                                     prevColumn);
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}
 
Example #6
Source File: ColumnOrderChange.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void apply(Database database, boolean caseSensitive)
{
    Table     table      = findChangedTable(database, caseSensitive);
    ArrayList newColumns = new ArrayList();

    for (int idx = 0; idx < table.getColumnCount(); idx++)
    {
         newColumns.add(table.getColumn(idx));
    }        
    for (int idx = 0; idx < table.getColumnCount(); idx++)
    {
        Column column = table.getColumn(idx);
        int    newPos = getNewPosition(column.getName(), caseSensitive);

        if (newPos >= 0)
        {
            newColumns.set(newPos, column);
        }
    }
    table.removeAllColumns();
    table.addColumns(newColumns);
}
 
Example #7
Source File: SybasePlatform.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the change of a column definition..
 * 
 * @param currentModel The current database schema
 * @param params       The parameters used in the creation of new tables. Note that for existing
 *                     tables, the parameters won't be applied
 * @param change       The change object
 */
public void processChange(Database               currentModel,
                          CreationParameters     params,
                          ColumnDefinitionChange change) throws IOException
{
    Table         changedTable  = findChangedTable(currentModel, change);
    Column        changedColumn = changedTable.findColumn(change.getChangedColumn(), isDelimitedIdentifierModeOn());
    Column        newColumn     = change.getNewColumn();
    SybaseBuilder sqlBuilder    = (SybaseBuilder)getSqlBuilder();

    // if we only change the default value, then we need to use different SQL
    if (!ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), changedColumn, newColumn) &&
        !ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), changedColumn, newColumn) &&
        !ColumnDefinitionChange.isRequiredStatusChanged(changedColumn, newColumn) &&
        !ColumnDefinitionChange.isAutoIncrementChanged(changedColumn, newColumn))
    {
        sqlBuilder.changeColumnDefaultValue(changedTable, changedColumn, newColumn.getDefaultValue());
    }
    else
    {
        sqlBuilder.changeColumn(changedTable, changedColumn, newColumn);
    }
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}
 
Example #8
Source File: FirebirdBuilder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the SQL to add/insert a column.
 * 
 * @param model      The database model
 * @param table      The table
 * @param newColumn  The new column
 * @param prevColumn The column after which the new column shall be added; <code>null</code>
 *                   if the new column is to be inserted at the beginning
 */
public void insertColumn(Database model, Table table, Column newColumn, Column prevColumn) throws IOException
{
    addColumn(model, table, newColumn);

    // column positions start at 1 in Firebird
    int pos = 1;

    if (prevColumn != null)
    {
        pos = table.getColumnIndex(prevColumn) + 2;
    }

    // Even though Firebird can only add columns, we can move them later on
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("ALTER ");
    printIdentifier(getColumnName(newColumn));
    print(" POSITION ");
    print(String.valueOf(pos));
    printEndOfStatement();
}
 
Example #9
Source File: PlatformImplBase.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Processes a change representing the addition of a primary key.
 * 
 * @param currentModel The current database schema
 * @param params       The parameters used in the creation of new tables. Note that for existing
 *                     tables, the parameters won't be applied
 * @param change       The change object
 */
public void processChange(Database            currentModel,
                          CreationParameters  params,
                          AddPrimaryKeyChange change) throws IOException
{
    Table    changedTable  = findChangedTable(currentModel, change);
    String[] pkColumnNames = change.getPrimaryKeyColumns();
    Column[] pkColumns     = new Column[pkColumnNames.length];

    for (int colIdx = 0; colIdx < pkColumns.length; colIdx++)
    {
        pkColumns[colIdx] = changedTable.findColumn(pkColumnNames[colIdx], isDelimitedIdentifierModeOn());
    }
    getSqlBuilder().createPrimaryKey(changedTable, pkColumns);
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}
 
Example #10
Source File: Oracle8Builder.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected String getSqlType(Column column) {
  // convert back to unspecified precision if required
  if (column.getTypeCode() == Types.NUMERIC
      || column.getTypeCode() == Types.DECIMAL) {
    if (column.isUnspecifiedPrecision()) {
      if (column.getScale() == 0) {
        return "NUMBER";
      }
      else {
        return "NUMBER(*," + column.getScale() + ')';
      }
    }
  }
  return super.getSqlType(column);
}
 
Example #11
Source File: MySqlPlatform.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the change of the primary key of a table.
 * 
 * @param currentModel The current database schema
 * @param params       The parameters used in the creation of new tables. Note that for existing
 *                     tables, the parameters won't be applied
 * @param change       The change object
 */
public void processChange(Database           currentModel,
                          CreationParameters params,
                          PrimaryKeyChange   change) throws IOException
{
    Table    changedTable     = findChangedTable(currentModel, change);
    String[] newPKColumnNames = change.getNewPrimaryKeyColumns();
    Column[] newPKColumns     = new Column[newPKColumnNames.length];

    for (int colIdx = 0; colIdx < newPKColumnNames.length; colIdx++)
    {
        newPKColumns[colIdx] = changedTable.findColumn(newPKColumnNames[colIdx], isDelimitedIdentifierModeOn());
    }
    
    ((MySqlBuilder)getSqlBuilder()).dropPrimaryKey(changedTable);
    getSqlBuilder().createPrimaryKey(changedTable, newPKColumns);
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}
 
Example #12
Source File: PostgreSqlModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
{
    Table table = super.readTable(metaData, values);

    if (table != null)
    {
        // PostgreSQL also returns unique indexes for pk and non-pk auto-increment columns
        // which are of the form "[table]_[column]_key"
        HashMap uniquesByName = new HashMap();

        for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++)
        {
            Index index = table.getIndex(indexIdx);

            if (index.isUnique() && (index.getName() != null))
            {
                uniquesByName.put(index.getName(), index);
            }
        }
        for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
        {
            Column column = table.getColumn(columnIdx);

            if (column.isAutoIncrement())
            {
                String indexName = table.getName() + "_" + column.getName() + "_key";

                if (uniquesByName.containsKey(indexName))
                {
                    table.removeIndex((Index)uniquesByName.get(indexName));
                    uniquesByName.remove(indexName);
                }
            }
        }
    }
    return table;
}
 
Example #13
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
     * Outputs the DDL for the specified column.
     * 
     * @param table  The table containing the column
     * @param column The column
     */
    protected void writeColumn(Table table, Column column) throws IOException
    {
        //see comments in columnsDiffer about null/"" defaults
        printIdentifier(getColumnName(column));
        print(" ");
        print(getSqlType(column));
        writeColumnDefaultValueStmt(table, column);
        if (column.isRequired())
        {
            print(" ");
            writeColumnNotNullableStmt();
        }
        else if (getPlatformInfo().isNullAsDefaultValueRequired() &&
                 getPlatformInfo().hasNullDefault(column.getTypeCode()))
        {
            print(" ");
            writeColumnNullableStmt();
        }
// GemStone changes BEGIN
        if (column.isAutoIncrement() &&
            !getPlatformInfo().isDefaultValueUsedForIdentitySpec() &&
            !(getPlatform().isAddIdentityUsingAlterTableOn() &&
                getPlatformInfo().isAddingIdentityUsingAlterTableSupported()))
        /* (original code)
        if (column.isAutoIncrement() && !getPlatformInfo().isDefaultValueUsedForIdentitySpec())
        */
// GemStone changes END
        {
            if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported() && !column.isPrimaryKey())
            {
                throw new ModelException("Column "+column.getName()+" in table "+table.getQualifiedName()+" is auto-incrementing but not a primary key column, which is not supported by the platform");
            }
            print(" ");
            writeColumnAutoIncrementStmt(table, column);
        }
    }
 
Example #14
Source File: MckoiBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void dropTable(Table table) throws IOException
{ 
    print("DROP TABLE IF EXISTS ");
    printIdentifier(getTableName(table));
    printEndOfStatement();

    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        dropAutoIncrementSequence(table, columns[idx]);
    }
}
 
Example #15
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the database-native type for the given column.
 * 
 * @param column The column
 * @return The native type
 */
protected String getNativeType(Column column)
{
    String nativeType = (String)getPlatformInfo().getNativeType(column.getTypeCode());

    return nativeType == null ? column.getType() : nativeType;
}
 
Example #16
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains a '>' character.
 */
public void testTableNameContainsMoreCharacter() throws Exception
{
    String   tableName   = "test>table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table table-name=\"test>table\" id=\"1\" value=\"" + testedValue + "\" />\n" +
                  "</data>\n");
}
 
Example #17
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for columns that have a different in the given source and target table, and applies them
 * to the given intermediate model.
 * 
 * @param sourceModel       The source model
 * @param sourceTable       The source table
 * @param intermediateModel The intermediate model to apply the changes to
 * @param intermediateTable The table from the intermediate model corresponding to the source table
 * @param targetModel       The target model
 * @param targetTable       The target table
 * @return The changes
 */
protected List checkForChangedColumns(Database sourceModel,
                                      Table    sourceTable,
                                      Database intermediateModel,
                                      Table    intermediateTable,
                                      Database targetModel,
                                      Table    targetTable)
{
    List changes = new ArrayList();

    for (int columnIdx = 0; columnIdx < targetTable.getColumnCount(); columnIdx++)
    {
        Column targetColumn = targetTable.getColumn(columnIdx);
        Column sourceColumn = intermediateTable.findColumn(targetColumn.getName(), _caseSensitive);

        if (sourceColumn != null)
        {
            ColumnDefinitionChange change = compareColumns(intermediateTable, sourceColumn, targetTable, targetColumn);

            if (change != null)
            {
                changes.add(change);
                change.apply(intermediateModel, _caseSensitive);
            }
        }
    }
    return changes;
}
 
Example #18
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains a '>' character.
 */
public void testTableNameContainsMoreCharacter() throws Exception
{
    String   tableName   = "test>table";
    Database model       = new Database("test");
    Table    table       = new Table();
    Column   idColumn    = new Column();
    Column   valueColumn = new Column();

    idColumn.setName("id");
    idColumn.setType("INTEGER");
    idColumn.setPrimaryKey(true);
    idColumn.setRequired(true);
    valueColumn.setName("value");
    valueColumn.setType("VARCHAR");
    valueColumn.setSize("50");
    valueColumn.setRequired(true);
    table.setName(tableName);
    table.addColumn(idColumn);
    table.addColumn(valueColumn);
    model.addTable(table);

    SqlDynaBean bean        = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));
    String      testedValue = "Some Text";

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table table-name=\"test>table\" id=\"1\" value=\"" + testedValue + "\" />\n" +
                  "</data>\n");
}
 
Example #19
Source File: DerbyBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException
{
    if (ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn) ||
        ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), sourceColumn, targetColumn))
    {
        String targetNativeType = getNativeType(targetColumn);

        // Derby currently has the limitation that it cannot convert numeric values
        // to VARCHAR, though it can convert them to CHAR
        if (TypeMap.isNumericType(sourceColumn.getTypeCode()) &&
            "VARCHAR".equalsIgnoreCase(targetNativeType))
        {
            targetNativeType = "CHAR";
        }

        print("CAST (");
        printIdentifier(getColumnName(sourceColumn));
        print(" AS ");
        print(getSqlType(targetColumn, targetNativeType));
        print(")");
    }
    else
    {
        printIdentifier(getColumnName(sourceColumn));
    }
}
 
Example #20
Source File: Oracle8Platform.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected TableDefinitionChangesPredicate getTableDefinitionChangesPredicate()
{
    // While Oracle has an ALTER TABLE MODIFY statement, it is somewhat limited
    // esp. if there is data in the table, so we don't use it
    return new DefaultTableDefinitionChangesPredicate()
    {
        protected boolean isSupported(Table intermediateTable, TableChange change)
        {
            if ((change instanceof AddPrimaryKeyChange) ||
                (change instanceof RemovePrimaryKeyChange))
            {
                return true;
            }
            else if (change instanceof RemoveColumnChange)
            {
                // TODO: for now we trigger recreating the table, but ideally we should simply add the necessary pk changes
                RemoveColumnChange removeColumnChange = (RemoveColumnChange)change;
                Column             column             = intermediateTable.findColumn(removeColumnChange.getChangedColumn(), isDelimitedIdentifierModeOn());

                return !column.isPrimaryKey();
            }
            else if (change instanceof AddColumnChange)
            {
                AddColumnChange addColumnChange = (AddColumnChange)change;

                // Oracle can only add not insert columns
                // Also, we cannot add NOT NULL columns unless they have a default value
                return addColumnChange.isAtEnd() &&
                       (!addColumnChange.getNewColumn().isRequired() || (addColumnChange.getNewColumn().getDefaultValue() != null));
            }
            else
            {
                return false;
            }
        }
    };
}
 
Example #21
Source File: MckoiBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void dropTable(Table table) throws IOException
{ 
    print("DROP TABLE IF EXISTS ");
    printIdentifier(getTableName(table));
    printEndOfStatement();

    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        dropAutoIncrementSequence(table, columns[idx]);
    }
}
 
Example #22
Source File: ColumnDefinitionChange.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the default value of the given target column is different from the one of the given source column.
 * This method compares the parsed default values instead of their representations in the columns.
 * 
 * @param sourceColumn The source column
 * @param targetColumn The target column
 * @return <code>true</code> if the default values differ
 */
public static boolean isDefaultValueChanged(Column sourceColumn, Column targetColumn)
{
    Object sourceDefaultValue = sourceColumn.getParsedDefaultValue();
    Object targetDefaultValue = targetColumn.getParsedDefaultValue();

    return ((sourceDefaultValue == null) && (targetDefaultValue != null)) ||
           ((sourceDefaultValue != null) && !sourceDefaultValue.equals(targetDefaultValue));
}
 
Example #23
Source File: MckoiModelReader.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
{
    Column column = super.readColumn(metaData, values);

    if (column.getSize() != null)
    {
        if (column.getSizeAsInt() <= 0)
        {
            column.setSize(null);
        }
    }

    String defaultValue = column.getDefaultValue();

    if (defaultValue != null)
    {
        if (defaultValue.toLowerCase().startsWith("nextval('") ||
            defaultValue.toLowerCase().startsWith("uniquekey('"))
        {
            column.setDefaultValue(null);
            column.setAutoIncrement(true);
        }
        else if (TypeMap.isTextType(column.getTypeCode()))
        {
            column.setDefaultValue(unescape(column.getDefaultValue(), "'", "\\'"));
        }
    }
    return column;
}
 
Example #24
Source File: InterbaseBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the SQL to drop a column.
 * 
 * @param table  The table
 * @param column The column to drop
 */
public void dropColumn(Table table, Column column) throws IOException
{
    if (column.isAutoIncrement())
    {
        writeAutoIncrementDropStmts(table, column);
    }
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("DROP ");
    printIdentifier(getColumnName(column));
    printEndOfStatement();
}
 
Example #25
Source File: InterbaseBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void dropTable(Table table) throws IOException
{
    // dropping generators for auto-increment
    Column[] columns = table.getAutoIncrementColumns();

    for (int idx = 0; idx < columns.length; idx++)
    {
        writeAutoIncrementDropStmts(table, columns[idx]);
    }
    super.dropTable(table);
}
 
Example #26
Source File: MSSqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Generates the SQL to drop a column from a table.
 * 
 * @param table  The table where to drop the column from
 * @param column The column to drop
 */
public void dropColumn(Table table, Column column) throws IOException
{
    if (!StringUtils.isEmpty(column.getDefaultValue()))
    {
        writeDropConstraintStatement(table, column, "D");
    }
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("DROP COLUMN ");
    printIdentifier(getColumnName(column));
    printEndOfStatement();
}
 
Example #27
Source File: InterbaseBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the SQL to drop a column.
 * 
 * @param table  The table
 * @param column The column to drop
 */
public void dropColumn(Table table, Column column) throws IOException
{
    if (column.isAutoIncrement())
    {
        writeAutoIncrementDropStmts(table, column);
    }
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("DROP ");
    printIdentifier(getColumnName(column));
    printEndOfStatement();
}
 
Example #28
Source File: PlatformImplBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Allows the platform to postprocess the model just read from the database.
 * 
 * @param model The model
 */
protected void postprocessModelFromDatabase(Database model)
{
    // Default values for CHAR/VARCHAR/LONGVARCHAR columns have quotation marks
    // around them which we'll remove now
    for (int tableIdx = 0; tableIdx < model.getTableCount(); tableIdx++)
    {
        Table table = model.getTable(tableIdx);

        for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
        {
            Column column = table.getColumn(columnIdx);

            if (TypeMap.isTextType(column.getTypeCode()) ||
                TypeMap.isDateTimeType(column.getTypeCode()))
            {
                String defaultValue = column.getDefaultValue();

                if ((defaultValue != null) && (defaultValue.length() >= 2) &&
                    defaultValue.startsWith("'") && defaultValue.endsWith("'"))
                {
                    defaultValue = defaultValue.substring(1, defaultValue.length() - 1);
                    column.setDefaultValue(defaultValue);
                }
            }
        }
    }
}
 
Example #29
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Write the ALTER TABLE statement to set a given column as a generated
 * identity column. There is no default since this is a non-standard
 * GemFireXD extension.
 */
public void writeAddIdentityColumnUsingAlterTable(Table table,
    Column column) throws IOException {
  if (!getPlatformInfo().isAddingIdentityUsingAlterTableSupported()) {
    throw new ModelException("Platform " + getPlatform()
        + " does not support setting identity column using ALTER TABLE");
  }
}
 
Example #30
Source File: InterbasePlatform.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the removal of a column from a table.
 * 
 * @param currentModel The current database schema
 * @param params       The parameters used in the creation of new tables. Note that for existing
 *                     tables, the parameters won't be applied
 * @param change       The change object
 */
public void processChange(Database           currentModel,
                          CreationParameters params,
                          RemoveColumnChange change) throws IOException
{
    Table  changedTable  = findChangedTable(currentModel, change);
    Column droppedColumn = changedTable.findColumn(change.getChangedColumn(), isDelimitedIdentifierModeOn());

    ((InterbaseBuilder)getSqlBuilder()).dropColumn(changedTable, droppedColumn);
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}