Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2011-07-26 13:30:01 -0400
committerRyan D. Brooks2011-07-26 13:30:01 -0400
commit3453bd458333e2bae61b711796aa33b8865eee6b (patch)
tree32cb21aa8d20b467ff3609dee7e0e6ac9e904288 /plugins/org.eclipse.osee.framework.core.datastore
parentcd99d08062843397efa1690f4d7769d4bc4acb7f (diff)
downloadorg.eclipse.osee-3453bd458333e2bae61b711796aa33b8865eee6b.tar.gz
org.eclipse.osee-3453bd458333e2bae61b711796aa33b8865eee6b.tar.xz
org.eclipse.osee-3453bd458333e2bae61b711796aa33b8865eee6b.zip
bug[ats_LCBBP]: Ensure connections are closed when reading database schema
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.datastore')
-rw-r--r--plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/ExtractDatabaseSchemaOperation.java571
1 files changed, 283 insertions, 288 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/ExtractDatabaseSchemaOperation.java b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/ExtractDatabaseSchemaOperation.java
index 14c3ce048f..552ef8ee05 100644
--- a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/ExtractDatabaseSchemaOperation.java
+++ b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/ExtractDatabaseSchemaOperation.java
@@ -51,24 +51,25 @@ import org.eclipse.osee.framework.jdk.core.util.Strings;
*/
public class ExtractDatabaseSchemaOperation extends AbstractOperation {
private static final String DEFAULT_FILTER = "BIN.*";
+ private static final Pattern sqlPattern = Pattern.compile("SQL\\d+");
private DatabaseMetaData dbData;
private String dbName;
private String dbVersion;
private final Map<String, SchemaData> database;
- private final List<String> filter;
- private final Set<String> tablesToExtract;
+ private final List<String> filter = new ArrayList<String>();
+ private final Set<String> tablesToExtract = new TreeSet<String>();
private final Set<String> schemas;
private final IOseeDatabaseService dbService;
+ private final Matcher indexMatcher;
public ExtractDatabaseSchemaOperation(IOseeDatabaseService dbService, Set<String> schemas, Map<String, SchemaData> schemaData) {
super("Extract Database Schema", Activator.PLUGIN_ID);
this.dbService = dbService;
this.schemas = schemas;
this.database = schemaData;
- this.filter = new ArrayList<String>();
filter.add(DEFAULT_FILTER);
- this.tablesToExtract = new TreeSet<String>();
+ this.indexMatcher = sqlPattern.matcher("");
}
@Override
@@ -93,39 +94,6 @@ public class ExtractDatabaseSchemaOperation extends AbstractOperation {
filter.add(value);
}
- // private Set<String> getAllSchemas() throws SQLException {
- // ResultSet schemaResults = dbData.getSchemas();
- // Set<String> schemaSet = new TreeSet<String>();
- //
- // while (schemaResults.next()) {
- // String schema = schemaResults.getString("TABLE_SCHEM");
- // if (Strings.isValid(schema)) {
- // schemaSet.add(schema);
- // }
- // }
- // schemaResults.close();
- // return schemaSet;
- // }
-
- // /**
- // * Writes the XML files in the directory specified.
- // *
- // * @param directory The directory tow write the XML files.
- // */
- // public void writeToFile(File directory) throws IOException {
- // FileUtility.setupDirectoryForWrite(directory);
- // Set<String> keys = database.keySet();
- // for (String schema : keys) {
- // SchemaData tableData = database.get(schema);
- // File xmlFile = new File(directory.getAbsolutePath() + File.separator + schema + FileUtility.SCHEMA_EXTENSION);
- // try {
- // Jaxp.writeXmlDocument(tableData.getXmlDocument(), xmlFile);
- // } catch (Exception ex) {
- // OseeLog.log(Activator.class, Level.SEVERE, ex);
- // }
- // }
- // }
-
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
@@ -159,325 +127,352 @@ public class ExtractDatabaseSchemaOperation extends AbstractOperation {
tablesToExtract.clear();
}
- private SchemaData getTableInformation(String schemaPattern) throws Exception {
+ private SchemaData getTableInformation(String schema) throws Exception {
SchemaData dbTables = new SchemaData();
- ResultSet tables = null;
- tables = dbData.getTables(null, null, null, new String[] {"TABLE"});
-
- while (tables.next()) {
- String tableName = tables.getString("TABLE_NAME").toUpperCase();
- String schemaName = tables.getString("TABLE_SCHEM");
- if (tableName != null && !isFiltered(tableName) && schemaName.equalsIgnoreCase(schemaPattern)) {
- boolean extract = true;
- if (this.tablesToExtract != null && this.tablesToExtract.size() > 0) {
- extract = tablesToExtract.contains(schemaPattern + "." + tableName);
- }
+ ResultSet resultSet = null;
+ try {
+ resultSet = dbData.getTables(null, schema, null, new String[] {"TABLE"});
+ if (resultSet != null) {
+ while (resultSet.next()) {
+ String tableName = resultSet.getString("TABLE_NAME").toUpperCase();
+ String schemaName = resultSet.getString("TABLE_SCHEM");
+ if (tableName != null && !isFiltered(tableName) && schemaName.equalsIgnoreCase(schema)) {
+ boolean extract = true;
+ if (!tablesToExtract.isEmpty()) {
+ extract = tablesToExtract.contains(schema + "." + tableName);
+ }
- if (extract) {
- TableElement tableEntry = new TableElement();
- tableEntry.addTableDescription(TableDescriptionFields.name, tableName);
- tableEntry.addTableDescription(TableDescriptionFields.schema, schemaName);
- getColumnInformation(tableEntry);
- getColumnPrimaryKey(tableEntry);
+ if (extract) {
+ TableElement tableEntry = new TableElement();
+ tableEntry.addTableDescription(TableDescriptionFields.name, tableName);
+ tableEntry.addTableDescription(TableDescriptionFields.schema, schemaName);
+ getColumnInformation(tableEntry);
+ getColumnPrimaryKey(tableEntry);
- if (!(SupportedDatabase.isDatabaseType(dbData, SupportedDatabase.foxpro) || SupportedDatabase.isDatabaseType(
- dbData, SupportedDatabase.postgresql))) {
- getColumnForeignKey(tableEntry);
+ if (!(SupportedDatabase.isDatabaseType(dbData, SupportedDatabase.foxpro) || SupportedDatabase.isDatabaseType(
+ dbData, SupportedDatabase.postgresql))) {
+ getColumnForeignKey(tableEntry);
+ }
+ getIndexInfo(tableEntry);
+ dbTables.addTableDefinition(tableEntry);
+ }
}
- getIndexInfo(tableEntry);
- dbTables.addTableDefinition(tableEntry);
}
}
+ } finally {
+ if (resultSet != null) {
+ resultSet.close();
+ }
}
- tables.close();
return dbTables;
}
private void getColumnInformation(TableElement aTable) throws Exception {
ResultSet columns = null;
try {
- columns = dbData.getColumns(null, aTable.getSchema(), aTable.getName(), null);
- } catch (SQLException ex) {
- columns = dbData.getColumns(null, null, aTable.getName(), null);
- }
- while (columns.next()) {
- String id = columns.getString("COLUMN_NAME");
- id = id.toUpperCase();
- ColumnMetadata column = new ColumnMetadata(id);
-
- int dataType = columns.getInt("DATA_TYPE");
- if (SupportedDatabase.isDatabaseType(dbData, SupportedDatabase.foxpro)) {
- if (dataType == Types.CHAR) {
- dataType = Types.VARCHAR;
- }
- }
- String dataTypeName = SQL3DataType.get(dataType).name();
- column.addColumnField(ColumnFields.type, dataTypeName);
-
- String defaultValue = "";
- int defaultType = columns.getInt("NULLABLE");
- switch (defaultType) {
- case java.sql.DatabaseMetaData.columnNoNulls:
- defaultValue = "not null";
- break;
- case java.sql.DatabaseMetaData.columnNullable:
- // Dont specify if Null - Let DB Decide.
- defaultValue = "";
- break;
- case java.sql.DatabaseMetaData.columnNullableUnknown:
- default:
- // Since unknown then don't specify
- defaultValue = "";
- break;
+ try {
+ columns = dbData.getColumns(null, aTable.getSchema(), aTable.getName(), null);
+ } catch (SQLException ex) {
+ columns = dbData.getColumns(null, null, aTable.getName(), null);
}
- if (!defaultValue.equals("")) {
- column.addColumnField(ColumnFields.defaultValue, defaultValue);
- }
-
- if (!SupportedDatabase.isDatabaseType(dbData, SupportedDatabase.foxpro)) {
- // int dataType = columns.getInt("DATA_TYPE");
- switch (dataType) {
- case java.sql.Types.CHAR:
- case java.sql.Types.VARCHAR:
- String limits = columns.getString("COLUMN_SIZE");
- if (Strings.isValid(limits)) {
- column.addColumnField(ColumnFields.limits, limits);
- }
- break;
- case java.sql.Types.DECIMAL:
- case java.sql.Types.NUMERIC:
- limits = columns.getString("COLUMN_SIZE");
- String decimal = columns.getString("DECIMAL_DIGITS");
- if (Strings.isValid(decimal)) {
- if (Strings.isValid(limits)) {
- limits += "," + decimal;
- }
- }
- if (Strings.isValid(limits)) {
- column.addColumnField(ColumnFields.limits, limits);
- }
- default:
- break;
+ while (columns.next()) {
+ String id = columns.getString("COLUMN_NAME");
+ id = id.toUpperCase();
+ ColumnMetadata column = new ColumnMetadata(id);
+
+ int dataType = columns.getInt("DATA_TYPE");
+ if (SupportedDatabase.isDatabaseType(dbData, SupportedDatabase.foxpro)) {
+ if (dataType == Types.CHAR) {
+ dataType = Types.VARCHAR;
+ }
}
- } else {
- switch (dataType) {
- case java.sql.Types.CHAR:
- case java.sql.Types.VARCHAR:
- String limits = "255";
- column.addColumnField(ColumnFields.limits, limits);
+ String dataTypeName = SQL3DataType.get(dataType).name();
+ column.addColumnField(ColumnFields.type, dataTypeName);
+
+ String defaultValue = "";
+ int defaultType = columns.getInt("NULLABLE");
+ switch (defaultType) {
+ case java.sql.DatabaseMetaData.columnNoNulls:
+ defaultValue = "not null";
+ break;
+ case java.sql.DatabaseMetaData.columnNullable:
+ // Dont specify if Null - Let DB Decide.
+ defaultValue = "";
break;
+ case java.sql.DatabaseMetaData.columnNullableUnknown:
default:
+ // Since unknown then don't specify
+ defaultValue = "";
break;
}
+ if (!defaultValue.equals("")) {
+ column.addColumnField(ColumnFields.defaultValue, defaultValue);
+ }
+
+ if (!SupportedDatabase.isDatabaseType(dbData, SupportedDatabase.foxpro)) {
+ // int dataType = columns.getInt("DATA_TYPE");
+ switch (dataType) {
+ case java.sql.Types.CHAR:
+ case java.sql.Types.VARCHAR:
+ String limits = columns.getString("COLUMN_SIZE");
+ if (Strings.isValid(limits)) {
+ column.addColumnField(ColumnFields.limits, limits);
+ }
+ break;
+ case java.sql.Types.DECIMAL:
+ case java.sql.Types.NUMERIC:
+ limits = columns.getString("COLUMN_SIZE");
+ String decimal = columns.getString("DECIMAL_DIGITS");
+ if (Strings.isValid(decimal)) {
+ if (Strings.isValid(limits)) {
+ limits += "," + decimal;
+ }
+ }
+ if (Strings.isValid(limits)) {
+ column.addColumnField(ColumnFields.limits, limits);
+ }
+ default:
+ break;
+ }
+ } else {
+ switch (dataType) {
+ case java.sql.Types.CHAR:
+ case java.sql.Types.VARCHAR:
+ String limits = "255";
+ column.addColumnField(ColumnFields.limits, limits);
+ break;
+ default:
+ break;
+ }
+ }
+ aTable.addColumn(column);
+ }
+ } finally {
+ if (columns != null) {
+ columns.close();
}
- aTable.addColumn(column);
}
- columns.close();
}
private void getColumnPrimaryKey(TableElement aTable) throws SQLException {
ResultSet primaryKeys = null;
try {
- primaryKeys = dbData.getPrimaryKeys(null, aTable.getSchema(), aTable.getName());
- } catch (SQLException ex) {
- primaryKeys = dbData.getPrimaryKeys(null, null, aTable.getName());
- }
- Map<String, Set<String>> constraintKeyMap = new HashMap<String, Set<String>>();
+ try {
+ primaryKeys = dbData.getPrimaryKeys(null, aTable.getSchema(), aTable.getName());
+ } catch (SQLException ex) {
+ primaryKeys = dbData.getPrimaryKeys(null, null, aTable.getName());
+ }
+ Map<String, Set<String>> constraintKeyMap = new HashMap<String, Set<String>>();
- while (primaryKeys.next()) {
- String column = primaryKeys.getString("COLUMN_NAME");
- String keyId = primaryKeys.getString("PK_NAME");
+ while (primaryKeys.next()) {
+ String column = primaryKeys.getString("COLUMN_NAME");
+ String keyId = primaryKeys.getString("PK_NAME");
- if (!Strings.isValid(keyId)) {
- keyId = column + "_PK";
- }
+ if (!Strings.isValid(keyId)) {
+ keyId = column + "_PK";
+ }
- if (!constraintKeyMap.containsKey(keyId)) {
- Set<String> set = new TreeSet<String>();
- set.add(column);
- constraintKeyMap.put(keyId, set);
- } else {
- Set<String> set = constraintKeyMap.get(keyId);
- if (!set.contains(column)) {
+ if (!constraintKeyMap.containsKey(keyId)) {
+ Set<String> set = new TreeSet<String>();
set.add(column);
+ constraintKeyMap.put(keyId, set);
+ } else {
+ Set<String> set = constraintKeyMap.get(keyId);
+ if (!set.contains(column)) {
+ set.add(column);
+ }
}
}
- }
- Set<String> keys = constraintKeyMap.keySet();
- for (String pk : keys) {
- ConstraintElement constraint =
- ConstraintFactory.getConstraint(ConstraintTypes.PRIMARY_KEY, aTable.getSchema(), pk, false);
- Set<String> columnSet = constraintKeyMap.get(pk);
- for (String column : columnSet) {
- constraint.addColumn(column);
+ Set<String> keys = constraintKeyMap.keySet();
+ for (String pk : keys) {
+ ConstraintElement constraint =
+ ConstraintFactory.getConstraint(ConstraintTypes.PRIMARY_KEY, aTable.getSchema(), pk, false);
+ Set<String> columnSet = constraintKeyMap.get(pk);
+ for (String column : columnSet) {
+ constraint.addColumn(column);
+ }
+ aTable.addConstraint(constraint);
+ }
+ } finally {
+ if (primaryKeys != null) {
+ primaryKeys.close();
}
- aTable.addConstraint(constraint);
}
- primaryKeys.close();
}
private void getColumnForeignKey(TableElement aTable) throws SQLException {
- ResultSet importedKeys = dbData.getImportedKeys(null, aTable.getSchema(), aTable.getName());
-
- while (importedKeys.next()) {
-
- String appliesToColumnId = importedKeys.getString("FKCOLUMN_NAME");
- String fkeyId = importedKeys.getString("FK_NAME");
- String fKeyAddress = importedKeys.getString("FKTABLE_SCHEM");
-
- String refersToTable = importedKeys.getString("PKTABLE_NAME");
- String refersToTableAddress = importedKeys.getString("PKTABLE_SCHEM");
- String referencesColumn = importedKeys.getString("PKCOLUMN_NAME");
-
- OnDeleteEnum onDeleteAction = OnDeleteEnum.UNSPECIFIED;
- String onDeleteRule = importedKeys.getString("DELETE_RULE");
- if (Strings.isValid(onDeleteRule)) {
- // System.out.println("onDelete: " + onDeleteRule);
- int type = Integer.parseInt(onDeleteRule);
- switch (type) {
- case java.sql.DatabaseMetaData.importedKeyNoAction:
- onDeleteAction = OnDeleteEnum.NO_ACTION;
- break;
- case java.sql.DatabaseMetaData.importedKeyRestrict:
- onDeleteAction = OnDeleteEnum.RESTRICT;
- break;
- case java.sql.DatabaseMetaData.importedKeyCascade:
- onDeleteAction = OnDeleteEnum.CASCADE;
- break;
- case java.sql.DatabaseMetaData.importedKeySetNull:
- onDeleteAction = OnDeleteEnum.SET_NULL;
- break;
- case java.sql.DatabaseMetaData.importedKeySetDefault:
- default:
- onDeleteAction = OnDeleteEnum.UNSPECIFIED;
- break;
+ ResultSet importedKeys = null;
+ try {
+ importedKeys = dbData.getImportedKeys(null, aTable.getSchema(), aTable.getName());
+
+ while (importedKeys.next()) {
+
+ String appliesToColumnId = importedKeys.getString("FKCOLUMN_NAME");
+ String fkeyId = importedKeys.getString("FK_NAME");
+ String fKeyAddress = importedKeys.getString("FKTABLE_SCHEM");
+
+ String refersToTable = importedKeys.getString("PKTABLE_NAME");
+ String refersToTableAddress = importedKeys.getString("PKTABLE_SCHEM");
+ String referencesColumn = importedKeys.getString("PKCOLUMN_NAME");
+
+ OnDeleteEnum onDeleteAction = OnDeleteEnum.UNSPECIFIED;
+ String onDeleteRule = importedKeys.getString("DELETE_RULE");
+ if (Strings.isValid(onDeleteRule)) {
+ // System.out.println("onDelete: " + onDeleteRule);
+ int type = Integer.parseInt(onDeleteRule);
+ switch (type) {
+ case java.sql.DatabaseMetaData.importedKeyNoAction:
+ onDeleteAction = OnDeleteEnum.NO_ACTION;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyRestrict:
+ onDeleteAction = OnDeleteEnum.RESTRICT;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyCascade:
+ onDeleteAction = OnDeleteEnum.CASCADE;
+ break;
+ case java.sql.DatabaseMetaData.importedKeySetNull:
+ onDeleteAction = OnDeleteEnum.SET_NULL;
+ break;
+ case java.sql.DatabaseMetaData.importedKeySetDefault:
+ default:
+ onDeleteAction = OnDeleteEnum.UNSPECIFIED;
+ break;
+ }
}
- }
- OnUpdateEnum onUpdateAction = OnUpdateEnum.UNSPECIFIED;
- String onUpdateRule = importedKeys.getString("UPDATE_RULE");
- if (Strings.isValid(onUpdateRule)) {
- // System.out.println("onUpdate: " + onUpdateRule);
- int type = Integer.parseInt(onUpdateRule);
- switch (type) {
- case java.sql.DatabaseMetaData.importedKeyNoAction:
- onUpdateAction = OnUpdateEnum.NO_ACTION;
- break;
- case java.sql.DatabaseMetaData.importedKeyRestrict:
- onUpdateAction = OnUpdateEnum.RESTRICT;
- break;
- case java.sql.DatabaseMetaData.importedKeyCascade:
- case java.sql.DatabaseMetaData.importedKeySetNull:
- case java.sql.DatabaseMetaData.importedKeySetDefault:
- default:
- onUpdateAction = OnUpdateEnum.UNSPECIFIED;
- break;
+ OnUpdateEnum onUpdateAction = OnUpdateEnum.UNSPECIFIED;
+ String onUpdateRule = importedKeys.getString("UPDATE_RULE");
+ if (Strings.isValid(onUpdateRule)) {
+ // System.out.println("onUpdate: " + onUpdateRule);
+ int type = Integer.parseInt(onUpdateRule);
+ switch (type) {
+ case java.sql.DatabaseMetaData.importedKeyNoAction:
+ onUpdateAction = OnUpdateEnum.NO_ACTION;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyRestrict:
+ onUpdateAction = OnUpdateEnum.RESTRICT;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyCascade:
+ case java.sql.DatabaseMetaData.importedKeySetNull:
+ case java.sql.DatabaseMetaData.importedKeySetDefault:
+ default:
+ onUpdateAction = OnUpdateEnum.UNSPECIFIED;
+ break;
+ }
}
- }
- boolean deferrable = false;
- String deferrabilityId = importedKeys.getString("DEFERRABILITY");
- if (Strings.isValid(deferrabilityId)) {
- int type = Integer.parseInt(deferrabilityId);
- switch (type) {
- case java.sql.DatabaseMetaData.importedKeyInitiallyDeferred:
- case java.sql.DatabaseMetaData.importedKeyInitiallyImmediate:
- deferrable = true;
- break;
- case java.sql.DatabaseMetaData.importedKeyNotDeferrable:
- deferrable = false;
- break;
- default:
- deferrable = false;
- break;
+ boolean deferrable = false;
+ String deferrabilityId = importedKeys.getString("DEFERRABILITY");
+ if (Strings.isValid(deferrabilityId)) {
+ int type = Integer.parseInt(deferrabilityId);
+ switch (type) {
+ case java.sql.DatabaseMetaData.importedKeyInitiallyDeferred:
+ case java.sql.DatabaseMetaData.importedKeyInitiallyImmediate:
+ deferrable = true;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyNotDeferrable:
+ deferrable = false;
+ break;
+ default:
+ deferrable = false;
+ break;
+ }
}
- }
- if (!Strings.isValid(fKeyAddress)) {
- fKeyAddress = aTable.getSchema();
- }
+ if (!Strings.isValid(fKeyAddress)) {
+ fKeyAddress = aTable.getSchema();
+ }
- if (!Strings.isValid(fkeyId)) {
- fkeyId = appliesToColumnId + "_FK";
- }
+ if (!Strings.isValid(fkeyId)) {
+ fkeyId = appliesToColumnId + "_FK";
+ }
- if (!Strings.isValid(refersToTableAddress)) {
- refersToTableAddress = aTable.getSchema();
- }
+ if (!Strings.isValid(refersToTableAddress)) {
+ refersToTableAddress = aTable.getSchema();
+ }
- ConstraintElement constraint =
- ConstraintFactory.getConstraint(ConstraintTypes.FOREIGN_KEY, fKeyAddress, fkeyId, deferrable);
- constraint.addColumn(appliesToColumnId);
+ ConstraintElement constraint =
+ ConstraintFactory.getConstraint(ConstraintTypes.FOREIGN_KEY, fKeyAddress, fkeyId, deferrable);
+ constraint.addColumn(appliesToColumnId);
- ReferenceClause ref = new ReferenceClause(refersToTableAddress, refersToTable);
- ref.addColumn(referencesColumn);
+ ReferenceClause ref = new ReferenceClause(refersToTableAddress, refersToTable);
+ ref.addColumn(referencesColumn);
- ref.setOnDeleteAction(onDeleteAction);
- ref.setOnUpdateAction(onUpdateAction);
+ ref.setOnDeleteAction(onDeleteAction);
+ ref.setOnUpdateAction(onUpdateAction);
- ((ForeignKey) constraint).addReference(ref);
+ ((ForeignKey) constraint).addReference(ref);
- aTable.addConstraint(constraint);
+ aTable.addConstraint(constraint);
+ }
+ } finally {
+ if (importedKeys != null) {
+ importedKeys.close();
+ }
}
- importedKeys.close();
}
private void getIndexInfo(TableElement aTable) throws SQLException {
- ResultSet indexKeys = dbData.getIndexInfo(null, aTable.getSchema(), aTable.getName(), false, false);
- Pattern pattern = Pattern.compile("SQL\\d+");
+ ResultSet indexKeys = null;
+ try {
+ indexKeys = dbData.getIndexInfo(null, aTable.getSchema(), aTable.getName(), false, false);
- Map<String, Map<Integer, AppliesToClause>> indexMap = new HashMap<String, Map<Integer, AppliesToClause>>();
+ Map<String, Map<Integer, AppliesToClause>> indexMap = new HashMap<String, Map<Integer, AppliesToClause>>();
- while (indexKeys.next()) {
- String indexName = indexKeys.getString("INDEX_NAME");
+ while (indexKeys.next()) {
+ String indexName = indexKeys.getString("INDEX_NAME");
- if (indexName != null && indexName.length() > 0) {
- Matcher matcher = pattern.matcher(indexName);
- if (!matcher.matches()) {
- if (indexKeys.getShort("TYPE") == DatabaseMetaData.tableIndexOther) {
+ if (indexName != null && indexName.length() > 0) {
+ Matcher matcher = indexMatcher.reset(indexName);
+ if (!matcher.matches()) {
+ if (indexKeys.getShort("TYPE") == DatabaseMetaData.tableIndexOther) {
- short ordinal = indexKeys.getShort("ORDINAL_POSITION");
- String columnName = indexKeys.getString("COLUMN_NAME");
+ short ordinal = indexKeys.getShort("ORDINAL_POSITION");
+ String columnName = indexKeys.getString("COLUMN_NAME");
- String orderTypeString = indexKeys.getString("ASC_OR_DESC");
- OrderType orderType = OrderType.Undefined;
- if (orderTypeString != null) {
- if (orderTypeString.equalsIgnoreCase("A")) {
- orderType = OrderType.Ascending;
- } else if (orderTypeString.equalsIgnoreCase("D")) {
- orderType = OrderType.Descending;
+ String orderTypeString = indexKeys.getString("ASC_OR_DESC");
+ OrderType orderType = OrderType.Undefined;
+ if (orderTypeString != null) {
+ if (orderTypeString.equalsIgnoreCase("A")) {
+ orderType = OrderType.Ascending;
+ } else if (orderTypeString.equalsIgnoreCase("D")) {
+ orderType = OrderType.Descending;
+ }
}
- }
- Map<Integer, AppliesToClause> appliesTo = null;
- if (indexMap.containsKey(indexName)) {
- appliesTo = indexMap.get(indexName);
- } else {
- appliesTo = new HashMap<Integer, AppliesToClause>();
- indexMap.put(indexName, appliesTo);
+ Map<Integer, AppliesToClause> appliesTo = null;
+ if (indexMap.containsKey(indexName)) {
+ appliesTo = indexMap.get(indexName);
+ } else {
+ appliesTo = new HashMap<Integer, AppliesToClause>();
+ indexMap.put(indexName, appliesTo);
+ }
+ appliesTo.put(new Integer(ordinal), new AppliesToClause(columnName, orderType));
}
- appliesTo.put(new Integer(ordinal), new AppliesToClause(columnName, orderType));
}
}
}
- }
- for (String indexName : indexMap.keySet()) {
- Map<Integer, AppliesToClause> clauseMap = indexMap.get(indexName);
- IndexElement element = new IndexElement(indexName);
-
- Set<Integer> index = clauseMap.keySet();
- Set<Integer> sortedIndex = new TreeSet<Integer>();
- for (Integer val : index) {
- sortedIndex.add(val);
- }
+ for (String indexName : indexMap.keySet()) {
+ Map<Integer, AppliesToClause> clauseMap = indexMap.get(indexName);
+ IndexElement element = new IndexElement(indexName);
+
+ Set<Integer> index = clauseMap.keySet();
+ Set<Integer> sortedIndex = new TreeSet<Integer>();
+ for (Integer val : index) {
+ sortedIndex.add(val);
+ }
- for (Integer val : sortedIndex) {
- AppliesToClause clause = clauseMap.get(val);
- element.addAppliesTo(clause.getColumnName(), clause.getOrderType());
+ for (Integer val : sortedIndex) {
+ AppliesToClause clause = clauseMap.get(val);
+ element.addAppliesTo(clause.getColumnName(), clause.getOrderType());
+ }
+ aTable.addIndexData(element);
+ }
+ } finally {
+ if (indexKeys != null) {
+ indexKeys.close();
}
- aTable.addIndexData(element);
}
- indexKeys.close();
}
} \ No newline at end of file

Back to the top