📄 embeddatabasemetadata.java
字号:
/** * Are both data definition and data manipulation statements * within a transaction supported? * * @return true if so */ public boolean supportsDataDefinitionAndDataManipulationTransactions() { return true; } /** * Are only data manipulation statements within a transaction * supported? * * @return true if so */ public boolean supportsDataManipulationTransactionsOnly() { return false; } /** * Does a data definition statement within a transaction force the * transaction to commit? * * @return true if so * */ public boolean dataDefinitionCausesTransactionCommit() { return false; } /** * Is a data definition statement within a transaction ignored? * * @return true if so * */ public boolean dataDefinitionIgnoredInTransactions(){ return false; } /** * Get a description of stored procedures available in a * catalog. * * <P>Only procedure descriptions matching the schema and * procedure name criteria are returned. They are ordered by * PROCEDURE_SCHEM, and PROCEDURE_NAME. * * <P>Each procedure description has the the following columns: * <OL> * <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be null) * <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be null) * <LI><B>PROCEDURE_NAME</B> String => procedure name * <LI> reserved for future use * <LI> reserved for future use * <LI> reserved for future use * <LI><B>REMARKS</B> String => explanatory comment on the procedure * <LI><B>PROCEDURE_TYPE</B> short => kind of procedure: * <UL> * <LI> procedureResultUnknown - May return a result * <LI> procedureNoResult - Does not return a result * <LI> procedureReturnsResult - Returns a result * </UL> * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name pattern; "" retrieves those * without a schema * @param procedureNamePattern a procedure name pattern * @return ResultSet - each row is a procedure description * @see #getSearchStringEscape * @exception SQLException thrown on failure. */ public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { return doGetProcs(catalog, schemaPattern, procedureNamePattern, "getProcedures"); } /** * Get a description of stored procedures available in a * catalog. Same as getProcedures() above, except that * the result set will conform to ODBC specifications. */ public ResultSet getProceduresForODBC(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { return doGetProcs(catalog, schemaPattern, procedureNamePattern, "odbc_getProcedures"); } /** * Does the actual work for the getProcedures metadata calls. * See getProcedures() method above for parameter descriptions. * @param queryName Name of the query to execute; is used * to determine whether the result set should conform to * JDBC or ODBC specifications. */ private ResultSet doGetProcs(String catalog, String schemaPattern, String procedureNamePattern, String queryName) throws SQLException { PreparedStatement s = getPreparedQuery(queryName); s.setString(1, swapNull(catalog)); s.setString(2, swapNull(schemaPattern)); s.setString(3, swapNull(procedureNamePattern)); return s.executeQuery(); } /** * Get a description of a catalog's stored procedure parameters * and result columns. * * <P>Only descriptions matching the schema, procedure and * parameter name criteria are returned. They are ordered by * PROCEDURE_SCHEM and PROCEDURE_NAME. Within this, the return value, * if any, is first. Next are the parameter descriptions in call * order. The column descriptions follow in column number order. * * <P>Each row in the ResultSet is a parameter description or * column description with the following fields: * <OL> * <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be null) * <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be null) * <LI><B>PROCEDURE_NAME</B> String => procedure name * <LI><B>COLUMN_NAME</B> String => column/parameter name * <LI><B>COLUMN_TYPE</B> Short => kind of column/parameter: * <UL> * <LI> procedureColumnUnknown - nobody knows * <LI> procedureColumnIn - IN parameter * <LI> procedureColumnInOut - INOUT parameter * <LI> procedureColumnOut - OUT parameter * <LI> procedureColumnReturn - procedure return value * <LI> procedureColumnResult - result column in ResultSet * </UL> * <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types * <LI><B>TYPE_NAME</B> String => SQL type name * <LI><B>PRECISION</B> int => precision * <LI><B>LENGTH</B> int => length in bytes of data * <LI><B>SCALE</B> short => scale * <LI><B>RADIX</B> short => radix * <LI><B>NULLABLE</B> short => can it contain NULL? * <UL> * <LI> procedureNoNulls - does not allow NULL values * <LI> procedureNullable - allows NULL values * <LI> procedureNullableUnknown - nullability unknown * </UL> * <LI><B>REMARKS</B> String => comment describing parameter/column * </OL> * * <P><B>Note:</B> Some databases may not return the column * descriptions for a procedure. Additional columns beyond * REMARKS can be defined by the database. * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name pattern; "" retrieves those * without a schema * @param procedureNamePattern a procedure name pattern * @param columnNamePattern a column name pattern * @return ResultSet - each row is a stored procedure parameter or * column description * @see #getSearchStringEscape * @exception SQLException thrown on failure. */ public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException { return doGetProcCols(catalog, schemaPattern, procedureNamePattern, columnNamePattern, "getProcedureColumns"); } /** * Get a description of a catalog's stored procedure parameters * and result columns. Same as getProcedureColumns() above, * except that the result set will conform to ODBC specifications. */ public ResultSet getProcedureColumnsForODBC(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException { return doGetProcCols(catalog, schemaPattern, procedureNamePattern, columnNamePattern, "odbc_getProcedureColumns"); } /** * Does the actual work for the getProcedureColumns metadata * calls. See getProcedureColumns() method above for parameter * descriptions. * @param queryName Name of the query to execute; is used * to determine whether the result set should conform to * JDBC or ODBC specifications. */ private ResultSet doGetProcCols(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern, String queryName) throws SQLException { PreparedStatement s = getPreparedQuery(queryName); // // catalog is not part of the query // s.setString(1, swapNull(schemaPattern)); s.setString(2, swapNull(procedureNamePattern)); s.setString(3, swapNull(columnNamePattern)); return s.executeQuery(); } /** * Get a description of tables available in a catalog. * * <P>Only table descriptions matching the catalog, schema, table * name and type criteria are returned. They are ordered by * TABLE_TYPE, TABLE_SCHEM and TABLE_NAME. * * <P>Each table description has the following columns: * <OL> * <LI><B>TABLE_CAT</B> String => table catalog (may be null) * <LI><B>TABLE_SCHEM</B> String => table schema (may be null) * <LI><B>TABLE_NAME</B> String => table name * <LI><B>TABLE_TYPE</B> String => table type. Typical types are "TABLE", * "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", * "LOCAL TEMPORARY", "ALIAS", "SYNONYM". * <LI><B>REMARKS</B> String => explanatory comment on the table * </OL> * * <P><B>Note:</B> Some databases may not return information for * all tables. * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name pattern; "" retrieves those * without a schema * @param tableNamePattern a table name pattern * @param types a list of table types to include; null returns all types * @return ResultSet - each row is a table description * @see #getSearchStringEscape * @exception SQLException thrown on failure. */ public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException { synchronized (getConnectionSynchronization()) { setupContextStack(); ResultSet rs = null; try { String queryText = getQueryDescriptions().getProperty("getTables"); /* * The query text is assumed to end with a "where" clause, so * that we can safely append * "and table_Type in ('xxx','yyy','zzz', ...)" and * have it become part of the where clause. * * Let's assume for now that the table type first char corresponds * to JBMS table type identifiers. */ StringBuffer whereClauseTail = new StringBuffer(queryText); if (types != null && types.length >= 1) { whereClauseTail.append(" AND TABLETYPE IN ('"); whereClauseTail.append(types[0].substring(0, 1)); for (int i=1; i<types.length; i++) { whereClauseTail.append("','"); whereClauseTail.append(types[i].substring(0, 1)); } whereClauseTail.append("')"); } // Add the order by clause after the 'in' list. whereClauseTail.append( " ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME"); PreparedStatement s = getEmbedConnection().prepareMetaDataStatement(whereClauseTail.toString()); s.setString(1, swapNull(catalog)); s.setString(2, swapNull(schemaPattern)); s.setString(3, swapNull(tableNamePattern)); rs = s.executeQuery(); } catch (Throwable t) { throw handleException(t); } finally { restoreContextStack(); } return rs; } } /** * Get the schema names available in this database. The results * are ordered by schema name. * * <P>The schema column is: * <OL> * <LI><B>TABLE_SCHEM</B> String => schema name * </OL> * * @return ResultSet - each row has a single String column that is a * schema name * @exception SQLException thrown on failure. */ public ResultSet getSchemas() throws SQLException { return getSimpleQuery("getSchemas"); } /** * Get the catalog names available in this database. The results * are ordered by catalog name. * * <P>The catalog column is: * <OL> * <LI><B>TABLE_CAT</B> String => catalog name * </OL> * * @return ResultSet - each row has a single String column that is a * catalog name * @exception SQLException thrown on failure. */ public ResultSet getCatalogs() throws SQLException { return getSimpleQuery("getCatalogs"); } /** * Get the table types available in this database. The results * are ordered by table type. * * <P>The table type is: * <OL> * <LI><B>TABLE_TYPE</B> String => table type. Typical types are "TABLE", * "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", * "LOCAL TEMPORARY", "ALIAS", "SYNONYM". * </OL> * * @return ResultSet - each row has a single String column that is a * table type * @exception SQLException thrown on failure. */ public ResultSet getTableTypes() throws SQLException { return getSimpleQuery("getTableTypes"); } /** * Get a description of table columns available in a catalog. * * <P>Only column descriptions matching the catalog, schema, table * and column name criteria are returned. They are ordered by * TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION. * * <P>Each column description has the following columns: * <OL> * <LI><B>TABLE_CAT</B> String => table catalog (may be null) * <LI><B>TABLE_SCHEM</B> String => table schema (may be null) * <LI><B>TABLE_NAME</B> String => table name * <LI><B>COLUMN_NAME</B> String => column name * <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types * <LI><B>TYPE_NAME</B> String => Data source dependent type name * <LI><B>COLUMN_SIZE</B> int => column size. For char or date * types this is the maximum number of characters, for numeric or * decimal types this is precision. * <LI><B>BUFFER_LENGTH</B> is not used. * <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits * <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2) * <LI><B>NULLABLE</B> int => is NULL allowed? * <UL> * <LI> columnNoNulls - might not allow NULL values * <LI> columnNullable - definitely allows NULL values * <LI> columnNullableUnknown - nullability unknown * </UL> * <LI><B>REMARKS</B> String => comment describing column (may be null) * <LI><B>COLUMN_DEF</B> String => default value (may be null) * <LI><B>SQL_DATA_TYPE</B> int => unused * <LI><B>SQL_DATETIME_SUB</B> int => unused * <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the * maximum number of bytes in the column * <LI><B>ORDINAL_POSITION</B> int => index of column in table * (starting at 1) * <LI><B>IS_NULLABLE</B> String => "NO" means column definitely * does not allow NULL values; "YES" means the column might * allow NULL values. An empty string means nobody knows. * </OL> * * @param catalog a catalog name; "" retrieves those without a * catalog; null means drop catalog name from the selection criteria * @param schemaPattern a schema name pattern; "" retrieves those * without a schema * @param tableNamePattern a table name pattern * @param columnNamePattern a column name pattern * @return ResultSet - each row is a column description * @see #getSearchStringEscape * @exception SQLException thrown on failure. */ public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { return doGetCols(catalog, schemaPattern, tableNamePattern, columnNamePattern, "getColumns"); } /** * Get a description of table columns available in a catalog. * Same as getColumns() above, except that the result set * will conform to ODBC specifications. */ public ResultSet getColumnsForODBC(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { return doGetCols(catalog, schemaPattern, tableNamePattern, columnNamePattern, "odbc_getColumns"); } /** * Does the actual work for the getColumns metadata calls. * See getColumns() method above for parameter descriptions. * @param queryName Name of the query to execute; is used * to determine whether the result set should conform to * JDBC or ODBC specifications. */ private ResultSet doGetCols(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern, String queryName) throws SQLException { PreparedStatement s = getPreparedQuery(queryName); s.setString(1, swapNull(catalog)); s.setString(2, swapNull(schemaPattern)); s.setString(3, swapNull(tableNamePattern)); s.setString(4, swapNull(columnNamePattern)); return s.executeQuery(); } /** * Get a description of the access rights for a table's columns. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -