Java Code Examples for org.apache.ddlutils.model.Column#setSize()
The following examples show how to use
org.apache.ddlutils.model.Column#setSize() .
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: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * 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 3
Source File: ColumnDefinitionChange.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void apply(Database model, boolean caseSensitive) { Column column = findChangedColumn(model, caseSensitive); column.setTypeCode(_newColumnDef.getTypeCode()); column.setSize(_newColumnDef.getSize()); column.setAutoIncrement(_newColumnDef.isAutoIncrement()); column.setRequired(_newColumnDef.isRequired()); column.setDescription(_newColumnDef.getDescription()); column.setDefaultValue(_newColumnDef.getDefaultValue()); }
Example 4
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column value contains the '<' character. */ public void testColumnValueContainsLessCharacter() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = "foo<bar"; idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); 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(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column column-name=\"foo<bar\">" + testedValue + "</column>\n" + " </test>\n" + "</data>\n"); }
Example 5
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when the table name contains a '<' character. */ public void testTableNameContainsLessCharacter() throws Exception { String tableName = "test<table"; 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 table-name=\"test<table\" id=\"1\" value=\"" + testedValue + "\" />\n" + "</data>\n"); }
Example 6
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 7
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column value contains the '>' character. */ public void testColumnValueContainsMoreCharacter() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = "foo>bar"; idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); 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(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column column-name=\"foo>bar\">" + testedValue + "</column>\n" + " </test>\n" + "</data>\n"); }
Example 8
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column value contains the '<' character. */ public void testColumnValueContainsLessCharacter() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = "foo<bar"; idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); 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(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column column-name=\"foo<bar\">" + testedValue + "</column>\n" + " </test>\n" + "</data>\n"); }
Example 9
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column value contains the '&' character. */ public void testColumnValueContainsAmpersand() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = "foo&bar"; idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); 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(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column column-name=\"foo&bar\">" + testedValue + "</column>\n" + " </test>\n" + "</data>\n"); }
Example 10
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column value contains an invalid character. */ public void testColumnValueContainsInvalidCharacters() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = "the\u0000value"; idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); 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(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(columnName.getBytes("UTF-8")), "UTF-8") + "</column-name>\n" + " <column-value>" + testedValue + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
Example 11
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column name is not a valid tag, * and the value is invalid, and both are short. */ public void testColumnNameAndValueLongAndInvalid() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = StringUtils.repeat("the\u0000name", 100); idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); table.addColumn(idColumn); table.addColumn(valueColumn); model.addTable(table); SqlDynaBean bean = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0)); String testedValue = StringUtils.repeat("the\u0000value", 40); bean.set("id", new Integer(1)); bean.set(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(columnName.getBytes("UTF-8")), "UTF-8") + "</column-name>\n" + " <column-value " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(testedValue.getBytes("UTF-8")), "UTF-8") + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
Example 12
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when the table name contains a '>' character. */ public void testTableNameContainsMoreCharacter() throws Exception { String tableName = "test>table"; 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 table-name=\"test>table\" id=\"1\" value=\"" + testedValue + "\" />\n" + "</data>\n"); }
Example 13
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column name is not a valid tag, * and the value is invalid, and both are short. */ public void testColumnNameAndValueLongAndInvalid() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = StringUtils.repeat("the\u0000name", 100); idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); table.addColumn(idColumn); table.addColumn(valueColumn); model.addTable(table); SqlDynaBean bean = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0)); String testedValue = StringUtils.repeat("the\u0000value", 40); bean.set("id", new Integer(1)); bean.set(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column>\n" + " <column-name " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(columnName.getBytes("UTF-8")), "UTF-8") + "</column-name>\n" + " <column-value " + DatabaseIO.BASE64_ATTR_NAME + "=\"true\">" + new String(Base64.encodeBase64(testedValue.getBytes("UTF-8")), "UTF-8") + "</column-value>\n" + " </column>\n" + " </test>\n" + "</data>\n"); }
Example 14
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when a column value contains the '&' character. */ public void testColumnValueContainsAmpersand() throws Exception { Database model = new Database("test"); Table table = new Table(); Column idColumn = new Column(); Column valueColumn = new Column(); String columnName = "foo&bar"; idColumn.setName("id"); idColumn.setType("INTEGER"); idColumn.setPrimaryKey(true); idColumn.setRequired(true); valueColumn.setName(columnName); valueColumn.setType("VARCHAR"); valueColumn.setSize("50"); valueColumn.setRequired(true); table.setName("test"); 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(columnName, testedValue); roundtripTest(model, bean, "UTF-8", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<data>\n" + " <test id=\"1\">\n" + " <column column-name=\"foo&bar\">" + testedValue + "</column>\n" + " </test>\n" + "</data>\n"); }
Example 15
Source File: JdbcSchemaManager.java From eagle with Apache License 2.0 | 5 votes |
private void buildTable(Table table) { Column id = new Column(); id.setName("id"); id.setPrimaryKey(true); id.setRequired(true); id.setTypeCode(Types.VARCHAR); id.setSize("50"); table.addColumn(id); Column value = new Column(); value.setName("value"); value.setTypeCode(Types.CLOB); table.addColumn(value); }
Example 16
Source File: ColumnDefinitionChange.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public void apply(Database model, boolean caseSensitive) { Column column = findChangedColumn(model, caseSensitive); column.setTypeCode(_newColumnDef.getTypeCode()); column.setSize(_newColumnDef.getSize()); column.setAutoIncrement(_newColumnDef.isAutoIncrement()); column.setRequired(_newColumnDef.isRequired()); column.setDescription(_newColumnDef.getDescription()); column.setDefaultValue(_newColumnDef.getDefaultValue()); }
Example 17
Source File: TestDataReaderAndWriter.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tests the reader & writer behavior when the table name contains a '&' character. */ public void testTableNameContainsAmpersand() throws Exception { String tableName = "test&table"; 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 table-name=\"test&table\" id=\"1\" value=\"" + testedValue + "\" />\n" + "</data>\n"); }
Example 18
Source File: TestAgainstLiveDatabaseBase.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Returns a copy of the given model adjusted for type changes because of the native type mappings * which when read back from the database will map to different types. * * @param sourceModel The source model * @return The adjusted model */ protected Database adjustModel(Database sourceModel) { Database model = new CloneHelper().clone(sourceModel); for (int tableIdx = 0; tableIdx < model.getTableCount(); tableIdx++) { Table table = model.getTable(tableIdx); for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++) { Column column = table.getColumn(columnIdx); int origType = column.getTypeCode(); int targetType = getPlatformInfo().getTargetJdbcType(origType); // we adjust the column types if the native type would back-map to a // different jdbc type if (targetType != origType) { column.setTypeCode(targetType); // we should also adapt the default value if (column.getDefaultValue() != null) { DefaultValueHelper helper = getPlatform().getSqlBuilder().getDefaultValueHelper(); column.setDefaultValue(helper.convert(column.getDefaultValue(), origType, targetType)); } } // we also promote the default size if the column has no size // spec of its own if ((column.getSize() == null) && getPlatformInfo().hasSize(targetType)) { Integer defaultSize = getPlatformInfo().getDefaultSize(targetType); if (defaultSize != null) { column.setSize(defaultSize.toString()); } } // finally the platform might return a synthetic default value if the column // is a primary key column if (getPlatformInfo().isSyntheticDefaultValueForRequiredReturned() && (column.getDefaultValue() == null) && column.isRequired() && !column.isAutoIncrement()) { switch (column.getTypeCode()) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: column.setDefaultValue("0"); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: column.setDefaultValue("0.0"); break; case Types.BIT: column.setDefaultValue("false"); break; default: column.setDefaultValue(""); break; } } if (column.isPrimaryKey() && getPlatformInfo().isPrimaryKeyColumnAutomaticallyRequired()) { column.setRequired(true); } if (column.isAutoIncrement() && getPlatformInfo().isIdentityColumnAutomaticallyRequired()) { column.setRequired(true); } } // we also add the default names to foreign keys that are initially unnamed for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++) { ForeignKey fk = table.getForeignKey(fkIdx); if (fk.getName() == null) { fk.setName(getPlatform().getSqlBuilder().getForeignKeyName(table, fk)); } } } return model; }
Example 19
Source File: DatabaseIO.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Reads a column element from the XML stream reader. * * @param xmlReader The reader * @return The column object */ private Column readColumnElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException { Column column = new Column(); for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME)) { column.setName(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_PRIMARY_KEY)) { column.setPrimaryKey(getAttributeValueAsBoolean(xmlReader, idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_REQUIRED)) { column.setRequired(getAttributeValueAsBoolean(xmlReader, idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_TYPE)) { column.setType(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE)) { column.setSize(getAttributeValueBeingNullAware(xmlReader, idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT)) { column.setDefaultValue(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_AUTO_INCREMENT)) { column.setAutoIncrement(getAttributeValueAsBoolean(xmlReader, idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DESCRIPTION)) { column.setDescription(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_JAVA_NAME)) { column.setJavaName(xmlReader.getAttributeValue(idx)); } } consumeRestOfElement(xmlReader); 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; }