Java Code Examples for org.apache.ddlutils.model.Table#removeIndex()
The following examples show how to use
org.apache.ddlutils.model.Table#removeIndex() .
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: AxionModelReader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ protected void removeSystemIndices(DatabaseMetaDataWrapper metaData, Table table) throws SQLException { // Axion's JDBC driver does not support primary key reading, so we have to filter at this level for (int indexIdx = 0; indexIdx < table.getIndexCount();) { Index index = table.getIndex(indexIdx); // also, Axion's internal indices are not unique if (index.getName().startsWith("SYS_")) { table.removeIndex(indexIdx); } else { indexIdx++; } } }
Example 2
Source File: JdbcModelReader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Tries to remove the internal index for the table's primary key. * * @param metaData The database meta data * @param table The table */ protected void removeInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table) throws SQLException { Column[] pks = table.getPrimaryKeyColumns(); List columnNames = new ArrayList(); for (int columnIdx = 0; columnIdx < pks.length; columnIdx++) { columnNames.add(pks[columnIdx].getName()); } for (int indexIdx = 0; indexIdx < table.getIndexCount();) { Index index = table.getIndex(indexIdx); if (index.isUnique() && matches(index, columnNames) && isInternalPrimaryKeyIndex(metaData, table, index)) { table.removeIndex(indexIdx); } else { indexIdx++; } } }
Example 3
Source File: AxionModelReader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ protected void removeSystemIndices(DatabaseMetaDataWrapper metaData, Table table) throws SQLException { // Axion's JDBC driver does not support primary key reading, so we have to filter at this level for (int indexIdx = 0; indexIdx < table.getIndexCount();) { Index index = table.getIndex(indexIdx); // also, Axion's internal indices are not unique if (index.getName().startsWith("SYS_")) { table.removeIndex(indexIdx); } else { indexIdx++; } } }
Example 4
Source File: JdbcModelReader.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Tries to remove the internal index for the table's primary key. * * @param metaData The database meta data * @param table The table */ protected void removeInternalPrimaryKeyIndex(DatabaseMetaDataWrapper metaData, Table table) throws SQLException { Column[] pks = table.getPrimaryKeyColumns(); List columnNames = new ArrayList(); for (int columnIdx = 0; columnIdx < pks.length; columnIdx++) { columnNames.add(pks[columnIdx].getName()); } for (int indexIdx = 0; indexIdx < table.getIndexCount();) { Index index = table.getIndex(indexIdx); if (index.isUnique() && matches(index, columnNames) && isInternalPrimaryKeyIndex(metaData, table, index)) { table.removeIndex(indexIdx); } else { indexIdx++; } } }
Example 5
Source File: PostgreSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Table table = super.readTable(metaData, values); if (table != null) { // PostgreSQL also returns unique indexes for pk and non-pk auto-increment columns // which are of the form "[table]_[column]_key" HashMap uniquesByName = new HashMap(); for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++) { Index 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()) { String indexName = table.getName() + "_" + column.getName() + "_key"; if (uniquesByName.containsKey(indexName)) { table.removeIndex((Index)uniquesByName.get(indexName)); uniquesByName.remove(indexName); } } } } return table; }
Example 6
Source File: MSSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { String tableName = (String)values.get("TABLE_NAME"); for (int idx = 0; idx < KNOWN_SYSTEM_TABLES.length; idx++) { if (KNOWN_SYSTEM_TABLES[idx].equals(tableName)) { return null; } } Table table = super.readTable(metaData, values); if (table != null) { // Sql Server does not return the auto-increment status via the database metadata determineAutoIncrementFromResultSetMetaData(table, table.getColumns()); // TODO: Replace this manual filtering using named pks once they are available // This is then probably of interest to every platform for (int idx = 0; idx < table.getIndexCount();) { Index index = table.getIndex(idx); if (index.isUnique() && existsPKWithName(metaData, table, index.getName())) { table.removeIndex(idx); } else { idx++; } } } return table; }
Example 7
Source File: JdbcModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tries to remove the internal index for the given foreign key. * * @param metaData The database meta data * @param table The table where the table is defined * @param fk The foreign key */ protected void removeInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table, ForeignKey fk) throws SQLException { List columnNames = new ArrayList(); boolean mustBeUnique = !getPlatformInfo().isSystemForeignKeyIndicesAlwaysNonUnique(); for (int columnIdx = 0; columnIdx < fk.getReferenceCount(); columnIdx++) { String name = fk.getReference(columnIdx).getLocalColumnName(); Column localColumn = table.findColumn(name, getPlatform().isDelimitedIdentifierModeOn()); if (mustBeUnique && !localColumn.isPrimaryKey()) { mustBeUnique = false; } columnNames.add(name); } for (int indexIdx = 0; indexIdx < table.getIndexCount();) { Index index = table.getIndex(indexIdx); if ((!mustBeUnique || index.isUnique()) && matches(index, columnNames) && isInternalForeignKeyIndex(metaData, table, fk, index)) { fk.setAutoIndexPresent(true); table.removeIndex(indexIdx); } else { indexIdx++; } } }
Example 8
Source File: PostgreSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { Table table = super.readTable(metaData, values); if (table != null) { // PostgreSQL also returns unique indexes for pk and non-pk auto-increment columns // which are of the form "[table]_[column]_key" HashMap uniquesByName = new HashMap(); for (int indexIdx = 0; indexIdx < table.getIndexCount(); indexIdx++) { Index 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()) { String indexName = table.getName() + "_" + column.getName() + "_key"; if (uniquesByName.containsKey(indexName)) { table.removeIndex((Index)uniquesByName.get(indexName)); uniquesByName.remove(indexName); } } } } return table; }
Example 9
Source File: MSSqlModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException { String tableName = (String)values.get("TABLE_NAME"); for (int idx = 0; idx < KNOWN_SYSTEM_TABLES.length; idx++) { if (KNOWN_SYSTEM_TABLES[idx].equals(tableName)) { return null; } } Table table = super.readTable(metaData, values); if (table != null) { // Sql Server does not return the auto-increment status via the database metadata determineAutoIncrementFromResultSetMetaData(table, table.getColumns()); // TODO: Replace this manual filtering using named pks once they are available // This is then probably of interest to every platform for (int idx = 0; idx < table.getIndexCount();) { Index index = table.getIndex(idx); if (index.isUnique() && existsPKWithName(metaData, table, index.getName())) { table.removeIndex(idx); } else { idx++; } } } return table; }
Example 10
Source File: JdbcModelReader.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Tries to remove the internal index for the given foreign key. * * @param metaData The database meta data * @param table The table where the table is defined * @param fk The foreign key */ protected void removeInternalForeignKeyIndex(DatabaseMetaDataWrapper metaData, Table table, ForeignKey fk) throws SQLException { List columnNames = new ArrayList(); boolean mustBeUnique = !getPlatformInfo().isSystemForeignKeyIndicesAlwaysNonUnique(); for (int columnIdx = 0; columnIdx < fk.getReferenceCount(); columnIdx++) { String name = fk.getReference(columnIdx).getLocalColumnName(); Column localColumn = table.findColumn(name, getPlatform().isDelimitedIdentifierModeOn()); if (mustBeUnique && !localColumn.isPrimaryKey()) { mustBeUnique = false; } columnNames.add(name); } for (int indexIdx = 0; indexIdx < table.getIndexCount();) { Index index = table.getIndex(indexIdx); if ((!mustBeUnique || index.isUnique()) && matches(index, columnNames) && isInternalForeignKeyIndex(metaData, table, fk, index)) { fk.setAutoIndexPresent(true); table.removeIndex(indexIdx); } else { indexIdx++; } } }