Java Code Examples for org.apache.ddlutils.model.Column#getSizeAsInt()
The following examples show how to use
org.apache.ddlutils.model.Column#getSizeAsInt() .
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: GemFireXDBuilder.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Returns the database-native type for the given column. * * @param column * The column * @return The native type */ @Override protected String getNativeType(Column column) { // if the size of types overflows, then try to go to the next larger // type (e.g. see #43238) final int columnSize = column.getSizeAsInt(); final int columnType = column.getTypeCode(); if (columnSize > 0) { final ColumnSizeSpec sizeSpec = this._maxSizes.get(columnType); if (sizeSpec != null && columnSize >= sizeSpec._size) { return sizeSpec._higherType; } } // boost TINYINT and SMALLINT autoincrement columns to INT (#43227) if (column.isAutoIncrement()) { switch (column.getTypeCode()) { case Types.TINYINT: case Types.SMALLINT: return "INTEGER"; } } final String nativeType = getPlatformInfo().getNativeType(columnType); return nativeType != null ? nativeType : column.getType(); }
Example 2
Source File: ColumnDefinitionChange.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Determines whether the size or precision/scale of the given target column is smaller than that of the given source column. * If size and precision/scale do not matter for the target column's type, then <code>false</code> is returned. Note that for * columns with precision & scale, it also counted as being smaller if the scale of the target column is smaller than the * one of the source column, regardless of whether the precision of the target column is smaller than precision of the source * column or equal to it or even bigger. The reason for this is that the reduced scale would still potentially lead to truncation * errors. * * @param platformInfo The info object for the current platform * @param sourceColumn The source column * @param targetColumn The target column * @return <code>true</code> if the size of the target column is smaller */ public static boolean isSizeReduced(PlatformInfo platformInfo, Column sourceColumn, Column targetColumn) { int targetTypeCode = platformInfo.getTargetJdbcType(targetColumn.getTypeCode()); boolean sizeMatters = platformInfo.hasSize(targetTypeCode); boolean scaleMatters = platformInfo.hasPrecisionAndScale(targetTypeCode); if (sizeMatters && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt())) { return true; } else if (scaleMatters && ((sourceColumn.getPrecisionRadix() > targetColumn.getPrecisionRadix()) || (sourceColumn.getScale() > targetColumn.getScale()))) { return true; } else { return false; } }
Example 3
Source File: SapDbModelReader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getDefaultValue() != null) { // SapDb pads the default value with spaces column.setDefaultValue(column.getDefaultValue().trim()); // SapDb uses the default value for the auto-increment specification if (column.getDefaultValue().startsWith("DEFAULT SERIAL")) { column.setAutoIncrement(true); column.setDefaultValue(null); } } if (column.getTypeCode() == Types.DECIMAL) { // We also perform back-mapping to BIGINT if ((column.getSizeAsInt() == 38) && (column.getScale() == 0)) { column.setTypeCode(Types.BIGINT); } } return column; }
Example 4
Source File: GemFireXDBuilder.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Returns the database-native type for the given column. * * @param column * The column * @return The native type */ @Override protected String getNativeType(Column column) { // if the size of types overflows, then try to go to the next larger // type (e.g. see #43238) final int columnSize = column.getSizeAsInt(); final int columnType = column.getTypeCode(); if (columnSize > 0) { final ColumnSizeSpec sizeSpec = this._maxSizes.get(columnType); if (sizeSpec != null && columnSize >= sizeSpec._size) { return sizeSpec._higherType; } } // boost TINYINT and SMALLINT autoincrement columns to INT (#43227) if (column.isAutoIncrement()) { switch (column.getTypeCode()) { case Types.TINYINT: case Types.SMALLINT: return "INTEGER"; } } final String nativeType = getPlatformInfo().getNativeType(columnType); return nativeType != null ? nativeType : column.getType(); }
Example 5
Source File: ColumnDefinitionChange.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Determines whether the size or precision/scale of the given target column is smaller than that of the given source column. * If size and precision/scale do not matter for the target column's type, then <code>false</code> is returned. Note that for * columns with precision & scale, it also counted as being smaller if the scale of the target column is smaller than the * one of the source column, regardless of whether the precision of the target column is smaller than precision of the source * column or equal to it or even bigger. The reason for this is that the reduced scale would still potentially lead to truncation * errors. * * @param platformInfo The info object for the current platform * @param sourceColumn The source column * @param targetColumn The target column * @return <code>true</code> if the size of the target column is smaller */ public static boolean isSizeReduced(PlatformInfo platformInfo, Column sourceColumn, Column targetColumn) { int targetTypeCode = platformInfo.getTargetJdbcType(targetColumn.getTypeCode()); boolean sizeMatters = platformInfo.hasSize(targetTypeCode); boolean scaleMatters = platformInfo.hasPrecisionAndScale(targetTypeCode); if (sizeMatters && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt())) { return true; } else if (scaleMatters && ((sourceColumn.getPrecisionRadix() > targetColumn.getPrecisionRadix()) || (sourceColumn.getScale() > targetColumn.getScale()))) { return true; } else { return false; } }
Example 6
Source File: SapDbModelReader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getDefaultValue() != null) { // SapDb pads the default value with spaces column.setDefaultValue(column.getDefaultValue().trim()); // SapDb uses the default value for the auto-increment specification if (column.getDefaultValue().startsWith("DEFAULT SERIAL")) { column.setAutoIncrement(true); column.setDefaultValue(null); } } if (column.getTypeCode() == Types.DECIMAL) { // We also perform back-mapping to BIGINT if ((column.getSizeAsInt() == 38) && (column.getScale() == 0)) { column.setTypeCode(Types.BIGINT); } } return column; }
Example 7
Source File: Oracle9Builder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected String getNativeType(Column column) { // convert the type to DATE or TIMESTAMP depending on precision // the JDBC type was converted to TIMESTAMP for both by Oracle8ModelReader // getColumn method, but the precision will still help us determine the // actual type to use (see comments in #45096) final int typeCode = column.getTypeCode(); if (typeCode == Types.TIMESTAMP) { if (column.getSizeAsInt() <= 7) { return "DATE"; } } return super.getNativeType(column); }
Example 8
Source File: MSSqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException { boolean sizeChanged = ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn); boolean typeChanged = ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), sourceColumn, targetColumn); if (sizeChanged || typeChanged) { if (TypeMap.isTextType(targetColumn.getTypeCode()) && sizeChanged && (targetColumn.getSize() != null) && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt())) { print("SUBSTRING(CAST("); printIdentifier(getColumnName(sourceColumn)); print(" AS "); print(getNativeType(targetColumn)); print("),1,"); print(getSizeSpec(targetColumn)); print(")"); } else { print("CAST("); printIdentifier(getColumnName(sourceColumn)); print(" AS "); print(getSqlType(targetColumn)); print(")"); } } else { printIdentifier(getColumnName(sourceColumn)); } }
Example 9
Source File: HsqlDbBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException { boolean sizeChanged = ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn); boolean typeChanged = ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), sourceColumn, targetColumn); if (sizeChanged || typeChanged) { boolean needSubstr = TypeMap.isTextType(targetColumn.getTypeCode()) && sizeChanged && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt()); if (needSubstr) { print("SUBSTR("); } print("CAST("); printIdentifier(getColumnName(sourceColumn)); print(" AS "); if (needSubstr) { print(getNativeType(targetColumn)); } else { print(getSqlType(targetColumn)); } print(")"); if (needSubstr) { print(",1,"); print(targetColumn.getSize()); print(")"); } } else { super.writeCastExpression(sourceColumn, targetColumn); } }
Example 10
Source File: MckoiModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getSize() != null) { if (column.getSizeAsInt() <= 0) { column.setSize(null); } } String defaultValue = column.getDefaultValue(); if (defaultValue != null) { if (defaultValue.toLowerCase().startsWith("nextval('") || defaultValue.toLowerCase().startsWith("uniquekey('")) { column.setDefaultValue(null); column.setAutoIncrement(true); } else if (TypeMap.isTextType(column.getTypeCode())) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "\\'")); } } return column; }
Example 11
Source File: FirebirdBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException { boolean sizeChanged = ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn); boolean typeChanged = ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), sourceColumn, targetColumn); if (sizeChanged || typeChanged) { boolean needSubstr = TypeMap.isTextType(targetColumn.getTypeCode()) && sizeChanged && (targetColumn.getSize() != null) && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt()); if (needSubstr) { print("SUBSTRING("); } // we're not using CAST but instead string construction which does not require us to know the size print("("); printIdentifier(getColumnName(sourceColumn)); print(" || '' "); if (needSubstr) { print(") FROM 1 FOR "); print(targetColumn.getSize()); print(")"); } else { print(")"); } } else { super.writeCastExpression(sourceColumn, targetColumn); } }
Example 12
Source File: MaxDbModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getDefaultValue() != null) { // SapDb pads the default value with spaces column.setDefaultValue(column.getDefaultValue().trim()); // SapDb uses the default value for the auto-increment specification if (column.getDefaultValue().startsWith("DEFAULT SERIAL")) { column.setAutoIncrement(true); column.setDefaultValue(null); } } if (column.getTypeCode() == Types.DECIMAL) { // need to use COLUMN_SIZE for precision instead of NUM_PREC_RADIX column.setPrecisionRadix(column.getSizeAsInt()); // We also perform back-mapping to BIGINT if ((column.getSizeAsInt() == 38) && (column.getScale() == 0)) { column.setTypeCode(Types.BIGINT); } } return column; }
Example 13
Source File: MaxDbModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getDefaultValue() != null) { // SapDb pads the default value with spaces column.setDefaultValue(column.getDefaultValue().trim()); // SapDb uses the default value for the auto-increment specification if (column.getDefaultValue().startsWith("DEFAULT SERIAL")) { column.setAutoIncrement(true); column.setDefaultValue(null); } } if (column.getTypeCode() == Types.DECIMAL) { // need to use COLUMN_SIZE for precision instead of NUM_PREC_RADIX column.setPrecisionRadix(column.getSizeAsInt()); // We also perform back-mapping to BIGINT if ((column.getSizeAsInt() == 38) && (column.getScale() == 0)) { column.setTypeCode(Types.BIGINT); } } return column; }
Example 14
Source File: FirebirdBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException { boolean sizeChanged = ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn); boolean typeChanged = ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), sourceColumn, targetColumn); if (sizeChanged || typeChanged) { boolean needSubstr = TypeMap.isTextType(targetColumn.getTypeCode()) && sizeChanged && (targetColumn.getSize() != null) && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt()); if (needSubstr) { print("SUBSTRING("); } // we're not using CAST but instead string construction which does not require us to know the size print("("); printIdentifier(getColumnName(sourceColumn)); print(" || '' "); if (needSubstr) { print(") FROM 1 FOR "); print(targetColumn.getSize()); print(")"); } else { print(")"); } } else { super.writeCastExpression(sourceColumn, targetColumn); } }
Example 15
Source File: MckoiModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getSize() != null) { if (column.getSizeAsInt() <= 0) { column.setSize(null); } } String defaultValue = column.getDefaultValue(); if (defaultValue != null) { if (defaultValue.toLowerCase().startsWith("nextval('") || defaultValue.toLowerCase().startsWith("uniquekey('")) { column.setDefaultValue(null); column.setAutoIncrement(true); } else if (TypeMap.isTextType(column.getTypeCode())) { column.setDefaultValue(unescape(column.getDefaultValue(), "'", "\\'")); } } return column; }
Example 16
Source File: Oracle9Builder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected String getNativeType(Column column) { // convert the type to DATE or TIMESTAMP depending on precision // the JDBC type was converted to TIMESTAMP for both by Oracle8ModelReader // getColumn method, but the precision will still help us determine the // actual type to use (see comments in #45096) final int typeCode = column.getTypeCode(); if (typeCode == Types.TIMESTAMP) { if (column.getSizeAsInt() <= 7) { return "DATE"; } } return super.getNativeType(column); }
Example 17
Source File: MSSqlBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException { boolean sizeChanged = ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn); boolean typeChanged = ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), sourceColumn, targetColumn); if (sizeChanged || typeChanged) { if (TypeMap.isTextType(targetColumn.getTypeCode()) && sizeChanged && (targetColumn.getSize() != null) && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt())) { print("SUBSTRING(CAST("); printIdentifier(getColumnName(sourceColumn)); print(" AS "); print(getNativeType(targetColumn)); print("),1,"); print(getSizeSpec(targetColumn)); print(")"); } else { print("CAST("); printIdentifier(getColumnName(sourceColumn)); print(" AS "); print(getSqlType(targetColumn)); print(")"); } } else { printIdentifier(getColumnName(sourceColumn)); } }
Example 18
Source File: HsqlDbBuilder.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException { boolean sizeChanged = ColumnDefinitionChange.isSizeChanged(getPlatformInfo(), sourceColumn, targetColumn); boolean typeChanged = ColumnDefinitionChange.isTypeChanged(getPlatformInfo(), sourceColumn, targetColumn); if (sizeChanged || typeChanged) { boolean needSubstr = TypeMap.isTextType(targetColumn.getTypeCode()) && sizeChanged && (sourceColumn.getSizeAsInt() > targetColumn.getSizeAsInt()); if (needSubstr) { print("SUBSTR("); } print("CAST("); printIdentifier(getColumnName(sourceColumn)); print(" AS "); if (needSubstr) { print(getNativeType(targetColumn)); } else { print(getSqlType(targetColumn)); } print(")"); if (needSubstr) { print(",1,"); print(targetColumn.getSize()); print(")"); } } else { super.writeCastExpression(sourceColumn, targetColumn); } }
Example 19
Source File: PostgreSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getSize() != null) { if (column.getSizeAsInt() <= 0) { column.setSize(null); // PostgreSQL reports BYTEA and TEXT as BINARY(-1) and VARCHAR(-1) respectively // Since we cannot currently use the Blob/Clob interface with BYTEA, we instead // map them to LONGVARBINARY/LONGVARCHAR if (column.getTypeCode() == Types.BINARY) { column.setTypeCode(Types.LONGVARBINARY); } else if (column.getTypeCode() == Types.VARCHAR) { column.setTypeCode(Types.LONGVARCHAR); } } // fix issue DDLUTILS-165 as postgresql-8.2-504-jdbc3.jar seems to return Integer.MAX_VALUE // on columns defined as TEXT. else if (column.getSizeAsInt() == Integer.MAX_VALUE) { column.setSize(null); if (column.getTypeCode() == Types.VARCHAR) { column.setTypeCode(Types.LONGVARCHAR); } else if (column.getTypeCode() == Types.BINARY) { column.setTypeCode(Types.LONGVARBINARY); } } } String defaultValue = column.getDefaultValue(); if ((defaultValue != null) && (defaultValue.length() > 0)) { // If the default value looks like "nextval('ROUNDTRIP_VALUE_seq'::text)" // then it is an auto-increment column if (defaultValue.startsWith("nextval(")) { column.setAutoIncrement(true); defaultValue = null; } else { // PostgreSQL returns default values in the forms "-9000000000000000000::bigint" or // "'some value'::character varying" or "'2000-01-01'::date" switch (column.getTypeCode()) { case Types.INTEGER: case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: defaultValue = extractUndelimitedDefaultValue(defaultValue); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: defaultValue = extractDelimitedDefaultValue(defaultValue); break; } if (TypeMap.isTextType(column.getTypeCode())) { // We assume escaping via double quote (see also the backslash_quote setting: // http://www.postgresql.org/docs/7.4/interactive/runtime-config.html#RUNTIME-CONFIG-COMPATIBLE) defaultValue = unescape(defaultValue, "'", "''"); } } column.setDefaultValue(defaultValue); } return column; }
Example 20
Source File: PostgreSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Column column = super.readColumn(metaData, values); if (column.getSize() != null) { if (column.getSizeAsInt() <= 0) { column.setSize(null); // PostgreSQL reports BYTEA and TEXT as BINARY(-1) and VARCHAR(-1) respectively // Since we cannot currently use the Blob/Clob interface with BYTEA, we instead // map them to LONGVARBINARY/LONGVARCHAR if (column.getTypeCode() == Types.BINARY) { column.setTypeCode(Types.LONGVARBINARY); } else if (column.getTypeCode() == Types.VARCHAR) { column.setTypeCode(Types.LONGVARCHAR); } } // fix issue DDLUTILS-165 as postgresql-8.2-504-jdbc3.jar seems to return Integer.MAX_VALUE // on columns defined as TEXT. else if (column.getSizeAsInt() == Integer.MAX_VALUE) { column.setSize(null); if (column.getTypeCode() == Types.VARCHAR) { column.setTypeCode(Types.LONGVARCHAR); } else if (column.getTypeCode() == Types.BINARY) { column.setTypeCode(Types.LONGVARBINARY); } } } String defaultValue = column.getDefaultValue(); if ((defaultValue != null) && (defaultValue.length() > 0)) { // If the default value looks like "nextval('ROUNDTRIP_VALUE_seq'::text)" // then it is an auto-increment column if (defaultValue.startsWith("nextval(")) { column.setAutoIncrement(true); defaultValue = null; } else { // PostgreSQL returns default values in the forms "-9000000000000000000::bigint" or // "'some value'::character varying" or "'2000-01-01'::date" switch (column.getTypeCode()) { case Types.INTEGER: case Types.BIGINT: case Types.DECIMAL: case Types.NUMERIC: defaultValue = extractUndelimitedDefaultValue(defaultValue); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: defaultValue = extractDelimitedDefaultValue(defaultValue); break; } if (TypeMap.isTextType(column.getTypeCode())) { // We assume escaping via double quote (see also the backslash_quote setting: // http://www.postgresql.org/docs/7.4/interactive/runtime-config.html#RUNTIME-CONFIG-COMPATIBLE) defaultValue = unescape(defaultValue, "'", "''"); } } column.setDefaultValue(defaultValue); } return column; }