use of org.jumpmind.db.model.PlatformColumn in project symmetric-ds by JumpMind.
the class PostgreSqlDdlReader method readColumn.
@Override
protected Column readColumn(DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
Column column = super.readColumn(metaData, values);
PlatformColumn platformColumn = column.findPlatformColumn(platform.getName());
if (platformColumn != null && "serial".equals(platformColumn.getType()) || "serial4".equals(platformColumn.getType())) {
platformColumn.setType("int4");
} else if (platformColumn != null && "bigserial".equals(platformColumn.getType()) || "serial8".equals(platformColumn.getType())) {
platformColumn.setType("int8");
}
if (column.getSize() != null) {
if (column.getSizeAsInt() <= 0) {
column.setSize(null);
// map them to LONGVARBINARY/LONGVARCHAR
if (column.getMappedTypeCode() == Types.BINARY) {
column.setMappedTypeCode(Types.LONGVARBINARY);
} else if (column.getMappedTypeCode() == Types.VARCHAR) {
column.setMappedTypeCode(Types.LONGVARCHAR);
}
} else // on columns defined as TEXT.
if (column.getSizeAsInt() == Integer.MAX_VALUE) {
column.setSize(null);
if (column.getMappedTypeCode() == Types.VARCHAR) {
column.setMappedTypeCode(Types.LONGVARCHAR);
} else if (column.getMappedTypeCode() == Types.BINARY) {
column.setMappedTypeCode(Types.LONGVARBINARY);
}
} else if (column.getSizeAsInt() == 131089 && column.getJdbcTypeCode() == Types.NUMERIC) {
column.setSizeAndScale(0, 0);
column.setMappedTypeCode(Types.DECIMAL);
if (platformColumn != null) {
platformColumn.setSize(-1);
platformColumn.setDecimalDigits(-1);
}
}
}
String defaultValue = column.getDefaultValue();
if ((defaultValue != null) && (defaultValue.length() > 0)) {
// then it is an auto-increment column
if (defaultValue.startsWith("nextval(") || (PostgreSqlDdlBuilder.isUsePseudoSequence() && defaultValue.endsWith("seq()"))) {
column.setAutoIncrement(true);
defaultValue = null;
} else {
// "'some value'::character varying" or "'2000-01-01'::date"
switch(column.getMappedTypeCode()) {
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.getMappedTypeCode())) {
// 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;
}
Aggregations