*/
protected Collection readIndices(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
Map indices = new ListOrderedMap();
StringBuffer query = new StringBuffer();
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 = getConnection().prepareStatement(query.toString());
ResultSet indexData = null;
stmt.setString(1, getPlatform().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
try
{
indexData = stmt.executeQuery();
while (indexData.next())
{
Map values = readColumns(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();
}