Java Code Examples for org.apache.ddlutils.model.Column#getName()
The following examples show how to use
org.apache.ddlutils.model.Column#getName() .
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 | 6 votes |
/** * Compares the two columns and returns the change necessary to create the second * column from the first one if they differe. * * @param sourceTable The source table which contains the source column * @param sourceColumn The source column * @param targetTable The target table which contains the target column * @param targetColumn The target column * @return The change or <code>null</code> if the columns are the same */ protected ColumnDefinitionChange compareColumns(Table sourceTable, Column sourceColumn, Table targetTable, Column targetColumn) { if (ColumnDefinitionChange.isChanged(getPlatformInfo(), sourceColumn, targetColumn)) { Column newColumnDef = _cloneHelper.clone(sourceColumn, true); int targetTypeCode = _platformInfo.getTargetJdbcType(targetColumn.getTypeCode()); boolean sizeMatters = _platformInfo.hasSize(targetTypeCode); boolean scaleMatters = _platformInfo.hasPrecisionAndScale(targetTypeCode); newColumnDef.setTypeCode(targetColumn.getTypeCode()); newColumnDef.setSize(sizeMatters || scaleMatters ? targetColumn.getSize() : null); newColumnDef.setAutoIncrement(targetColumn.isAutoIncrement()); newColumnDef.setRequired(targetColumn.isRequired()); newColumnDef.setDescription(targetColumn.getDescription()); newColumnDef.setDefaultValue(targetColumn.getDefaultValue()); return new ColumnDefinitionChange(sourceTable.getQualifiedName(), sourceColumn.getName(), newColumnDef); } else { return null; } }
Example 2
Source File: ModelComparator.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Compares the two columns and returns the change necessary to create the second * column from the first one if they differe. * * @param sourceTable The source table which contains the source column * @param sourceColumn The source column * @param targetTable The target table which contains the target column * @param targetColumn The target column * @return The change or <code>null</code> if the columns are the same */ protected ColumnDefinitionChange compareColumns(Table sourceTable, Column sourceColumn, Table targetTable, Column targetColumn) { if (ColumnDefinitionChange.isChanged(getPlatformInfo(), sourceColumn, targetColumn)) { Column newColumnDef = _cloneHelper.clone(sourceColumn, true); int targetTypeCode = _platformInfo.getTargetJdbcType(targetColumn.getTypeCode()); boolean sizeMatters = _platformInfo.hasSize(targetTypeCode); boolean scaleMatters = _platformInfo.hasPrecisionAndScale(targetTypeCode); newColumnDef.setTypeCode(targetColumn.getTypeCode()); newColumnDef.setSize(sizeMatters || scaleMatters ? targetColumn.getSize() : null); newColumnDef.setAutoIncrement(targetColumn.isAutoIncrement()); newColumnDef.setRequired(targetColumn.isRequired()); newColumnDef.setDescription(targetColumn.getDescription()); newColumnDef.setDefaultValue(targetColumn.getDefaultValue()); return new ColumnDefinitionChange(sourceTable.getQualifiedName(), sourceColumn.getName(), newColumnDef); } else { return null; } }
Example 3
Source File: SqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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 4
Source File: PostgreSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@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 5
Source File: HsqlDbBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeColumn(Table table, Column column) throws IOException { //see comments in columnsDiffer about null/"" defaults printIdentifier(getColumnName(column)); print(" "); print(getSqlType(column)); if (column.isAutoIncrement()) { if (!column.isPrimaryKey()) { throw new ModelException("Column "+column.getName()+" in table "+table.getName()+" is auto-incrementing but not a primary key column, which is not supported by the platform"); } print(" "); writeColumnAutoIncrementStmt(table, column); } else { writeColumnDefaultValueStmt(table, column); } if (column.isRequired()) { print(" "); writeColumnNotNullableStmt(); } else if (getPlatformInfo().isNullAsDefaultValueRequired() && getPlatformInfo().hasNullDefault(column.getTypeCode())) { print(" "); writeColumnNullableStmt(); } }
Example 6
Source File: ModelComparator.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: SqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: PostgreSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@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 9
Source File: HsqlDbBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeColumn(Table table, Column column) throws IOException { //see comments in columnsDiffer about null/"" defaults printIdentifier(getColumnName(column)); print(" "); print(getSqlType(column)); if (column.isAutoIncrement()) { if (!column.isPrimaryKey()) { throw new ModelException("Column "+column.getName()+" in table "+table.getName()+" is auto-incrementing but not a primary key column, which is not supported by the platform"); } print(" "); writeColumnAutoIncrementStmt(table, column); } else { writeColumnDefaultValueStmt(table, column); } if (column.isRequired()) { print(" "); writeColumnNotNullableStmt(); } else if (getPlatformInfo().isNullAsDefaultValueRequired() && getPlatformInfo().hasNullDefault(column.getTypeCode())) { print(" "); writeColumnNullableStmt(); } }
Example 10
Source File: ModelComparator.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: SqlDynaProperty.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Creates a property instance for the given column that accepts any data type. * * @param column The column */ public SqlDynaProperty(Column column) { super(column.getName()); _column = column; }
Example 12
Source File: ColumnXmlWriter.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Creates a new column writer. * * @param column The column, cannot be null * @param value The value, cannot be null */ public ColumnXmlWriter(Column column, String value) { /* * - attribute "column name"="column value" in the parent's (table) element * iff the column name is a valid attribute name and is not "table-name" and not "column", * and the value is a valid attribute value not longer than 255 characters * - otherwise, writes a sub-element <column> with an attribute column-name that contains the name * of the column, and the body of that sub-element contains the column value, * iff the column name is a valid attribute value not longer than 255 characters. If the column * value contains illegal characters, then the column sub element will have a "base64" attribute * with the value "true" and the value will be base64 encoded * - otherwise writes a sub-element <column> with a sub-element <column-name> whose * body is the name of the column, and another sub-element <column-value> whose body contains * the column value. If either the column name or value contain illegal characters, then the * corresponding sub element will have a "base64" attribute with the value "true" and its body will * be base64 encoded. */ if (XMLUtils.hasIllegalXMLCharacters(value)) { columnValue = XMLUtils.base64Encode(value); valueBase64Encoded = true; } else { columnValue = value; valueBase64Encoded = false; } if (XMLUtils.hasIllegalXMLCharacters(column.getName())) { columnName = XMLUtils.base64Encode(column.getName()); nameBase64Encoded = true; columnFormattingMethod = AS_VALUE; } else { columnName = column.getName(); nameBase64Encoded = false; if (columnName.length() > XMLUtils.MAX_NAME_LENGTH) { columnFormattingMethod = AS_VALUE; } else if ("table-name".equals(columnName) || DatabaseIO.BASE64_ATTR_NAME.equals(columnName) || !XMLUtils.isWellFormedXMLName(columnName)) { columnFormattingMethod = AS_COLUMN_ATTRIBUTE; } else if (valueBase64Encoded || (value.length() > XMLUtils.MAX_ATTRIBUTE_LENGTH)) { columnFormattingMethod = AS_SUBTAG; } else { columnFormattingMethod = AS_TABLE_ATTRIBUTE; } } }
Example 13
Source File: SqlDynaProperty.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Creates a property instance for the given column that accepts any data type. * * @param column The column */ public SqlDynaProperty(Column column) { super(column.getName()); _column = column; }
Example 14
Source File: ColumnXmlWriter.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Creates a new column writer. * * @param column The column, cannot be null * @param value The value, cannot be null */ public ColumnXmlWriter(Column column, String value) { /* * - attribute "column name"="column value" in the parent's (table) element * iff the column name is a valid attribute name and is not "table-name" and not "column", * and the value is a valid attribute value not longer than 255 characters * - otherwise, writes a sub-element <column> with an attribute column-name that contains the name * of the column, and the body of that sub-element contains the column value, * iff the column name is a valid attribute value not longer than 255 characters. If the column * value contains illegal characters, then the column sub element will have a "base64" attribute * with the value "true" and the value will be base64 encoded * - otherwise writes a sub-element <column> with a sub-element <column-name> whose * body is the name of the column, and another sub-element <column-value> whose body contains * the column value. If either the column name or value contain illegal characters, then the * corresponding sub element will have a "base64" attribute with the value "true" and its body will * be base64 encoded. */ if (XMLUtils.hasIllegalXMLCharacters(value)) { columnValue = XMLUtils.base64Encode(value); valueBase64Encoded = true; } else { columnValue = value; valueBase64Encoded = false; } if (XMLUtils.hasIllegalXMLCharacters(column.getName())) { columnName = XMLUtils.base64Encode(column.getName()); nameBase64Encoded = true; columnFormattingMethod = AS_VALUE; } else { columnName = column.getName(); nameBase64Encoded = false; if (columnName.length() > XMLUtils.MAX_NAME_LENGTH) { columnFormattingMethod = AS_VALUE; } else if ("table-name".equals(columnName) || DatabaseIO.BASE64_ATTR_NAME.equals(columnName) || !XMLUtils.isWellFormedXMLName(columnName)) { columnFormattingMethod = AS_COLUMN_ATTRIBUTE; } else if (valueBase64Encoded || (value.length() > XMLUtils.MAX_ATTRIBUTE_LENGTH)) { columnFormattingMethod = AS_SUBTAG; } else { columnFormattingMethod = AS_TABLE_ATTRIBUTE; } } }
Example 15
Source File: SqlDynaProperty.java From gemfirexd-oss with Apache License 2.0 | 2 votes |
/** * Creates a property instance for the given column that only accepts the given type. * * @param column The column * @param type The type of the property */ public SqlDynaProperty(Column column, Class type) { super(column.getName(), type); _column = column; }
Example 16
Source File: SqlDynaProperty.java From gemfirexd-oss with Apache License 2.0 | 2 votes |
/** * Creates a property instance for the given column that only accepts the given type. * * @param column The column * @param type The type of the property */ public SqlDynaProperty(Column column, Class type) { super(column.getName(), type); _column = column; }