use of org.jumpmind.db.model.IIndex in project symmetric-ds by JumpMind.
the class Db2As400DdlReader method readIndices.
@Override
protected Collection<IIndex> readIndices(Connection connection, DatabaseMetaDataWrapper metaData, String tableName) throws SQLException {
Map<String, IIndex> indices = new LinkedHashMap<String, IIndex>();
if (getPlatformInfo().isIndicesSupported()) {
ResultSet indexData = null;
try {
indexData = metaData.getIndices(getTableNamePatternForConstraints(tableName), false, false);
Collection<Column> columns = readColumns(metaData, tableName);
while (indexData.next()) {
Map<String, Object> values = readMetaData(indexData, getColumnsForIndex());
String columnName = (String) values.get("COLUMN_NAME");
if (hasColumn(columns, columnName)) {
readIndex(metaData, values, indices);
}
}
} finally {
close(indexData);
}
}
return indices.values();
}
use of org.jumpmind.db.model.IIndex in project symmetric-ds by JumpMind.
the class AbstractJdbcDdlReader method removeInternalForeignKeyIndex.
/*
* 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(Connection connection, DatabaseMetaDataWrapper metaData, Table table, ForeignKey fk) throws SQLException {
List<String> columnNames = new ArrayList<String>();
for (int columnIdx = 0; columnIdx < fk.getReferenceCount(); columnIdx++) {
columnNames.add(fk.getReference(columnIdx).getLocalColumnName());
}
for (int indexIdx = 0; indexIdx < table.getIndexCount(); ) {
IIndex index = table.getIndex(indexIdx);
if (matches(index, columnNames) && isInternalForeignKeyIndex(connection, metaData, table, fk, index)) {
fk.setAutoIndexPresent(true);
table.removeIndex(indexIdx);
} else {
indexIdx++;
}
}
}
use of org.jumpmind.db.model.IIndex in project symmetric-ds by JumpMind.
the class AbstractDatabasePlatform method prefixIndexes.
protected void prefixIndexes(Table table, String tablePrefix, boolean storesUpperCaseIdentifiers) throws CloneNotSupportedException {
IIndex[] indexes = table.getIndices();
if (indexes != null) {
for (IIndex index : indexes) {
String prefixedName = tablePrefix + index.getName();
prefixedName = storesUpperCaseIdentifiers ? prefixedName.toUpperCase() : prefixedName.toLowerCase();
index.setName(prefixedName);
}
}
}
use of org.jumpmind.db.model.IIndex in project symmetric-ds by JumpMind.
the class AbstractDdlBuilder method writeExternalIndicesCreateStmt.
/**
* Writes the indexes of the given table.
*
* @param table
* The table
*/
protected void writeExternalIndicesCreateStmt(Table table, StringBuilder ddl) {
for (int idx = 0; idx < table.getIndexCount(); idx++) {
IIndex index = table.getIndex(idx);
if (!index.isUnique() && !databaseInfo.isIndicesSupported()) {
return;
}
writeExternalIndexCreateStmt(table, index, ddl);
}
}
use of org.jumpmind.db.model.IIndex in project symmetric-ds by JumpMind.
the class FirebirdDdlReader method readIndices.
@Override
protected Collection<IIndex> readIndices(Connection connection, DatabaseMetaDataWrapper metaData, String tableName) throws SQLException {
// Jaybird is not able to read indices when delimited identifiers are
// turned on, so we gather the data manually using Firebird's system tables
@SuppressWarnings("unchecked") Map<String, IIndex> indices = new ListOrderedMap();
StringBuilder query = new StringBuilder();
query.append("SELECT a.RDB$INDEX_NAME INDEX_NAME, b.RDB$RELATION_NAME TABLE_NAME, b.RDB$UNIQUE_FLAG NON_UNIQUE,");
query.append(" a.RDB$FIELD_POSITION ORDINAL_POSITION, a.RDB$FIELD_NAME COLUMN_NAME, 3 INDEX_TYPE");
query.append(" FROM RDB$INDEX_SEGMENTS a, RDB$INDICES b WHERE a.RDB$INDEX_NAME=b.RDB$INDEX_NAME AND b.RDB$RELATION_NAME = ?");
PreparedStatement stmt = connection.prepareStatement(query.toString());
ResultSet indexData = null;
stmt.setString(1, getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
try {
indexData = stmt.executeQuery();
while (indexData.next()) {
Map<String, Object> values = readMetaData(indexData, getColumnsForIndex());
// we have to reverse the meaning of the unique flag
values.put("NON_UNIQUE", Boolean.FALSE.equals(values.get("NON_UNIQUE")) ? Boolean.TRUE : Boolean.FALSE);
// and trim the names
values.put("INDEX_NAME", ((String) values.get("INDEX_NAME")).trim());
values.put("TABLE_NAME", ((String) values.get("TABLE_NAME")).trim());
values.put("COLUMN_NAME", ((String) values.get("COLUMN_NAME")).trim());
readIndex(metaData, values, indices);
}
} finally {
if (indexData != null) {
indexData.close();
}
}
return indices.values();
}
Aggregations