Class DBMDWrapper
- All Implemented Interfaces:
OptionalTool
OptionalTool to create wrapper functions which allow you to invoke DatabaseMetaData methods via SQL. The wrapper functions slightly change the signature of the metadata methods as follows:
- Arguments of type int[] and String[] have been eliminated--they are automatically wildcarded.
- The method getRowIdLifetime() has been commented out--Derby does not support object types.
- The method getSchemas() has been commented out--it can be uncommented when the registration logic is made smarter to handle the dropping of different overloads.
- The method supportsConvert() has been commented out because Derby only allows one function by a given name and the supportsConvert( int, int ) overload is more general.
Methods which return ResultSet are mapped to table functions. You can join the metadata table functions like this:
-- list all of the columns in the connected Derby database
select t.table_schem, t.table_name, c.column_name, c.type_name
from table( getTables( null, null, null ) ) t,
table( getColumns( null, null, null, null ) ) c
where c.table_schem = t.table_schem
and c.table_name = t.table_name
and t.table_type = 'TABLE'
;
-- now list metadata in a foreign database
call setDatabaseURL( 'com.mysql.jdbc.Driver', 'jdbc:mysql://localhost/world?user=root&password=' );
select t.table_schem, t.table_name, c.column_name, c.type_name
from table( getTables( 'WORLD', null, null ) ) t,
table( getColumns( 'WORLD', null, null, null) ) c
where c.table_name = t.table_name
and t.table_type = 'TABLE'
;
-- release the foreign connection
call setDatabaseURL( '', '' );
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int//////////////////////////////////////////////////////////////////////////////// -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean////////////////////////////////////////////////////////////////////////////////static booleanprivate voidappendArgs(StringBuffer buffer, Method method) Append function arguments to an evolving ddl text buffer.private voidappendReturnType(StringBuffer buffer, Connection conn, Method method) Append return type to an evolving ddl text bufferprivate voidappendTableFunctionSignature(StringBuffer buffer, Connection conn, Method method) Append the signature of a table function to an evolving ddl text bufferstatic booleanstatic booleanstatic booleanstatic booleandeletesAreDetected(int type) static booleanprivate static voidexecuteDDL(Connection conn, String text) Execute a DDL statement.static ResultSetgetAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) static ResultSetgetBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) static ResultSetstatic Stringstatic Stringstatic ResultSetstatic ResultSetgetColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) static ResultSetgetColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) static ResultSetgetCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) static intstatic intstatic Stringstatic Stringprivate static DatabaseMetaDatagetDBMD()Get the current session's database metadata.private static ConnectionGet the default connection, called from inside the database engine.static intstatic intstatic intstatic Stringstatic Stringprivate ObjectgetDummyValue(Class type) Get a dummy value for an argument to a DBMD method.static ResultSetgetExportedKeys(String catalog, String schema, String table) static Stringstatic ResultSetgetFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) static ResultSetgetFunctions(String catalog, String schemaPattern, String functionNamePattern) static Stringstatic ResultSetgetImportedKeys(String catalog, String schema, String table) static ResultSetgetIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) static intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic intstatic Stringstatic ResultSetgetPrimaryKeys(String catalog, String schema, String table) static ResultSetgetProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) static ResultSetgetProcedures(String catalog, String schemaPattern, String procedureNamePattern) static Stringstatic intstatic ResultSetgetSchemas(String catalog, String schemaPattern) static Stringstatic Stringstatic Stringstatic intstatic Stringstatic ResultSetgetSuperTables(String catalog, String schemaPattern, String tableNamePattern) static ResultSetgetSuperTypes(String catalog, String schemaPattern, String typeNamePattern) static Stringstatic ResultSetgetTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) static ResultSetstatic ResultSetstatic Stringstatic ResultSetstatic ResultSetstatic StringgetURL()static Stringstatic ResultSetgetVersionColumns(String catalog, String schema, String table) static booleaninsertsAreDetected(int type) static booleanstatic booleanprivate booleanisSet(int allModifiers, int requestedModifier) Return true if the requested modifer is setprivate booleanisTableFunction(Method method) Return true if the method describes a table function.void////////////////////////////////////////////////////////////////////////////////static booleanprivate StringmapJavaToSQLType(Class javaType) Get the SQL type which corresponds to a Java type.static booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanothersDeletesAreVisible(int type) static booleanothersInsertsAreVisible(int type) static booleanothersUpdatesAreVisible(int type) static booleanownDeletesAreVisible(int type) static booleanownInsertsAreVisible(int type) static booleanownUpdatesAreVisible(int type) private static PreparedStatementprepareStatement(Connection conn, String text) Prepare a statement and print out the text.private voidregister(boolean register) Workhorse to register or unregister all public static methods as Derby routines.private voidregisterFunction(Connection conn, Method method) Register the method as a Derby function.static booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanprivate voidstringifyJDBCType(StringBuffer buffer, ResultSetMetaData rsmd, int columnNumber) Append the name of a SQL type to an evolving ddl text bufferstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleansupportsConvert(int fromType, int toType) static booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleansupportsResultSetConcurrency(int type, int concurrency) static booleansupportsResultSetHoldability(int holdability) static booleansupportsResultSetType(int type) static booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleanstatic booleansupportsTransactionIsolationLevel(int level) static booleanstatic booleanstatic booleanvoidunloadTool(String... configurationParameters) Unload the tool, giving it optional configuration parametersprivate voidunregisterFunction(Connection conn, Method method) Drop the function with this method name.static booleanupdatesAreDetected(int type) static booleanstatic booleanprivate static SQLExceptionWrap an exception in a SQLException.
-
Field Details
-
DEFAULT_PRECISION
private static final int DEFAULT_PRECISION////////////////////////////////////////////////////////////////////////////////- See Also:
-
-
Constructor Details
-
DBMDWrapper
public DBMDWrapper()0-arg constructor to satisfy the OptionalTool contract
-
-
Method Details
-
loadTool
////////////////////////////////////////////////////////////////////////////////- Specified by:
loadToolin interfaceOptionalTool- Throws:
SQLException
-
unloadTool
Description copied from interface:OptionalToolUnload the tool, giving it optional configuration parameters- Specified by:
unloadToolin interfaceOptionalTool- Throws:
SQLException
-
register
Workhorse to register or unregister all public static methods as Derby routines.
- Throws:
SQLException
-
allProceduresAreCallable
////////////////////////////////////////////////////////////////////////////////- Throws:
SQLException
-
allTablesAreSelectable
- Throws:
SQLException
-
autoCommitFailureClosesAllResultSets
- Throws:
SQLException
-
dataDefinitionCausesTransactionCommit
- Throws:
SQLException
-
dataDefinitionIgnoredInTransactions
- Throws:
SQLException
-
deletesAreDetected
- Throws:
SQLException
-
doesMaxRowSizeIncludeBlobs
- Throws:
SQLException
-
getAttributes
public static ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException - Throws:
SQLException
-
getBestRowIdentifier
public static ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException - Throws:
SQLException
-
getCatalogs
- Throws:
SQLException
-
getCatalogSeparator
- Throws:
SQLException
-
getCatalogTerm
- Throws:
SQLException
-
getClientInfoProperties
- Throws:
SQLException
-
getColumnPrivileges
public static ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException - Throws:
SQLException
-
getColumns
public static ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException - Throws:
SQLException
-
getCrossReference
public static ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException - Throws:
SQLException
-
getDatabaseMajorVersion
- Throws:
SQLException
-
getDatabaseMinorVersion
- Throws:
SQLException
-
getDatabaseProductName
- Throws:
SQLException
-
getDatabaseProductVersion
- Throws:
SQLException
-
getDefaultTransactionIsolation
- Throws:
SQLException
-
getDriverMajorVersion
- Throws:
SQLException
-
getDriverMinorVersion
- Throws:
SQLException
-
getDriverName
- Throws:
SQLException
-
getDriverVersion
- Throws:
SQLException
-
getExportedKeys
public static ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException - Throws:
SQLException
-
getExtraNameCharacters
- Throws:
SQLException
-
getFunctionColumns
public static ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException - Throws:
SQLException
-
getFunctions
public static ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException - Throws:
SQLException
-
getIdentifierQuoteString
- Throws:
SQLException
-
getImportedKeys
public static ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException - Throws:
SQLException
-
getIndexInfo
public static ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException - Throws:
SQLException
-
getJDBCMajorVersion
- Throws:
SQLException
-
getJDBCMinorVersion
- Throws:
SQLException
-
getMaxBinaryLiteralLength
- Throws:
SQLException
-
getMaxCatalogNameLength
- Throws:
SQLException
-
getMaxCharLiteralLength
- Throws:
SQLException
-
getMaxColumnNameLength
- Throws:
SQLException
-
getMaxColumnsInGroupBy
- Throws:
SQLException
-
getMaxColumnsInIndex
- Throws:
SQLException
-
getMaxColumnsInOrderBy
- Throws:
SQLException
-
getMaxColumnsInSelect
- Throws:
SQLException
-
getMaxColumnsInTable
- Throws:
SQLException
-
getMaxConnections
- Throws:
SQLException
-
getMaxCursorNameLength
- Throws:
SQLException
-
getMaxIndexLength
- Throws:
SQLException
-
getMaxProcedureNameLength
- Throws:
SQLException
-
getMaxRowSize
- Throws:
SQLException
-
getMaxSchemaNameLength
- Throws:
SQLException
-
getMaxStatementLength
- Throws:
SQLException
-
getMaxStatements
- Throws:
SQLException
-
getMaxTableNameLength
- Throws:
SQLException
-
getMaxTablesInSelect
- Throws:
SQLException
-
getMaxUserNameLength
- Throws:
SQLException
-
getNumericFunctions
- Throws:
SQLException
-
getPrimaryKeys
public static ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException - Throws:
SQLException
-
getProcedureColumns
public static ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException - Throws:
SQLException
-
getProcedures
public static ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException - Throws:
SQLException
-
getProcedureTerm
- Throws:
SQLException
-
getResultSetHoldability
- Throws:
SQLException
-
getSchemas
- Throws:
SQLException
-
getSchemaTerm
- Throws:
SQLException
-
getSearchStringEscape
- Throws:
SQLException
-
getSQLKeywords
- Throws:
SQLException
-
getSQLStateType
- Throws:
SQLException
-
getStringFunctions
- Throws:
SQLException
-
getSuperTables
public static ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException - Throws:
SQLException
-
getSuperTypes
public static ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException - Throws:
SQLException
-
getSystemFunctions
- Throws:
SQLException
-
getTablePrivileges
public static ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException - Throws:
SQLException
-
getTables
public static ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException - Throws:
SQLException
-
getTableTypes
- Throws:
SQLException
-
getTimeDateFunctions
- Throws:
SQLException
-
getTypeInfo
- Throws:
SQLException
-
getUDTs
public static ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern) throws SQLException - Throws:
SQLException
-
getURL
- Throws:
SQLException
-
getUserName
- Throws:
SQLException
-
getVersionColumns
public static ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException - Throws:
SQLException
-
insertsAreDetected
- Throws:
SQLException
-
isCatalogAtStart
- Throws:
SQLException
-
isReadOnly
- Throws:
SQLException
-
locatorsUpdateCopy
- Throws:
SQLException
-
nullPlusNonNullIsNull
- Throws:
SQLException
-
nullsAreSortedAtEnd
- Throws:
SQLException
-
nullsAreSortedAtStart
- Throws:
SQLException
-
nullsAreSortedHigh
- Throws:
SQLException
-
nullsAreSortedLow
- Throws:
SQLException
-
othersDeletesAreVisible
- Throws:
SQLException
-
othersInsertsAreVisible
- Throws:
SQLException
-
othersUpdatesAreVisible
- Throws:
SQLException
-
ownDeletesAreVisible
- Throws:
SQLException
-
ownInsertsAreVisible
- Throws:
SQLException
-
ownUpdatesAreVisible
- Throws:
SQLException
-
storesLowerCaseIdentifiers
- Throws:
SQLException
-
storesLowerCaseQuotedIdentifiers
- Throws:
SQLException
-
storesMixedCaseIdentifiers
- Throws:
SQLException
-
storesMixedCaseQuotedIdentifiers
- Throws:
SQLException
-
storesUpperCaseIdentifiers
- Throws:
SQLException
-
storesUpperCaseQuotedIdentifiers
- Throws:
SQLException
-
supportsAlterTableWithAddColumn
- Throws:
SQLException
-
supportsAlterTableWithDropColumn
- Throws:
SQLException
-
supportsANSI92EntryLevelSQL
- Throws:
SQLException
-
supportsANSI92FullSQL
- Throws:
SQLException
-
supportsANSI92IntermediateSQL
- Throws:
SQLException
-
supportsBatchUpdates
- Throws:
SQLException
-
supportsCatalogsInDataManipulation
- Throws:
SQLException
-
supportsCatalogsInIndexDefinitions
- Throws:
SQLException
-
supportsCatalogsInPrivilegeDefinitions
- Throws:
SQLException
-
supportsCatalogsInProcedureCalls
- Throws:
SQLException
-
supportsCatalogsInTableDefinitions
- Throws:
SQLException
-
supportsColumnAliasing
- Throws:
SQLException
-
supportsConvert
- Throws:
SQLException
-
supportsCoreSQLGrammar
- Throws:
SQLException
-
supportsDataDefinitionAndDataManipulationTransactions
- Throws:
SQLException
-
supportsDataManipulationTransactionsOnly
- Throws:
SQLException
-
supportsDifferentTableCorrelationNames
- Throws:
SQLException
-
supportsExpressionsInOrderBy
- Throws:
SQLException
-
supportsExtendedSQLGrammar
- Throws:
SQLException
-
supportsFullOuterJoins
- Throws:
SQLException
-
supportsGetGeneratedKeys
- Throws:
SQLException
-
supportsGroupBy
- Throws:
SQLException
-
supportsGroupByBeyondSelect
- Throws:
SQLException
-
supportsIntegrityEnhancementFacility
- Throws:
SQLException
-
supportsLikeEscapeClause
- Throws:
SQLException
-
supportsLimitedOuterJoins
- Throws:
SQLException
-
supportsMinimumSQLGrammar
- Throws:
SQLException
-
supportsMixedCaseIdentifiers
- Throws:
SQLException
-
supportsMixedCaseQuotedIdentifiers
- Throws:
SQLException
-
supportsMultipleOpenResults
- Throws:
SQLException
-
supportsMultipleResultSets
- Throws:
SQLException
-
supportsMultipleTransactions
- Throws:
SQLException
-
supportsNamedParameters
- Throws:
SQLException
-
supportsNonNullableColumns
- Throws:
SQLException
-
supportsOpenCursorsAcrossCommit
- Throws:
SQLException
-
supportsOpenCursorsAcrossRollback
- Throws:
SQLException
-
supportsOpenStatementsAcrossCommit
- Throws:
SQLException
-
supportsOpenStatementsAcrossRollback
- Throws:
SQLException
-
supportsOuterJoins
- Throws:
SQLException
-
supportsPositionedDelete
- Throws:
SQLException
-
supportsPositionedUpdate
- Throws:
SQLException
-
supportsResultSetConcurrency
- Throws:
SQLException
-
supportsResultSetHoldability
- Throws:
SQLException
-
supportsResultSetType
- Throws:
SQLException
-
supportsSavepoints
- Throws:
SQLException
-
supportsSchemasInDataManipulation
- Throws:
SQLException
-
supportsSchemasInIndexDefinitions
- Throws:
SQLException
-
supportsSchemasInPrivilegeDefinitions
- Throws:
SQLException
-
supportsSchemasInProcedureCalls
- Throws:
SQLException
-
supportsSchemasInTableDefinitions
- Throws:
SQLException
-
supportsSelectForUpdate
- Throws:
SQLException
-
supportsStatementPooling
- Throws:
SQLException
-
supportsStoredFunctionsUsingCallSyntax
- Throws:
SQLException
-
supportsStoredProcedures
- Throws:
SQLException
-
supportsSubqueriesInComparisons
- Throws:
SQLException
-
supportsSubqueriesInExists
- Throws:
SQLException
-
supportsSubqueriesInIns
- Throws:
SQLException
-
supportsSubqueriesInQuantifieds
- Throws:
SQLException
-
supportsTableCorrelationNames
- Throws:
SQLException
-
supportsTransactionIsolationLevel
- Throws:
SQLException
-
supportsTransactions
- Throws:
SQLException
-
supportsUnion
- Throws:
SQLException
-
supportsUnionAll
- Throws:
SQLException
-
updatesAreDetected
- Throws:
SQLException
-
usesLocalFilePerTable
- Throws:
SQLException
-
usesLocalFiles
- Throws:
SQLException
-
isSet
private boolean isSet(int allModifiers, int requestedModifier) Return true if the requested modifer is set
-
unregisterFunction
Drop the function with this method name.
- Throws:
SQLException
-
registerFunction
Register the method as a Derby function.
- Throws:
SQLException
-
isTableFunction
Return true if the method describes a table function.
-
appendArgs
Append function arguments to an evolving ddl text buffer.
- Throws:
SQLException
-
appendReturnType
private void appendReturnType(StringBuffer buffer, Connection conn, Method method) throws SQLException Append return type to an evolving ddl text buffer
- Throws:
SQLException
-
appendTableFunctionSignature
private void appendTableFunctionSignature(StringBuffer buffer, Connection conn, Method method) throws SQLException Append the signature of a table function to an evolving ddl text buffer
- Throws:
SQLException
-
getDummyValue
-
stringifyJDBCType
private void stringifyJDBCType(StringBuffer buffer, ResultSetMetaData rsmd, int columnNumber) throws SQLException Append the name of a SQL type to an evolving ddl text buffer
- Throws:
SQLException
-
mapJavaToSQLType
Get the SQL type which corresponds to a Java type.
- Throws:
SQLException
-
getDBMD
Get the current session's database metadata.
- Throws:
SQLException
-
getDefaultConnection
Get the default connection, called from inside the database engine.
- Throws:
SQLException
-
executeDDL
Execute a DDL statement.
- Throws:
SQLException
-
prepareStatement
Prepare a statement and print out the text.
- Throws:
SQLException
-
wrap
Wrap an exception in a SQLException.
-