📄 databasemetadata.java
字号:
String schema, String table) throws SqlException { checkForClosedConnection(); // validate input table, which can not be null if (table == null) { throw new SqlException(agent_.logWriter_, "getBestRowIdentifier(): null not allowed for table name"); } PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSPECIALCOLUMNS(?,?,?,?,?,?,?)"); cs.setIntX(1, SQL_ROWVER); cs.setStringX(2, catalog); cs.setStringX(3, schema); cs.setStringX(4, table); cs.setIntX(5, 0); cs.setShortX(6, (short) 0); cs.setStringX(7, getOptions()); lastGetSpecialColumnsResultSet_ = executeCatalogQuery(cs); return lastGetSpecialColumnsResultSet_; } // call stored procedure SQLPrimaryKeys // SYSIBM.SQLPrimaryKeys( // CatalogName varchar(128), // SchemaName varchar(128), // TableName varchar(128), // Options varchar(4000)) // public java.sql.ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SqlException { synchronized (connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getPrimaryKeys", catalog, schema, table); } return getPrimaryKeysX(catalog, schema, table); } } private ResultSet getPrimaryKeysX(String catalog, String schema, String table) throws SqlException { checkForClosedConnection(); ; // validate the input table name if (table == null) { throw new SqlException(agent_.logWriter_, "getIndexInfo(): null not allowed for table name"); } PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLPRIMARYKEYS(?,?,?,?)"); cs.setStringX(1, catalog); cs.setStringX(2, schema); cs.setStringX(3, table); cs.setStringX(4, getOptions()); lastGetPrimaryKeysResultSet_ = executeCatalogQuery(cs); return lastGetPrimaryKeysResultSet_; } // call storlastGetPrimaryKeysResultSet_ed procedure SQLForeignKeys // SYSIBM.SQLForeignKeys( // PKCatalogName varchar(128), // PKSchemaName varchar(128), // PKTableName varchar(128), // FKCatalogName varchar(128), // FKSchemaName varchar(128), // FKTableName varchar(128), // Options varchar(4000)) // public java.sql.ResultSet getImportedKeys(String catalog, String schema, String table) throws SqlException { synchronized (connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getImportedKeys", catalog, schema, table); } return getImportedKeysX(catalog, schema, table); } } private ResultSet getImportedKeysX(String catalog, String schema, String table) throws SqlException { checkForClosedConnection(); PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLFOREIGNKEYS(?,?,?,?,?,?,?)"); cs.setStringX(1, ""); cs.setStringX(2, null); cs.setStringX(3, ""); cs.setStringX(4, catalog); cs.setStringX(5, schema); cs.setStringX(6, table); // We're passing the keyword EXPORTEDKEY, but this support may not be in the GA version of SPs. // As a workaround in getCrossReference(), we'll just "select * where 0=1" when primaryTable=="" if (connection_.holdability() == ClientDataSource.HOLD_CURSORS_OVER_COMMIT) { cs.setStringX(7, "DATATYPE='JDBC';IMPORTEDKEY=1; CURSORHOLD=1"); } else { cs.setStringX(7, "DATATYPE='JDBC';IMPORTEDKEY=1; CURSORHOLD=0"); } lastGetForeignKeysResultSet_ = executeCatalogQuery(cs); return lastGetForeignKeysResultSet_; } // call stored procedure SQLForeignKeys // SYSIBM.SQLForeignKeys( // PKCatalogName varchar(128), // PKSchemaName varchar(128), // PKTableName varchar(128), // FKCatalogName varchar(128), // FKSchemaName varchar(128), // FKTableName varchar(128), // Options varchar(4000)) // public java.sql.ResultSet getExportedKeys(String catalog, String schema, String table) throws SqlException { synchronized (connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getExportedKeys", catalog, schema, table); } return getExportedKeysX(catalog, schema, table); } } private ResultSet getExportedKeysX(String catalog, String schema, String table) throws SqlException { checkForClosedConnection(); ; PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLFOREIGNKEYS(?,?,?,?,?,?,?)"); cs.setStringX(1, catalog); cs.setStringX(2, schema); cs.setStringX(3, table); cs.setStringX(4, ""); cs.setStringX(5, null); cs.setStringX(6, ""); // We're passing the keyword EXPORTEDKEY, but this support may not be in the GA version of SPs. // As a workaround in getCrossReference(), we'll just "select * where 0=1" when foreignTable=="" if (connection_.holdability() == ClientDataSource.HOLD_CURSORS_OVER_COMMIT) { cs.setStringX(7, "DATATYPE='JDBC';EXPORTEDKEY=1; CURSORHOLD=1"); } else { cs.setStringX(7, "DATATYPE='JDBC';EXPORTEDKEY=1; CURSORHOLD=0"); } lastGetForeignKeysResultSet_ = executeCatalogQuery(cs); return lastGetForeignKeysResultSet_; } // call stored procedure SQLForeignKeys // SYSIBM.SQLForeignKeys( // PKCatalogName varchar(128), // PKSchemaName varchar(128), // PKTableName varchar(128), // FKCatalogName varchar(128), // FKSchemaName varchar(128), // FKTableName varchar(128), // Options varchar(4000)) // public java.sql.ResultSet getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SqlException { synchronized (connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getCrossReference", primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema, foreignTable); } return getCrossReferenceX(primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema, foreignTable); } } private ResultSet getCrossReferenceX(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SqlException { checkForClosedConnection(); ; // check input params, primaryTable and foreignTable cannot be null if (primaryTable == null) { throw new SqlException(agent_.logWriter_, "getCrossReference(): null not allowed for primary table name"); } if (foreignTable == null) { throw new SqlException(agent_.logWriter_, "getCrossReference(): null not allowed for foreign table name"); } PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLFOREIGNKEYS(?,?,?,?,?,?,?)"); cs.setStringX(1, primaryCatalog); cs.setStringX(2, primarySchema); cs.setStringX(3, primaryTable); cs.setStringX(4, foreignCatalog); cs.setStringX(5, foreignSchema); cs.setStringX(6, foreignTable); cs.setStringX(7, getOptions()); lastGetForeignKeysResultSet_ = executeCatalogQuery(cs); return lastGetForeignKeysResultSet_; } // call stored procedure SQLGetTypeInfo // SYSIBM.SQLGetTypeInfo (IN DATATYPE SMALLINT, // IN Options VARCHAR(4000)) // // public java.sql.ResultSet getTypeInfo() throws SqlException { synchronized (connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getTypeInfo"); } return getTypeInfoX(); } } private ResultSet getTypeInfoX() throws SqlException { checkForClosedConnection(); ; // check if the last call's resultset is closed or not. PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLGETTYPEINFO(?,?)"); cs.setShortX(1, (short) 0); cs.setStringX(2, getOptions()); lastGetTypeInfoResultSet_ = executeCatalogQuery(cs); return lastGetTypeInfoResultSet_; } // call stored procedure SQLStatistics // SYSIBM.SQLStatistics( // CatalogName varchar(128), // SchemaName varchar(128), // TableName varchar(128), // Unique Smallint, // Reserved Smallint, // Options varchar(4000)) // public java.sql.ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SqlException { synchronized (connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getIndexInfo", catalog, schema, table, unique, approximate); } return getIndexInfoX(catalog, schema, table, unique, approximate); } } private ResultSet getIndexInfoX(String catalog, String schema, String table, boolean unique, boolean approximate) throws SqlException { checkForClosedConnection(); // validate the input table name if (table == null) { throw new SqlException(agent_.logWriter_, "getIndexInfo(): null not allowed for table name"); } PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSTATISTICS(?,?,?,?,?,?)"); cs.setStringX(1, catalog); cs.setStringX(2, schema); cs.setStringX(3, table); if (unique) { cs.setShortX(4, SQL_INDEX_UNIQUE); } else { cs.setShortX(4, SQL_INDEX_ALL); } if (approximate) { cs.setShortX(5, (short) 1); } else { cs.setShortX(5, (short) 0); } cs.setStringX(6, getOptions()); lastGetStatisticsResultSet_ = executeCatalogQuery(cs); return lastGetStatisticsResultSet_; } //--------------------------JDBC 2.0----------------------------- public java.sql.ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SqlException { synchronized (connection_) { if (agent_.loggingEnabled()) { agent_.logWriter_.traceEntry(this, "getUDTs", catalog, schemaPattern, typeNamePattern, types); } return getUDTsX(catalog, schemaPattern, typeNamePattern, types); } } private ResultSet getUDTsX(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SqlException { checkForClosedConnection(); ; PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLUDTS(?,?,?,?,?)"); cs.setStringX(1, catalog); cs.setStringX(2, schemaPattern); cs.setStringX(3, typeNamePattern); int i = 0; String udtTypes = new String(); while (types != null && i < types.length) { if (i > 0) { udtTypes = udtTypes.concat(","); } udtTypes = udtTypes.concat(String.valueOf(types[i])); i++; } cs.setStringX(4, udtTypes); cs.setStringX(5, getOptions()); lastGetUDTsResultSet_ = executeCatalogQuery(cs); return lastGetUDTsResultSet_; } // helper method for the catalog queries only private String getOptions() { int cursorHold; if (connection_.holdability() == ClientDataSource.HOLD_CURSORS_OVER_COMMIT) { cursorHold = 1; } else { cursorHold = 0; } return "DATATYPE='JDBC';DYNAMIC=0;REPORTPUBLICPRIVILEGES=1;CURSORHOLD=" + cursorHold; } // Derby uses a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -