Search in sources :

Example 21 with IIndex

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;
}
Also used : IIndex(org.jumpmind.db.model.IIndex) Table(org.jumpmind.db.model.Table) HashMap(java.util.HashMap) Column(org.jumpmind.db.model.Column) PlatformColumn(org.jumpmind.db.model.PlatformColumn)

Aggregations

IIndex (org.jumpmind.db.model.IIndex)21 Column (org.jumpmind.db.model.Column)9 Table (org.jumpmind.db.model.Table)7 ForeignKey (org.jumpmind.db.model.ForeignKey)6 IndexColumn (org.jumpmind.db.model.IndexColumn)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 PlatformColumn (org.jumpmind.db.model.PlatformColumn)4 Reference (org.jumpmind.db.model.Reference)4 PreparedStatement (java.sql.PreparedStatement)3 LinkedHashMap (java.util.LinkedHashMap)3 IOException (java.io.IOException)2 ListOrderedMap (org.apache.commons.collections.map.ListOrderedMap)2 NonUniqueIndex (org.jumpmind.db.model.NonUniqueIndex)2 UniqueIndex (org.jumpmind.db.model.UniqueIndex)2 IoException (org.jumpmind.exception.IoException)2 HashSet (java.util.HashSet)1 AddColumnChange (org.jumpmind.db.alter.AddColumnChange)1 AddForeignKeyChange (org.jumpmind.db.alter.AddForeignKeyChange)1