use of org.apache.commons.collections.map.ListOrderedMap in project symmetric-ds by JumpMind.
the class InterbaseDdlReader 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, b.RDB$RELATION_NAME, b.RDB$UNIQUE_FLAG, ");
query.append(" a.RDB$FIELD_POSITION, a.RDB$FIELD_NAME ");
query.append(" FROM RDB$INDEX_SEGMENTS a, RDB$INDICES b ");
query.append(" 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 = new HashMap<String, Object>();
values.put("INDEX_NAME", indexData.getString(1).trim());
values.put("TABLE_NAME", indexData.getString(2).trim());
values.put("NON_UNIQUE", !indexData.getBoolean(3));
values.put("ORDINAL_POSITION", indexData.getShort(4));
values.put("COLUMN_NAME", indexData.getString(5).trim());
values.put("INDEX_TYPE", 3);
readIndex(metaData, values, indices);
}
} finally {
if (indexData != null) {
indexData.close();
}
}
return indices.values();
}
use of org.apache.commons.collections.map.ListOrderedMap in project symmetric-ds by JumpMind.
the class InformixDdlReader method readIndices.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Collection<IIndex> readIndices(Connection connection, DatabaseMetaDataWrapper metaData, String tableName) throws SQLException {
String sql = "select rtrim(dbinfo('dbname')) as TABLE_CAT, st.owner as TABLE_SCHEM, st.tabname as TABLE_NAME, " + "case when idxtype = 'U' then 0 else 1 end NON_UNIQUE, si.owner as INDEX_QUALIFIER, si.idxname as INDEX_NAME, " + "3 as TYPE, " + "case when sc.colno = si.part1 then 1 " + "when sc.colno = si.part1 then 1 " + "when sc.colno = si.part2 then 2 " + "when sc.colno = si.part3 then 3 " + "when sc.colno = si.part4 then 4 " + "when sc.colno = si.part5 then 5 " + "when sc.colno = si.part6 then 6 " + "when sc.colno = si.part7 then 7 " + "when sc.colno = si.part8 then 8 " + "else 0 end as ORDINAL_POSITION, " + "sc.colname as COLUMN_NAME, " + "null::varchar as ASC_OR_DESC, 0 as CARDINALITY, 0 as PAGES, null::varchar as FILTER_CONDITION " + "from sysindexes si " + "inner join systables st on si.tabid = st.tabid " + "inner join syscolumns sc on si.tabid = sc.tabid " + "where st.tabname like ? " + "and (sc.colno = si.part1 or sc.colno = si.part2 or sc.colno = si.part3 or " + "sc.colno = si.part4 or sc.colno = si.part5 or sc.colno = si.part6 or " + "sc.colno = si.part7 or sc.colno = si.part8) and " + "si.idxname not in (select idxname from sysconstraints where constrtype in ('R'))";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, tableName);
ResultSet rs = ps.executeQuery();
Map indices = new ListOrderedMap();
while (rs.next()) {
Map values = readMetaData(rs, getColumnsForIndex());
readIndex(metaData, values, indices);
}
rs.close();
ps.close();
return indices.values();
}
Aggregations