Java Code Examples for org.apache.ddlutils.model.Column#getParsedDefaultValue()
The following examples show how to use
org.apache.ddlutils.model.Column#getParsedDefaultValue() .
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: SqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Prints the default value stmt part for the column. * * @param table The table * @param column The column */ protected void writeColumnDefaultValueStmt(Table table, Column column) throws IOException { Object parsedDefault = column.getParsedDefaultValue(); if (parsedDefault != null) { if (!getPlatformInfo().isDefaultValuesForLongTypesSupported() && ((column.getTypeCode() == Types.LONGVARBINARY) || (column.getTypeCode() == Types.LONGVARCHAR))) { throw new ModelException("The platform does not support default values for LONGVARCHAR or LONGVARBINARY columns"); } // we write empty default value strings only if the type is not a numeric or date/time type if (isValidDefaultValue(column.getDefaultValue(), column.getTypeCode())) { print(" DEFAULT "); writeColumnDefaultValue(table, column); } } else if (getPlatformInfo().isDefaultValueUsedForIdentitySpec() && column.isAutoIncrement()) { print(" DEFAULT "); writeColumnDefaultValue(table, column); } }
Example 2
Source File: SqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Prints the default value stmt part for the column. * * @param table The table * @param column The column */ protected void writeColumnDefaultValueStmt(Table table, Column column) throws IOException { Object parsedDefault = column.getParsedDefaultValue(); if (parsedDefault != null) { if (!getPlatformInfo().isDefaultValuesForLongTypesSupported() && ((column.getTypeCode() == Types.LONGVARBINARY) || (column.getTypeCode() == Types.LONGVARCHAR))) { throw new ModelException("The platform does not support default values for LONGVARCHAR or LONGVARBINARY columns"); } // we write empty default value strings only if the type is not a numeric or date/time type if (isValidDefaultValue(column.getDefaultValue(), column.getTypeCode())) { print(" DEFAULT "); writeColumnDefaultValue(table, column); } } else if (getPlatformInfo().isDefaultValueUsedForIdentitySpec() && column.isAutoIncrement()) { print(" DEFAULT "); writeColumnDefaultValue(table, column); } }
Example 3
Source File: SapDbBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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("COLUMN "); printIdentifier(getColumnName(column)); boolean hasDefault = column.getParsedDefaultValue() != null; if (isValidDefaultValue(newDefaultValue, column.getTypeCode())) { if (hasDefault) { print(" ALTER DEFAULT "); } else { print(" ADD DEFAULT "); } printDefaultValue(newDefaultValue, column.getTypeCode()); } else if (hasDefault) { print(" DROP DEFAULT"); } printEndOfStatement(); }
Example 4
Source File: ColumnDefinitionChange.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: SapDbBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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("COLUMN "); printIdentifier(getColumnName(column)); boolean hasDefault = column.getParsedDefaultValue() != null; if (isValidDefaultValue(newDefaultValue, column.getTypeCode())) { if (hasDefault) { print(" ALTER DEFAULT "); } else { print(" ADD DEFAULT "); } printDefaultValue(newDefaultValue, column.getTypeCode()); } else if (hasDefault) { print(" DROP DEFAULT"); } printEndOfStatement(); }
Example 6
Source File: ColumnDefinitionChange.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: SybaseBuilder.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Writes the SQL to change the given column. * * @param table The table * @param column The column to change * @param newColumn The new column definition */ public void changeColumn(Table table, Column column, Column newColumn) throws IOException { Object oldParsedDefault = column.getParsedDefaultValue(); Object newParsedDefault = newColumn.getParsedDefaultValue(); String newDefault = newColumn.getDefaultValue(); boolean defaultChanges = ((oldParsedDefault == null) && (newParsedDefault != null)) || ((oldParsedDefault != null) && !oldParsedDefault.equals(newParsedDefault)); // Sybase does not like it if there is a default spec in the ALTER TABLE ALTER // statement; thus we have to change the default afterwards if (defaultChanges) { // we're first removing the default as it might make problems when the // datatype changes print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("REPLACE "); printIdentifier(getColumnName(column)); print(" DEFAULT NULL"); printEndOfStatement(); } print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("MODIFY "); if (newDefault != null) { newColumn.setDefaultValue(null); } writeColumn(table, newColumn); if (newDefault != null) { newColumn.setDefaultValue(newDefault); } printEndOfStatement(); if (defaultChanges) { print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("REPLACE "); printIdentifier(getColumnName(column)); if (newDefault != null) { writeColumnDefaultValueStmt(table, newColumn); } else { print(" DEFAULT NULL"); } printEndOfStatement(); } }
Example 8
Source File: MSSqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Writes the SQL to recreate a column, e.g. using a different type or similar. * * @param table The table * @param curColumn The current column definition * @param newColumn The new column definition */ public void recreateColumn(Table table, Column curColumn, Column newColumn) throws IOException { boolean hasDefault = curColumn.getParsedDefaultValue() != null; boolean shallHaveDefault = newColumn.getParsedDefaultValue() != null; String newDefault = newColumn.getDefaultValue(); // Sql Server does not like it if there is a default spec in the ALTER TABLE ALTER COLUMN // statement; thus we have to change the default manually if (newDefault != null) { newColumn.setDefaultValue(null); } if (hasDefault) { // we're dropping the old default writeDropConstraintStatement(table, curColumn, "D"); } print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("ALTER COLUMN "); writeColumn(table, newColumn); printEndOfStatement(); if (shallHaveDefault) { newColumn.setDefaultValue(newDefault); // if the column shall have a default, then we have to add it as a constraint print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("ADD CONSTRAINT "); printIdentifier(getConstraintName("DF", table, curColumn.getName(), null)); writeColumnDefaultValueStmt(table, newColumn); print(" FOR "); printIdentifier(getColumnName(curColumn)); printEndOfStatement(); } }
Example 9
Source File: SybaseBuilder.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Writes the SQL to change the given column. * * @param table The table * @param column The column to change * @param newColumn The new column definition */ public void changeColumn(Table table, Column column, Column newColumn) throws IOException { Object oldParsedDefault = column.getParsedDefaultValue(); Object newParsedDefault = newColumn.getParsedDefaultValue(); String newDefault = newColumn.getDefaultValue(); boolean defaultChanges = ((oldParsedDefault == null) && (newParsedDefault != null)) || ((oldParsedDefault != null) && !oldParsedDefault.equals(newParsedDefault)); // Sybase does not like it if there is a default spec in the ALTER TABLE ALTER // statement; thus we have to change the default afterwards if (defaultChanges) { // we're first removing the default as it might make problems when the // datatype changes print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("REPLACE "); printIdentifier(getColumnName(column)); print(" DEFAULT NULL"); printEndOfStatement(); } print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("MODIFY "); if (newDefault != null) { newColumn.setDefaultValue(null); } writeColumn(table, newColumn); if (newDefault != null) { newColumn.setDefaultValue(newDefault); } printEndOfStatement(); if (defaultChanges) { print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("REPLACE "); printIdentifier(getColumnName(column)); if (newDefault != null) { writeColumnDefaultValueStmt(table, newColumn); } else { print(" DEFAULT NULL"); } printEndOfStatement(); } }
Example 10
Source File: MSSqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Writes the SQL to recreate a column, e.g. using a different type or similar. * * @param table The table * @param curColumn The current column definition * @param newColumn The new column definition */ public void recreateColumn(Table table, Column curColumn, Column newColumn) throws IOException { boolean hasDefault = curColumn.getParsedDefaultValue() != null; boolean shallHaveDefault = newColumn.getParsedDefaultValue() != null; String newDefault = newColumn.getDefaultValue(); // Sql Server does not like it if there is a default spec in the ALTER TABLE ALTER COLUMN // statement; thus we have to change the default manually if (newDefault != null) { newColumn.setDefaultValue(null); } if (hasDefault) { // we're dropping the old default writeDropConstraintStatement(table, curColumn, "D"); } print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("ALTER COLUMN "); writeColumn(table, newColumn); printEndOfStatement(); if (shallHaveDefault) { newColumn.setDefaultValue(newDefault); // if the column shall have a default, then we have to add it as a constraint print("ALTER TABLE "); printlnIdentifier(getTableName(table)); printIndent(); print("ADD CONSTRAINT "); printIdentifier(getConstraintName("DF", table, curColumn.getName(), null)); writeColumnDefaultValueStmt(table, newColumn); print(" FOR "); printIdentifier(getColumnName(curColumn)); printEndOfStatement(); } }