JDBC Driver - DatabaseMetaData - Basic

The object DatabaseMetadata of the Polypheny JDBC driver provides methods to query properties of the DBMS, properties of namespaces as well as the supported functions of the driver and Polypheny.

This section documents the basic metadata functions.

supportsResultSetHoldability

public boolean supportsResultSetHoldability( int resultSetHoldability )
            throws SQLException

This method evaluates whether a specific result set holdability is supported by Polypheny. The holdability of a result set determines its behavior when a transaction gets committed.

For now, the sole holdability mode supported is ResultSet.CLOSE_CURSORS_AT_COMMIT.

Parameters:

Parameter Type Description
resultSetHoldability int The holdability mode to be inspected. Expected to be a ResultSet holdability constant, e.g., ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT.

Returns:

Return Type Description
boolean If the provided holdability mode is supported by the DBMS, it returns true. Given the constraints of the current system, it will yield true only for the ResultSet.CLOSE_CURSORS_AT_COMMIT constant. Any other holdability mode will result in false.

Throws:

  • SQLException: In cases where a database access error materializes during the support check.

getResultSetHoldability

The getResultSetHoldability() method retrieves the default result set holdability for ResultSet objects generated from this Statement object. Holdability defines the behavior of cursors when transactions are committed. In the context of this method, the default behavior is to close cursors when a transaction commits.

public int getResultSetHoldability() throws SQLException

Returns:

Return Type Description Default Value
int The holdability of ResultSet objects. ResultSet.CLOSE_CURSORS_AT_COMMIT

Throws:

  • SQLException: Thrown if a database access error occurs or the method is called on a closed connection.

getDatabaseMajorVersion and getDatabaseMinorVersion

The database version is commonly represented as a combination of major and minor version numbers. The getDatabaseMajorVersion() and getDatabaseMinorVersion() methods provide access to these numbers, respectively.

public int getDatabaseMajorVersion() throws SQLException

Fetches the major version number of the underlying database.

Returns:

Return Type Description
int The major version number of the database.

Throws:

  • SQLException: Thrown if a database access error occurs or the method is called on a closed connection.
public int getDatabaseMinorVersion() throws SQLException

Fetches the minor version number of the underlying database.

Returns:

Return Type Description
int The minor version number of the database.

Throws:

  • SQLException: Thrown if a database access error occurs or the method is called on a closed connection.

getJDBCMajorVersion and getJDBCMinorVersion

JDBC versions are typically denoted by a major and minor version number. The getJDBCMajorVersion() and getJDBCMinorVersion() methods provide access to these version numbers, respectively.

public int getJDBCMajorVersion() throws SQLException

Retrieves the major version number of the JDBC driver.

Returns:

Return Type Description
int The major version number of the JDBC driver.

Throws:

  • SQLException: Thrown if a database access error occurs or the method is called on a closed connection.
public int getJDBCMinorVersion() throws SQLException

Retrieves the minor version number of the JDBC driver.

Returns:

Return Type Description
int The minor version number of the JDBC driver.

Throws:

  • SQLException: Thrown if a database access error occurs or the method is called on a closed connection.

Usage Example:

DatabaseMetaData dbmd = connection.getMetaData();

int jdbcMajorVersion = dbmd.getJDBCMajorVersion();
int jdbcMinorVersion = dbmd.getJDBCMinorVersion();

System.out.println( "Using JDBC driver version: " + jdbcMajorVersion + "." + jdbcMinorVersion );

unwrap

The unwrap method attempts to retrieve an instance of the desired interface that might be a wrapper around the invoked object. If the current object is an instance of the specified class, it returns the object cast to that type.

@Override
public <T> T unwrap( Class<T> aClass ) throws SQLException

Parameters:

Parameter Type Description
aClass Class<T> The type of the class that the current instance is to be unwrapped as.

Returns:

Return Type Description
T The current instance unwrapped as the specified class if possible.

Throws:

  • SQLException: Thrown when the current object isn’t a wrapper for the specified class.

Usage Example:

try {
    DatabaseMetaData dbmd = connection.getMetaData();
    PolyphenyDatabaseMetadata polyphenyDbmd = dbmd.unwrap( PolyphenyDatabaseMetadata.class );
} catch ( SQLException e ) {
    System.out.println( e.getMessage() );
}

isWrapperFor

The isWrapperFor method checks if the current object is a wrapper for the specified class. It can be used to determine if calling unwrap with the specified class would succeed.

@Override
public boolean isWrapperFor( Class<?> aClass )

Parameters:

Parameter Type Description
aClass Class<?> The type of the class to check against the current instance.

Returns:

Return Type Description
boolean true if the current object is a wrapper for the specified class, false otherwise.

Usage Example:

DatabaseMetaData dbmd = connection.getMetaData();
if ( dbmd.isWrapperFor( PolyphenyDatabaseMetadata.class ) ) {
    PolyphenyDatabaseMetadata instance = myObject.unwrap( PolyphenyDatabaseMetadata.class );
} else {
    System.out.println( "Not a wrapper for PolyphenyDatabaseMetadata." );
}
© Polypheny GmbH. All Rights Reserved.