All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.gjc.spi.jdbc40.DatabaseMetaDataWrapper40 Maven / Gradle / Ivy

There is a newer version: 7.2024.1.Alpha1
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */
// Portions Copyright [2017-2021] [Payara Foundation and/or its affiliates]

package com.sun.gjc.spi.jdbc40;

import com.sun.gjc.common.DataSourceObjectBuilder;
import com.sun.gjc.spi.base.DatabaseMetaDataWrapper;

import java.sql.*;
import java.util.logging.Level;
import jakarta.resource.ResourceException;

/**
 * Wrapper class for DatabaseMetaData for JDBC 4.0 
*/ public class DatabaseMetaDataWrapper40 extends DatabaseMetaDataWrapper { /** * Creates a new instance of DatabaseMetaDataWrapper40 for JDBC 4.0 * * @param con Connection that is wrapped * @param metaData DatabaseMetaData that is wrapped */ public DatabaseMetaDataWrapper40(Connection con, DatabaseMetaData metaData) { super(con, metaData); } /** * Indicates whether or not this data source supports the SQL ROWID type, * and if so the lifetime for which a RowId object remains valid. *

* The returned int values have the following relationship: *

     *     ROWID_UNSUPPORTED <<y; ROWID_VALID_OTHER < ROWID_VALID_TRANSACTION
     *         < ROWID_VALID_SESSION < ROWID_VALID_FOREVER
     * 
* so conditional logic such as *
     *     if (metadata.getRowIdLifetime() > DatabaseMetaData.ROWID_VALID_TRANSACTION)
     * 
* can be used. Valid Forever means valid across all Sessions, and valid for * a Session means valid across all its contained Transactions. *

* @return the status indicating the lifetime of a RowId * @throws SQLException if a database access error occurs * @since 1.6 */ @Override public RowIdLifetime getRowIdLifetime() throws SQLException { return databaseMetaData.getRowIdLifetime(); } /** * Retrieves the schema names available in this database. The results * are ordered by TABLE_CATALOG and * TABLE_SCHEM. *

The schema columns are: *

    *
  1. TABLE_SCHEM String => schema name *
  2. TABLE_CATALOG String => catalog name (may be null) *
* * @param catalog a catalog name; must match the catalog name as it is stored * in the database;"" retrieves those without a catalog; null means catalog * name should not be used to narrow down the search. * @param schemaPattern a schema name; must match the schema name as it is * stored in the database; null means * schema name should not be used to narrow down the search. * @return a ResultSet object in which each row is a * schema description * @throws SQLException if a database access error occurs * @see #getSearchStringEscape * @since 1.6 */ @Override public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { return databaseMetaData.getSchemas(catalog, schemaPattern); } /** * Retrieves whether this database supports invoking user-defined or vendor functions * using the stored procedure escape syntax. * * @return true if so; false otherwise * @throws SQLException if a database access error occurs * @since 1.6 */ @Override public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { return databaseMetaData.supportsStoredFunctionsUsingCallSyntax(); } /** * Retrieves whether a SQLException while autoCommit is true indicates * that all open ResultSets are closed, even ones that are holdable. When a SQLException occurs while * autocommit is true, it is vendor specific whether the JDBC driver responds with a commit operation, a * rollback operation, or by doing neither a commit nor a rollback. A potential result of this difference * is in whether or not holdable ResultSets are closed. * * @return true if so; false otherwise * @throws SQLException if a database access error occurs * @since 1.6 */ @Override public boolean autoCommitFailureClosesAllResultSets() throws SQLException { return databaseMetaData.autoCommitFailureClosesAllResultSets(); } /** * Retrieves a list of the client info properties * that the driver supports. The result set contains the following columns *
    *
  1. NAME String=> The name of the client info property
    *
  2. MAX_LEN int=> The maximum length of the value for the property
    *
  3. DEFAULT_VALUE String=> The default value of the property
    *
  4. DESCRIPTION String=> A description of the property. This will typically * contain information as to where this property is * stored in the database. *
* The ResultSet is sorted by the NAME column * * @throws SQLException if a database access error occurs * @return A ResultSet object; each row is a supported client info * property * @since 1.6 */ @Override public ResultSet getClientInfoProperties() throws SQLException { return databaseMetaData.getClientInfoProperties(); } /** * Retrieves a description of the system and user functions available * in the given catalog. *

* Only system and user function descriptions matching the schema and * function name criteria are returned. They are ordered by * FUNCTION_CAT, FUNCTION_SCHEM, * FUNCTION_NAME and * SPECIFIC_ NAME. *

*

Each function description has the the following columns: *

    *
  1. FUNCTION_CAT String => function catalog (may be null) *
  2. FUNCTION_SCHEM String => function schema (may be null) *
  3. FUNCTION_NAME String => function name. This is the name * used to invoke the function *
  4. REMARKS String => explanatory comment on the function *
  5. FUNCTION_TYPE short => kind of function: *
      *
    • functionResultUnknown - Cannot determine if a return value * or table will be returned *
    • functionNoTable- Does not return a table *
    • functionReturnsTable - Returns a table *
    *
  6. SPECIFIC_NAME String => the name which uniquely identifies * this function within its schema. This is a user specified, or DBMS * generated, name that may be different then the FUNCTION_NAME * for example with overload functions *
* A user may not have permission to execute any of the functions that are * returned by getFunctions * * @param catalog a catalog name; must match the catalog name as it * is stored in the database; "" retrieves those without a catalog; * null means that the catalog name should not be used to narrow * the search * @param schemaPattern a schema name pattern; must match the schema name * as it is stored in the database; "" retrieves those without a schema; * null means that the schema name should not be used to narrow * the search * @param functionNamePattern a function name pattern; must match the * function name as it is stored in the database * @return ResultSet - each row is a function description * @throws SQLException if a database access error occurs * @see #getSearchStringEscape * @since 1.6 */ @Override public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { return databaseMetaData.getFunctions(catalog, schemaPattern, functionNamePattern); } /** * Retrieves a description of the given catalog's system or user * function parameters and return type. *

Only descriptions matching the schema, function and * parameter name criteria are returned. They are ordered by * FUNCTION_CAT, FUNCTION_SCHEM, * FUNCTION_NAME and * SPECIFIC_ 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. *

*

Each row in the ResultSet * is a parameter description, column description or * return type description with the following fields: *

    *
  1. FUNCTION_CAT String => function catalog (may be null) *
  2. FUNCTION_SCHEM String => function schema (may be null) *
  3. FUNCTION_NAME String => function name. This is the name * used to invoke the function *
  4. COLUMN_NAME String => column/parameter name *
  5. COLUMN_TYPE Short => kind of column/parameter: *
      *
    • functionColumnUnknown - nobody knows *
    • functionColumnIn - IN parameter *
    • functionColumnInOut - INOUT parameter *
    • functionColumnOut - OUT parameter *
    • functionColumnReturn - function return value *
    • functionColumnResult - Indicates that the parameter or column * is a column in the ResultSet *
    *
  6. DATA_TYPE int => SQL type from java.sql.Types *
  7. TYPE_NAME String => SQL type name, for a UDT type the * type name is fully qualified *
  8. PRECISION int => precision *
  9. LENGTH int => length in bytes of data *
  10. SCALE short => scale - null is returned for data types where * SCALE is not applicable. *
  11. RADIX short => radix *
  12. NULLABLE short => can it contain NULL. *
      *
    • functionNoNulls - does not allow NULL values *
    • functionNullable - allows NULL values *
    • functionNullableUnknown - nullability unknown *
    *
  13. REMARKS String => comment describing column/parameter *
  14. CHAR_OCTET_LENGTH int => the maximum length of binary * and character based parameters or columns. For any other datatype the returned value * is a NULL *
  15. ORDINAL_POSITION int => the ordinal position, starting * from 1, for the input and output parameters. A value of 0 * is returned if this row describes the function's return value. * For result set columns, it is the * ordinal position of the column in the result set starting from 1. *
  16. IS_NULLABLE String => ISO rules are used to determine * the nullability for a parameter or column. *
      *
    • YES --- if the parameter or column can include NULLs *
    • NO --- if the parameter or column cannot include NULLs *
    • empty string --- if the nullability for the * parameter or column is unknown *
    *
  17. SPECIFIC_NAME String => the name which uniquely identifies * this function within its schema. This is a user specified, or DBMS * generated, name that may be different then the FUNCTION_NAME * for example with overload functions *
*

The PRECISION column represents the specified column size for the given * parameter or column. * For numeric data, this is the maximum precision. For character data, this is the length in characters. * For datetime datatypes, this is the length in characters of the String representation (assuming the * maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype, * this is the length in bytes. Null is returned for data types where the * column size is not applicable. *

* @param catalog a catalog name; must match the catalog name as it * is stored in the database; "" retrieves those without a catalog; * null means that the catalog name should not be used to narrow * the search * @param schemaPattern a schema name pattern; must match the schema name * as it is stored in the database; "" retrieves those without a schema; * null means that the schema name should not be used to narrow * the search * @param functionNamePattern a procedure name pattern; must match the * function name as it is stored in the database * @param columnNamePattern a parameter name pattern; must match the * parameter or column name as it is stored in the database * @return ResultSet - each row describes a * user function parameter, column or return type * @throws SQLException if a database access error occurs * @see #getSearchStringEscape * @since 1.6 */ @Override public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException { return databaseMetaData.getFunctionColumns(catalog, schemaPattern, functionNamePattern, columnNamePattern); } /** * Returns an object that implements the given interface to allow access to * non-standard methods, or standard methods not exposed by the proxy. *

* If the receiver implements the interface then the result is the receiver * or a proxy for the receiver. If the receiver is a wrapper * and the wrapped object implements the interface then the result is the * wrapped object or a proxy for the wrapped object. Otherwise return the * the result of calling unwrap recursively on the wrapped object * or a proxy for that result. If the receiver is not a * wrapper and does not implement the interface, then an SQLException is thrown. *

* @param iface A Class defining an interface that the result must implement. * @return an object that implements the interface. May be a proxy for the actual implementing object. * @throws java.sql.SQLException If no object found that implements the interface * @since 1.6 */ @Override public T unwrap(Class iface) throws SQLException { T result; if (iface.isInstance(this)) { result = iface.cast(this); } else { result = databaseMetaData.unwrap(iface); } return result; } /** * Returns true if this either implements the interface argument or is directly or indirectly a wrapper * for an object that does. Returns false otherwise. If this implements the interface then return true, * else if this is a wrapper then return the result of recursively calling isWrapperFor on the wrapped * object. If this does not implement the interface and is not a wrapper, return false. * This method should be implemented as a low-cost operation compared to unwrap so that * callers can use this method to avoid expensive unwrap calls that may fail. If this method * returns true then calling unwrap with the same argument should succeed. * * @param iface a Class defining an interface. * @return true if this implements the interface or directly or indirectly wraps an object that does. * @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper * for an object with the given interface. * @since 1.6 */ @Override public boolean isWrapperFor(Class iface) throws SQLException { boolean result; if (iface.isInstance(this)) { result = true; } else { result = databaseMetaData.isWrapperFor(iface); } return result; } @Override public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { if (DataSourceObjectBuilder.isJDBC41()) { Class[] valueTypes = new Class[]{String.class, String.class, String.class, String.class}; try { return (ResultSet) getMethodExecutor().invokeMethod(databaseMetaData, "getPseudoColumns", valueTypes, catalog, schemaPattern, tableNamePattern, columnNamePattern); } catch (ResourceException ex) { _logger.log(Level.SEVERE, "jdbc.ex_dmd_wrapper", ex); throw new SQLException(ex); } } throw new UnsupportedOperationException("Operation not supported in this runtime."); } @Override public boolean generatedKeyAlwaysReturned() throws SQLException { if (DataSourceObjectBuilder.isJDBC41()) { try { return (Boolean) getMethodExecutor().invokeMethod(databaseMetaData, "generatedKeyAlwaysReturned", null); } catch (ResourceException ex) { _logger.log(Level.SEVERE, "jdbc.ex_dmd_wrapper", ex); throw new SQLException(ex); } } throw new UnsupportedOperationException("Operation not supported in this runtime."); } //-------------------------------- JDBC 4.2 -------------------------------- /** * * Retrieves the maximum number of bytes this database allows for * the logical size for a {@code LOB}. * * @return the maximum number of bytes allowed; a result of zero * means that there is no limit or the limit is not known * @exception SQLException if a database access error occurs */ @Override public long getMaxLogicalLobSize() throws SQLException { return databaseMetaData.getMaxLogicalLobSize(); } /** * Retrieves whether this database supports REF CURSOR. * * @return {@code true} if this database supports REF CURSOR; * {@code false} otherwise * @exception SQLException if a database access error occurs */ @Override public boolean supportsRefCursors() throws SQLException{ return databaseMetaData.supportsRefCursors(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy