use of org.jumpmind.db.model.IIndex in project symmetric-ds by JumpMind.
the class PostgreSqlDdlReader method readTable.
@Override
protected Table readTable(Connection connection, DatabaseMetaDataWrapper metaData, Map<String, Object> values) throws SQLException {
Table table = super.readTable(connection, metaData, values);
if (table != null) {
// PostgreSQL also returns unique indices for non-pk auto-increment
// columns which are of the form "[table]_[column]_key"
HashMap<String, IIndex> uniquesByName = new HashMap<String, IIndex>();
for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++) {
IIndex 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() && !column.isPrimaryKey()) {
String indexName = table.getName() + "_" + column.getName() + "_key";
if (uniquesByName.containsKey(indexName)) {
table.removeIndex((IIndex) uniquesByName.get(indexName));
uniquesByName.remove(indexName);
}
}
}
setPrimaryKeyConstraintName(connection, table);
}
return table;
}
Aggregations