Java Code Examples for org.apache.ddlutils.model.Column

The following examples show how to use org.apache.ddlutils.model.Column. These examples are extracted from open source projects. 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 Project: gemfirexd-oss   Source File: MySqlPlatform.java    License: 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 2
Source Project: gemfirexd-oss   Source File: Oracle8Builder.java    License: 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 3
Source Project: gemfirexd-oss   Source File: PlatformImplBase.java    License: 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 4
Source Project: gemfirexd-oss   Source File: SapDbBuilder.java    License: 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 Project: gemfirexd-oss   Source File: SapDbPlatform.java    License: 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 6
Source Project: gemfirexd-oss   Source File: MSSqlModelComparator.java    License: 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 7
Source Project: gemfirexd-oss   Source File: SybaseBuilder.java    License: 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 8
Source Project: gemfirexd-oss   Source File: InterbasePlatform.java    License: 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 9
Source Project: gemfirexd-oss   Source File: ColumnOrderChange.java    License: 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 10
Source Project: gemfirexd-oss   Source File: SybasePlatform.java    License: 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 11
Source Project: gemfirexd-oss   Source File: FirebirdBuilder.java    License: 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 12
Source Project: gemfirexd-oss   Source File: PostgreSqlBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public String getSelectLastIdentityValues(Table table)
{
    Column[] columns = table.getAutoIncrementColumns();

    if (columns.length == 0)
    {
        return null;
    }
    else
    {
        StringBuilder result = new StringBuilder();

        result.append("SELECT ");
        for (int idx = 0; idx < columns.length; idx++)
        {
            if (idx > 0)
            {
                result.append(", ");
            }
            result.append("currval('");
            result.append(getDelimitedIdentifier(getConstraintName(null, table, columns[idx].getName(), "seq")));
            result.append("') AS ");
            result.append(getDelimitedIdentifier(columns[idx].getName()));
        }
        return result.toString();
    }
}
 
Example 13
Source Project: gemfirexd-oss   Source File: ColumnDefinitionChange.java    License: 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 14
Source Project: gemfirexd-oss   Source File: InterbaseBuilder.java    License: 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 15
Source Project: gemfirexd-oss   Source File: SybaseBuilder.java    License: 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
{
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("DROP ");
    printIdentifier(getColumnName(column));
    printEndOfStatement();
}
 
Example 16
Source Project: gemfirexd-oss   Source File: AddIndexChange.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void apply(Database model, boolean caseSensitive)
{
    Table table = findChangedTable(model, caseSensitive);

    table.addIndex(_newIndex);
    for (int idx = 0; idx < _newIndex.getColumnCount(); idx++)
    {
        IndexColumn idxColumn = _newIndex.getColumn(idx);
        Column      tmpColumn = idxColumn.getColumn();

        idxColumn.setColumn(table.findColumn(tmpColumn.getName(), caseSensitive));
    }
}
 
Example 17
Source Project: gemfirexd-oss   Source File: RemovePrimaryKeyChange.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void apply(Database model, boolean caseSensitive)
{
    Table    table  = findChangedTable(model, caseSensitive);
    Column[] pkCols = table.getPrimaryKeyColumns();

    for (int idx = 0; idx < pkCols.length; idx++)
    {
        pkCols[idx].setPrimaryKey(false);
    }
}
 
Example 18
Source Project: gemfirexd-oss   Source File: PostgreSqlBuilder.java    License: 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
{
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("DROP COLUMN ");
    printIdentifier(getColumnName(column));
    printEndOfStatement();
    if (column.isAutoIncrement())
    {
        dropAutoIncrementSequence(table, column);
    }
}
 
Example 19
Source Project: gemfirexd-oss   Source File: WriteDataToDatabaseCommand.java    License: Apache License 2.0 5 votes vote down vote up
protected void writeAddIdentityUsingAlterTable(Platform platform,
    Database model) throws DataSinkException {
  // if identity column has to be set using alter table then
  // do it after loading the data
  if (_addIdentityUsingAlterTable && platform.getPlatformInfo()
          .isAddingIdentityUsingAlterTableSupported()) {
    StringWriter buffer = new StringWriter();
  
    SqlBuilder builder = platform.getSqlBuilder();
    builder.setWriter(buffer);
    for (int index = 0; index < model.getTableCount(); index++) {
      Table table = model.getTable(index);
      for (int col = 0; col < table.getColumnCount(); col++) {
        Column column = table.getColumn(col);
        if (column.isAutoIncrement()) {
          try {
            builder.writeAddIdentityColumnUsingAlterTable(table, column);
          } catch (IOException ioe) {
            throw new DataSinkException(ioe);
          }
        }
      }
    }
    String sql = buffer.toString();
    platform.evaluateBatch(sql, false);
  }
}
 
Example 20
Source Project: gemfirexd-oss   Source File: SapDbBuilder.java    License: 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
{
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("DROP ");
    printIdentifier(getColumnName(column));
    print(" RELEASE SPACE");
    printEndOfStatement();
}
 
Example 21
Source Project: gemfirexd-oss   Source File: ModelComparator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the names of the columns in the intermediate table corresponding to the given column objects.
 * 
 * @param columns           The column objects
 * @param intermediateTable The intermediate table
 * @return The column names
 */
protected String[] getIntermediateColumnNamesFor(Column[] columns, Table intermediateTable)
{
    String[] result = new String[columns.length];

    for (int idx = 0; idx < columns.length; idx++)
    {
        result[idx] = intermediateTable.findColumn(columns[idx].getName(), _caseSensitive).getName();
    }
    return result;
}
 
Example 22
Source Project: gemfirexd-oss   Source File: SqlBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Prints the SQL for adding a column to a table.
 * 
 * @param model     The database model
 * @param table     The table
 * @param newColumn The new column
 */
public void addColumn(Database model, Table table, Column newColumn) throws IOException
{
    print("ALTER TABLE ");
    printlnIdentifier(getTableName(table));
    printIndent();
    print("ADD COLUMN ");
    writeColumn(table, newColumn);
    printEndOfStatement();
}
 
Example 23
Source Project: gemfirexd-oss   Source File: DataToDatabaseSink.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new sink instance.
 * 
 * @param platform The database platform
 * @param model    The database model
 */
public DataToDatabaseSink(Platform platform, Database model)
{
    _platform = platform;
    _model    = model;
    for (int tableIdx = 0; tableIdx < model.getTableCount(); tableIdx++)
    {
        Table      table     = model.getTable(tableIdx);
        ForeignKey selfRefFk = table.getSelfReferencingForeignKey();

        if (selfRefFk != null)
        {
            Column[] pkColumns = table.getPrimaryKeyColumns();

            for (int idx = 0; idx < pkColumns.length; idx++)
            {
                if (pkColumns[idx].isAutoIncrement())
                {
                    _tablesWithSelfIdentityReference.add(table);
                    break;
                }
            }
            for (int idx = 0; idx < selfRefFk.getReferenceCount(); idx++)
            {
                if (selfRefFk.getReference(idx).getLocalColumn().isRequired())
                {
                    _tablesWithRequiredSelfReference.add(table);
                    break;
                }
            }
        }
    }
}
 
Example 24
Source Project: gemfirexd-oss   Source File: Oracle8Platform.java    License: 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 removedColumn = changedTable.findColumn(change.getChangedColumn(), isDelimitedIdentifierModeOn());

    ((Oracle8Builder)getSqlBuilder()).dropColumn(changedTable, removedColumn);
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}
 
Example 25
Source Project: gemfirexd-oss   Source File: MySql50ModelReader.java    License: 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);

    // make sure the defaultvalue is null when an empty is returned.
    if ("".equals(column.getDefaultValue()))
    {
        column.setDefaultValue(null);
    }
    return column;
}
 
Example 26
Source Project: gemfirexd-oss   Source File: TestDataReaderAndWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name contains characters not allowed in XML.
 */
public void testTableNameContainsInvalidCharacters() throws Exception
{
    String   tableName   = "test\u0000table";
    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 id=\"1\" value=\"" + testedValue + "\">\n" +
                  "    <table-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(tableName.getBytes("UTF-8")), "UTF-8") + "</table-name>\n" +
                  "  </table>\n" +
                  "</data>\n");
}
 
Example 27
Source Project: gemfirexd-oss   Source File: MSSqlModelComparator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected List checkForPrimaryKeyChanges(Database sourceModel,
                                         Table    sourceTable,
                                         Database intermediateModel,
                                         Table    intermediateTable,
                                         Database targetModel,
                                         Table    targetTable)
{
    List changes = super.checkForPrimaryKeyChanges(sourceModel, sourceTable, intermediateModel, intermediateTable, targetModel, targetTable);

    // now we add pk changes if one of the pk columns was changed
    // we only need to do this if there is no other pk change (which can only be a remove or add change or both)
    if (changes.isEmpty())
    {
        List columns = getRelevantChangedColumns(sourceTable, targetTable);

        for (Iterator it = columns.iterator(); it.hasNext();)
        {
            Column targetColumn = (Column)it.next();

            if (targetColumn.isPrimaryKey())
            {
                changes.add(new RemovePrimaryKeyChange(sourceTable.getName()));
                changes.add(new AddPrimaryKeyChange(sourceTable.getName(), sourceTable.getPrimaryKeyColumnNames()));
                break;
            }
        }
    }
    return changes;
}
 
Example 28
Source Project: gemfirexd-oss   Source File: DataDtdWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Writes the DTD attribute entry for the given column.
 * 
 * @param column The column
 * @param writer The writer to write the attribute entry to
 */
private void writeColumnAttributeEntry(Column column, PrintWriter writer) throws IOException
{
    writer.print("    <!--");
    if (column.isPrimaryKey())
    {
        writer.print(" primary key,");
    }
    if (column.isAutoIncrement())
    {
        writer.print(" auto increment,");
    }
    writer.print(" JDBC type: "+column.getType());
    if ((column.getSize() != null) && (column.getSize().length() > 0))
    {
        writer.print("("+column.getSize()+")");
    }
    writer.println(" -->");
    writer.print("    "+column.getName()+" CDATA ");
    if ((column.getDefaultValue() != null) && (column.getDefaultValue().length() > 0))
    {
        writer.println("\"" + column.getDefaultValue() + "\"");
    }
    else
    {
        writer.println(column.isRequired() ? "#REQUIRED" : "#IMPLIED");
    }
}
 
Example 29
Source Project: gemfirexd-oss   Source File: PlatformImplBase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method esp. for the {@link ModelBasedResultSetIterator} class that retrieves
 * the value for a column from the given result set. If a table was specified,
 * and it contains the column, then the jdbc type defined for the column is used for extracting
 * the value, otherwise the object directly retrieved from the result set is returned.<br/>
 * The method is defined here rather than in the {@link ModelBasedResultSetIterator} class
 * so that concrete platforms can modify its behavior.
 * 
 * @param resultSet  The result set
 * @param columnName The name of the column
 * @param table      The table
 * @return The value
 */
protected Object getObjectFromResultSet(ResultSet resultSet, String columnName, Table table) throws SQLException
{
    Column column = (table == null ? null : table.findColumn(columnName, isDelimitedIdentifierModeOn()));
    Object value  = null;

    if (column != null)
    {
        int originalJdbcType = column.getTypeCode();
        int targetJdbcType   = getPlatformInfo().getTargetJdbcType(originalJdbcType);
        int jdbcType         = originalJdbcType;

        // in general we're trying to retrieve the value using the original type
        // but sometimes we also need the target type:
        if ((originalJdbcType == Types.BLOB) && (targetJdbcType != Types.BLOB))
        {
            // we should not use the Blob interface if the database doesn't map to this type 
            jdbcType = targetJdbcType;
        }
        if ((originalJdbcType == Types.CLOB) && (targetJdbcType != Types.CLOB))
        {
            // we should not use the Clob interface if the database doesn't map to this type 
            jdbcType = targetJdbcType;
        }
        value = extractColumnValue(resultSet, columnName, 0, jdbcType);
    }
    else
    {
        value = resultSet.getObject(columnName);
    }
    return resultSet.wasNull() ? null : value;
}
 
Example 30
Source Project: gemfirexd-oss   Source File: PostgreSqlPlatform.java    License: 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 removedColumn = changedTable.findColumn(change.getChangedColumn(), isDelimitedIdentifierModeOn());

    ((PostgreSqlBuilder)getSqlBuilder()).dropColumn(changedTable, removedColumn);
    change.apply(currentModel, isDelimitedIdentifierModeOn());
}