private DataStore getImportedKeyList(TableIdentifier tbl) throws SQLException { // I'm not adding an ORDER BY because the statement is terribly slow anyway // and an ORDER BY makes it even slower for large results StringBuilder sql = new StringBuilder(baseSql.length() + 50); sql.append(getQuery(tbl)); sql.append("AND f.table_name = ? \n"); sql.append("AND f.owner = ? \n"); if (Settings.getInstance().getDebugMetadataSql()) { LogMgr.logDebug( "OracleFKHandler.getImportedKeyList()", "Retrieving imported foreign keys using:\n" + SqlUtil.replaceParameters(sql, tbl.getRawTableName(), tbl.getRawSchema())); } ResultSet rs; DataStore result = null; try { retrievalStatement = this.getConnection().getSqlConnection().prepareStatement(sql.toString()); retrievalStatement.setString(1, tbl.getRawTableName()); retrievalStatement.setString(2, tbl.getRawSchema()); rs = retrievalStatement.executeQuery(); result = processResult(rs); } finally { // the result set is closed by processResult SqlUtil.closeStatement(retrievalStatement); retrievalStatement = null; } sortResult(result); return result; }
/** * Adjust the baseSql query to reflect if a table for the current user is queried. * * <p>If the table belongs to the current user, the user_XXX views can be used instead of the * all_XXX views. Using the user_XXX views is faster (at least on my system) than the all_XXX * views - although it is still an awfully slow statement... <br> * Querying user_constraints instead of all_constraints means that constraints between two schemas * will not be shown. In order to still enable this, the config property: <br> * <code>workbench.db.oracle.optimize_fk_query</code> <br> * can be set to false, if all_constraints should always be queried. * * @param tbl the table for which the query should be generated * @return the query to use * @see OracleUtils#optimizeCatalogQueries() */ private String getQuery(TableIdentifier tbl) { if (OracleUtils.optimizeCatalogQueries()) { String schema = tbl.getRawSchema(); if (StringUtil.isEmptyString(schema) || schema.equalsIgnoreCase(currentUser)) { return baseSql.replace(" all_c", " user_c"); } } return baseSql; }