Java Code Examples for org.apache.ddlutils.model.Table#getQualifiedName()

The following examples show how to use org.apache.ddlutils.model.Table#getQualifiedName() . 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: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for tables that are present in the given source model but are no longer in the target
 * model, and applies them to the given intermediate model.
 * 
 * @param sourceModel       The source model
 * @param intermediateModel The intermediate model to apply the changes to
 * @param targetModel       The target model
 * @return The changes
 */
protected List checkForRemovedTables(Database sourceModel,
                                     Database intermediateModel,
                                     Database targetModel)
{
    List    changes            = new ArrayList();
    Table[] intermediateTables = intermediateModel.getTables();

    for (int tableIdx = 0; tableIdx < intermediateTables.length; tableIdx++)
    {
        Table intermediateTable = intermediateTables[tableIdx];
        Table targetTable       = targetModel.findTable(intermediateTable.getQualifiedName(), _caseSensitive);

        if (targetTable == null)
        {
            if (_log.isInfoEnabled())
            {
                _log.info("Table " + intermediateTable.getQualifiedName() + " needs to be removed");
            }

            RemoveTableChange tableChange = new RemoveTableChange(intermediateTable.getQualifiedName());

            changes.add(tableChange);
            tableChange.apply(intermediateModel, _caseSensitive);
        }
    }
    return changes;
}
 
Example 2
Source File: GemFireXDBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the given embedded index of the table.
 * 
 * @param table
 *          The table
 * @param index
 *          The index
 */
@Override
protected void writeEmbeddedIndexCreateStmt(Table table, Index index)
    throws IOException {
  if ((index.getName() != null) && (index.getName().length() > 0)) {
    print(" CONSTRAINT ");
    printIdentifier(getIndexName(table, index));
  }
  if (index.isUnique()) {
    print(" UNIQUE");
  }
  else {
    print(" INDEX ");
  }
  print(" (");

  for (int idx = 0; idx < index.getColumnCount(); idx++) {
    IndexColumn idxColumn = index.getColumn(idx);
    Column col = table.findColumn(idxColumn.getName());

    if (col == null) {
      // would get null pointer on next line anyway, so throw exception
      throw new ModelException("Invalid column '" + idxColumn.getName()
          + "' on index " + index.getName() + " for table " + table.getQualifiedName());
    }
    if (idx > 0) {
      print(", ");
    }
    printIdentifier(getColumnName(col));
  }

  print(")");
}
 
Example 3
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
     * Writes the table object to the given XML writer.
     * 
     * @param table     The table object
     * @param xmlWriter The XML writer
     */
    private void writeTableElement(Table table, PrettyPrintingXmlWriter xmlWriter) throws DdlUtilsXMLException
    {
        xmlWriter.indentIfPrettyPrinting(1);
        writeElementStart(xmlWriter, QNAME_ELEMENT_TABLE);
// GemStone changes BEGIN
        // write fully qualified table name
        final String tableName = table.getQualifiedName();
        writeAttribute(xmlWriter, QNAME_ATTRIBUTE_NAME, tableName);
        /* (original code)
        writeAttribute(xmlWriter, QNAME_ATTRIBUTE_NAME,        table.getName());
        */
// GemStone changes END
        writeAttribute(xmlWriter, QNAME_ATTRIBUTE_DESCRIPTION, table.getDescription());
        if ((table.getColumnCount() > 0) || (table.getForeignKeyCount() > 0) || (table.getIndexCount() > 0))
        {
            xmlWriter.printlnIfPrettyPrinting();
            for (int idx = 0; idx < table.getColumnCount(); idx++)
            {
                writeColumnElement(table.getColumn(idx), xmlWriter);
            }
            for (int idx = 0; idx < table.getForeignKeyCount(); idx++)
            {
                writeForeignKeyElement(table.getForeignKey(idx), xmlWriter);
            }
            for (int idx = 0; idx < table.getIndexCount(); idx++)
            {
                writeIndexElement(table.getIndex(idx), xmlWriter);
            }
            xmlWriter.indentIfPrettyPrinting(1);
        }
        writeElementEnd(xmlWriter);
    }
 
Example 4
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for indexes that are not present in the given source table but are in the 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 checkForAddedIndexes(Database sourceModel,
                                    Table    sourceTable,
                                    Database intermediateModel,
                                    Table    intermediateTable,
                                    Database targetModel,
                                    Table    targetTable)
{
    List changes = new ArrayList();

    for (int indexIdx = 0; indexIdx < targetTable.getIndexCount(); indexIdx++)
    {
        Index targetIndex       = targetTable.getIndex(indexIdx);
        Index intermediateIndex = findCorrespondingIndex(intermediateTable, targetIndex);
        Index sourceIndex       = findCorrespondingIndex(sourceTable, targetIndex);

        if ((sourceIndex == null) && (intermediateIndex == null))
        {
            if (_log.isInfoEnabled())
            {
                _log.info("Index " + targetIndex.getName() + " needs to be created for table " + intermediateTable.getQualifiedName());
            }

            Index          clonedIndex = _cloneHelper.clone(targetIndex, intermediateTable, _caseSensitive);
            AddIndexChange change      = new AddIndexChange(intermediateTable.getQualifiedName(), clonedIndex);

            changes.add(change);
            change.apply(intermediateModel, _caseSensitive);
        }
    }
    return changes;
}
 
Example 5
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the given embedded index of the table.
 * 
 * @param table The table
 * @param index The index
 */
protected void writeEmbeddedIndexCreateStmt(Table table, Index index) throws IOException
{
    if ((index.getName() != null) && (index.getName().length() > 0))
    {
        print(" CONSTRAINT ");
        printIdentifier(getIndexName(index));
    }
    if (index.isUnique())
    {
        print(" UNIQUE");
    }
    else
    {
        print(" INDEX ");
    }
    print(" (");

    for (int idx = 0; idx < index.getColumnCount(); idx++)
    {
        IndexColumn idxColumn = index.getColumn(idx);
        Column      col       = table.findColumn(idxColumn.getName());

        if (col == null)
        {
            // would get null pointer on next line anyway, so throw exception
            throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getQualifiedName());
        }
        if (idx > 0)
        {
            print(", ");
        }
        printIdentifier(getColumnName(col));
    }

    print(")");
}
 
Example 6
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for foreign keys that are present in the given source model but are no longer in the target
 * model, and applies them to the given intermediate model.
 * 
 * @param sourceModel       The source model
 * @param intermediateModel The intermediate model to apply the changes to
 * @param targetModel       The target model
 * @return The changes
 */
protected List checkForRemovedForeignKeys(Database sourceModel,
                                          Database intermediateModel,
                                          Database targetModel)
{
    List changes = new ArrayList();

    for (int tableIdx = 0; tableIdx < intermediateModel.getTableCount(); tableIdx++)
    {
        Table        intermediateTable = intermediateModel.getTable(tableIdx);
        Table        targetTable       = targetModel.findTable(intermediateTable.getQualifiedName(), _caseSensitive);
        ForeignKey[] intermediateFks   = intermediateTable.getForeignKeys();

        // Dropping foreign keys from tables to be removed might not be necessary, but some databases might require it
        for (int fkIdx = 0; fkIdx < intermediateFks.length; fkIdx++)
        {
            ForeignKey sourceFk = intermediateFks[fkIdx];
            ForeignKey targetFk = targetTable == null ? null : findCorrespondingForeignKey(targetTable, sourceFk);

            if (targetFk == null)
            {
                if (_log.isInfoEnabled())
                {
                    _log.info("Foreign key " + sourceFk + " needs to be removed from table " + intermediateTable.getQualifiedName());
                }

                RemoveForeignKeyChange fkChange = new RemoveForeignKeyChange(intermediateTable.getQualifiedName(), sourceFk);

                changes.add(fkChange);
                fkChange.apply(intermediateModel, _caseSensitive);
            }
        }
    }
    return changes;
}
 
Example 7
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for columns that are present in the given source table but are no longer in the 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 checkForRemovedColumns(Database sourceModel,
                                      Table    sourceTable,
                                      Database intermediateModel,
                                      Table    intermediateTable,
                                      Database targetModel,
                                      Table    targetTable)
{
    // if the platform does not support dropping pk columns, then the pk handling above will
    // generate appropriate pk changes

    List     changes = new ArrayList();
    Column[] columns = intermediateTable.getColumns();

    for (int columnIdx = 0; columnIdx < columns.length; columnIdx++)
    {
        Column sourceColumn = columns[columnIdx];
        Column targetColumn = targetTable.findColumn(sourceColumn.getName(), _caseSensitive);

        if (targetColumn == null)
        {
            if (_log.isInfoEnabled())
            {
                _log.info("Column " + sourceColumn.getName() + " needs to be removed from table " + intermediateTable.getQualifiedName());
            }

            RemoveColumnChange change = new RemoveColumnChange(intermediateTable.getQualifiedName(), sourceColumn.getName());

            changes.add(change);
            change.apply(intermediateModel, _caseSensitive);
        }
    }
    return changes;
}
 
Example 8
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for indexes that are present in the given source table but are no longer in the 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 checkForRemovedIndexes(Database sourceModel,
                                      Table    sourceTable,
                                      Database intermediateModel,
                                      Table    intermediateTable,
                                      Database targetModel,
                                      Table    targetTable)
{
    List    changes = new ArrayList();
    Index[] indexes = intermediateTable.getIndices();

    for (int indexIdx = 0; indexIdx < indexes.length; indexIdx++)
    {
        Index sourceIndex = indexes[indexIdx];
        Index targetIndex = findCorrespondingIndex(targetTable, sourceIndex);

        if (targetIndex == null)
        {
            if (_log.isInfoEnabled())
            {
                _log.info("Index " + sourceIndex.getName() + " needs to be removed from table " + intermediateTable.getQualifiedName());
            }

            RemoveIndexChange change = new RemoveIndexChange(intermediateTable.getQualifiedName(), sourceIndex);

            changes.add(change);
            change.apply(intermediateModel, _caseSensitive);
        }
    }
    return changes;
}
 
Example 9
Source File: ModelComparator.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates change objects for foreign keys that are not present in the given source model but are in the target
 * model, and applies them to the given intermediate model.
 * 
 * @param sourceModel       The source model
 * @param intermediateModel The intermediate model to apply the changes to
 * @param targetModel       The target model
 * @return The changes
 */
protected List checkForAddedForeignKeys(Database sourceModel,
                                        Database intermediateModel,
                                        Database targetModel)
{
    List changes = new ArrayList();

    for (int tableIdx = 0; tableIdx < targetModel.getTableCount(); tableIdx++)
    {
        Table targetTable       = targetModel.getTable(tableIdx);
        Table intermediateTable = intermediateModel.findTable(targetTable.getQualifiedName(), _caseSensitive);

        for (int fkIdx = 0; fkIdx < targetTable.getForeignKeyCount(); fkIdx++)
        {
            ForeignKey targetFk       = targetTable.getForeignKey(fkIdx);
            ForeignKey intermediateFk = findCorrespondingForeignKey(intermediateTable, targetFk);

            if (intermediateFk == null)
            {
                if (_log.isInfoEnabled())
                {
                    _log.info("Foreign key " + targetFk + " needs to be added to table " + intermediateTable.getQualifiedName());
                }

                intermediateFk = _cloneHelper.clone(targetFk, intermediateTable, intermediateModel, _caseSensitive);

                AddForeignKeyChange fkChange = new AddForeignKeyChange(intermediateTable.getQualifiedName(), intermediateFk);

                changes.add(fkChange);
                fkChange.apply(intermediateModel, _caseSensitive);
            }
        }
    }
    return changes;
}
 
Example 10
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
     * Writes the table object to the given XML writer.
     * 
     * @param table     The table object
     * @param xmlWriter The XML writer
     */
    private void writeTableElement(Table table, PrettyPrintingXmlWriter xmlWriter) throws DdlUtilsXMLException
    {
        xmlWriter.indentIfPrettyPrinting(1);
        writeElementStart(xmlWriter, QNAME_ELEMENT_TABLE);
// GemStone changes BEGIN
        // write fully qualified table name
        final String tableName = table.getQualifiedName();
        writeAttribute(xmlWriter, QNAME_ATTRIBUTE_NAME, tableName);
        /* (original code)
        writeAttribute(xmlWriter, QNAME_ATTRIBUTE_NAME,        table.getName());
        */
// GemStone changes END
        writeAttribute(xmlWriter, QNAME_ATTRIBUTE_DESCRIPTION, table.getDescription());
        if ((table.getColumnCount() > 0) || (table.getForeignKeyCount() > 0) || (table.getIndexCount() > 0))
        {
            xmlWriter.printlnIfPrettyPrinting();
            for (int idx = 0; idx < table.getColumnCount(); idx++)
            {
                writeColumnElement(table.getColumn(idx), xmlWriter);
            }
            for (int idx = 0; idx < table.getForeignKeyCount(); idx++)
            {
                writeForeignKeyElement(table.getForeignKey(idx), xmlWriter);
            }
            for (int idx = 0; idx < table.getIndexCount(); idx++)
            {
                writeIndexElement(table.getIndex(idx), xmlWriter);
            }
            xmlWriter.indentIfPrettyPrinting(1);
        }
        writeElementEnd(xmlWriter);
    }
 
Example 11
Source File: TableXmlWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public TableXmlWriter(Table table)
    {
// GemStone changes BEGIN
        // use fully qualified name
        // changes below replace table.getName() with fullTableName
        final String fullTableName = table.getQualifiedName();
// GemStone changes END
        if (XMLUtils.hasIllegalXMLCharacters(fullTableName))
        {
            tableName        = XMLUtils.base64Encode(fullTableName);
            formattingMethod = AS_SUB_TAG;
            base64Encoded    = true;
        }
        else
        {
            tableName     = fullTableName;
            base64Encoded = false;
            if (tableName.length() > XMLUtils.MAX_NAME_LENGTH)
            {
                formattingMethod = AS_SUB_TAG;
            }
            else if ("table".equals(tableName) || !XMLUtils.isWellFormedXMLName(tableName))
            {
                formattingMethod = AS_ATTRIBUTE;
            }
            else
            {
                formattingMethod = AS_TAG_NAME;
            }
        }
    }
 
Example 12
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the given embedded index of the table.
 * 
 * @param table The table
 * @param index The index
 */
protected void writeEmbeddedIndexCreateStmt(Table table, Index index) throws IOException
{
    if ((index.getName() != null) && (index.getName().length() > 0))
    {
        print(" CONSTRAINT ");
        printIdentifier(getIndexName(index));
    }
    if (index.isUnique())
    {
        print(" UNIQUE");
    }
    else
    {
        print(" INDEX ");
    }
    print(" (");

    for (int idx = 0; idx < index.getColumnCount(); idx++)
    {
        IndexColumn idxColumn = index.getColumn(idx);
        Column      col       = table.findColumn(idxColumn.getName());

        if (col == null)
        {
            // would get null pointer on next line anyway, so throw exception
            throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getQualifiedName());
        }
        if (idx > 0)
        {
            print(", ");
        }
        printIdentifier(getColumnName(col));
    }

    print(")");
}
 
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: GemFireXDBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the given index for the table using an external index creation
 * statement. This override adds the table name to index name (#43964).
 * 
 * @param table
 *          The table
 * @param index
 *          The index
 */
@Override
public void createIndex(Table table, Index index) throws IOException {
  if (getPlatformInfo().isIndicesSupported()) {
    if (index.getName() == null) {
      _log.warn("Cannot write unnamed index " + index);
    }
    else {
      print("CREATE");
      if (index.isUnique()) {
        print(" UNIQUE");
      }
      print(" INDEX ");
      printIdentifier(getIndexName(table, index));
      print(" ON ");
      printIdentifier(getTableName(table));
      print(" (");

      for (int idx = 0; idx < index.getColumnCount(); idx++) {
        IndexColumn idxColumn = index.getColumn(idx);
        Column col = table.findColumn(idxColumn.getName());

        if (col == null) {
          // would get null pointer on next line anyway, so throw exception
          throw new ModelException("Invalid column '" + idxColumn.getName()
              + "' on index " + index.getName() + " for table "
              + table.getQualifiedName());
        }
        if (idx > 0) {
          print(", ");
        }
        printIdentifier(getColumnName(col));
      }

      print(")");
      printEndOfStatement();
    }
  }
  else {
    throw new DdlUtilsException("This platform does not support indexes");
  }
}
 
Example 15
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the onDelete action for the given foreign key.
 *  
 * @param table      The table
 * @param foreignKey The foreignkey
 */
protected void writeForeignKeyOnUpdateAction(Table table, ForeignKey foreignKey) throws IOException
{
    CascadeActionEnum action = foreignKey.getOnUpdate();

    if (!getPlatformInfo().isActionSupportedForOnUpdate(action))
    {
        if (getPlatform().isDefaultOnUpdateActionUsedIfUnsupported())
        {
            _log.info("The platform does not support the " + action + " action for onUpdate; using " + getPlatformInfo().getDefaultOnUpdateAction() + " instead");
            action = getPlatformInfo().getDefaultOnUpdateAction();
        }
        else
        {
            throw new ModelException("The platform does not support the action '" + action +
                                     "' for onUpdate in foreign key in table " + table.getQualifiedName());
        }
    }
    if (action != getPlatformInfo().getDefaultOnUpdateAction())
    {
        print(" ON UPDATE ");
        switch (action.getValue())
        {
            case CascadeActionEnum.VALUE_CASCADE:
                print("CASCADE");
                break;
            case CascadeActionEnum.VALUE_SET_NULL:
                print("SET NULL");
                break;
            case CascadeActionEnum.VALUE_SET_DEFAULT:
                print("SET DEFAULT");
                break;
            case CascadeActionEnum.VALUE_RESTRICT:
                print("RESTRICT");
                break;
            case CascadeActionEnum.VALUE_NONE:
                print("NO ACTION");
                break;
            default:
                throw new ModelException("Unsupported cascade value '" + action +
                                         "' for onUpdate in foreign key in table " + table.getQualifiedName());
        }
    }
}
 
Example 16
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the onDelete action for the given foreign key.
 *  
 * @param table      The table
 * @param foreignKey The foreignkey
 */
protected void writeForeignKeyOnDeleteAction(Table table, ForeignKey foreignKey) throws IOException
{
    CascadeActionEnum action = foreignKey.getOnDelete();

    if (!getPlatformInfo().isActionSupportedForOnDelete(action))
    {
        if (getPlatform().isDefaultOnDeleteActionUsedIfUnsupported())
        {
            _log.info("The platform does not support the " + action + " action for onDelete; using " + getPlatformInfo().getDefaultOnDeleteAction() + " instead");
            action = getPlatformInfo().getDefaultOnDeleteAction();
        }
        else
        {
            throw new ModelException("The platform does not support the action '" + action +
                                     "' for onDelete in foreign key in table " + table.getQualifiedName());
        }
    }
    if (action != getPlatformInfo().getDefaultOnDeleteAction())
    {
        print(" ON DELETE ");
        switch (action.getValue())
        {
            case CascadeActionEnum.VALUE_CASCADE:
                print("CASCADE");
                break;
            case CascadeActionEnum.VALUE_SET_NULL:
                print("SET NULL");
                break;
            case CascadeActionEnum.VALUE_SET_DEFAULT:
                print("SET DEFAULT");
                break;
            case CascadeActionEnum.VALUE_RESTRICT:
                print("RESTRICT");
                break;
            case CascadeActionEnum.VALUE_NONE:
                print("NO ACTION");
                break;
            default:
                throw new ModelException("Unsupported cascade value '" + action +
                                         "' for onDelete in foreign key in table " + table.getQualifiedName());
        }
    }
}
 
Example 17
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the onDelete action for the given foreign key.
 *  
 * @param table      The table
 * @param foreignKey The foreignkey
 */
protected void writeForeignKeyOnUpdateAction(Table table, ForeignKey foreignKey) throws IOException
{
    CascadeActionEnum action = foreignKey.getOnUpdate();

    if (!getPlatformInfo().isActionSupportedForOnUpdate(action))
    {
        if (getPlatform().isDefaultOnUpdateActionUsedIfUnsupported())
        {
            _log.info("The platform does not support the " + action + " action for onUpdate; using " + getPlatformInfo().getDefaultOnUpdateAction() + " instead");
            action = getPlatformInfo().getDefaultOnUpdateAction();
        }
        else
        {
            throw new ModelException("The platform does not support the action '" + action +
                                     "' for onUpdate in foreign key in table " + table.getQualifiedName());
        }
    }
    if (action != getPlatformInfo().getDefaultOnUpdateAction())
    {
        print(" ON UPDATE ");
        switch (action.getValue())
        {
            case CascadeActionEnum.VALUE_CASCADE:
                print("CASCADE");
                break;
            case CascadeActionEnum.VALUE_SET_NULL:
                print("SET NULL");
                break;
            case CascadeActionEnum.VALUE_SET_DEFAULT:
                print("SET DEFAULT");
                break;
            case CascadeActionEnum.VALUE_RESTRICT:
                print("RESTRICT");
                break;
            case CascadeActionEnum.VALUE_NONE:
                print("NO ACTION");
                break;
            default:
                throw new ModelException("Unsupported cascade value '" + action +
                                         "' for onUpdate in foreign key in table " + table.getQualifiedName());
        }
    }
}
 
Example 18
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the given index for the table using an external index creation statement.
 * 
 * @param table The table
 * @param index The index
 */
public void createIndex(Table table, Index index) throws IOException
{
    if (!getPlatformInfo().isIndicesSupported())
    {
        throw new DdlUtilsException("This platform does not support indexes");
    }
    else if (index.getName() == null)
    {
        _log.warn("Cannot write unnamed index " + index);
    }
    else
    {
        print("CREATE");
        if (index.isUnique())
        {
            print(" UNIQUE");
        }
        print(" INDEX ");
        printIdentifier(getIndexName(index));
        print(" ON ");
        printIdentifier(getTableName(table));
        print(" (");

        for (int idx = 0; idx < index.getColumnCount(); idx++)
        {
            IndexColumn idxColumn = index.getColumn(idx);
            Column      col       = table.findColumn(idxColumn.getName());

            if (col == null)
            {
                // would get null pointer on next line anyway, so throw exception
                throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getQualifiedName());
            }
            if (idx > 0)
            {
                print(", ");
            }
            printIdentifier(getColumnName(col));
        }

        print(")");
        printEndOfStatement();
    }
}
 
Example 19
Source File: GemFireXDBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the given index for the table using an external index creation
 * statement. This override adds the table name to index name (#43964).
 * 
 * @param table
 *          The table
 * @param index
 *          The index
 */
@Override
public void createIndex(Table table, Index index) throws IOException {
  if (getPlatformInfo().isIndicesSupported()) {
    if (index.getName() == null) {
      _log.warn("Cannot write unnamed index " + index);
    }
    else {
      print("CREATE");
      if (index.isUnique()) {
        print(" UNIQUE");
      }
      print(" INDEX ");
      printIdentifier(getIndexName(table, index));
      print(" ON ");
      printIdentifier(getTableName(table));
      print(" (");

      for (int idx = 0; idx < index.getColumnCount(); idx++) {
        IndexColumn idxColumn = index.getColumn(idx);
        Column col = table.findColumn(idxColumn.getName());

        if (col == null) {
          // would get null pointer on next line anyway, so throw exception
          throw new ModelException("Invalid column '" + idxColumn.getName()
              + "' on index " + index.getName() + " for table "
              + table.getQualifiedName());
        }
        if (idx > 0) {
          print(", ");
        }
        printIdentifier(getColumnName(col));
      }

      print(")");
      printEndOfStatement();
    }
  }
  else {
    throw new DdlUtilsException("This platform does not support indexes");
  }
}
 
Example 20
Source File: SqlBuilder.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Writes the given index for the table using an external index creation statement.
 * 
 * @param table The table
 * @param index The index
 */
public void createIndex(Table table, Index index) throws IOException
{
    if (!getPlatformInfo().isIndicesSupported())
    {
        throw new DdlUtilsException("This platform does not support indexes");
    }
    else if (index.getName() == null)
    {
        _log.warn("Cannot write unnamed index " + index);
    }
    else
    {
        print("CREATE");
        if (index.isUnique())
        {
            print(" UNIQUE");
        }
        print(" INDEX ");
        printIdentifier(getIndexName(index));
        print(" ON ");
        printIdentifier(getTableName(table));
        print(" (");

        for (int idx = 0; idx < index.getColumnCount(); idx++)
        {
            IndexColumn idxColumn = index.getColumn(idx);
            Column      col       = table.findColumn(idxColumn.getName());

            if (col == null)
            {
                // would get null pointer on next line anyway, so throw exception
                throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getQualifiedName());
            }
            if (idx > 0)
            {
                print(", ");
            }
            printIdentifier(getColumnName(col));
        }

        print(")");
        printEndOfStatement();
    }
}