/* Copyright (C) 2002-2007 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. There are special exceptions to the terms and conditions of the GPL as it is applied to this software. View the full text of the exception in file EXCEPTIONS-CONNECTOR-J in the directory of this software distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.mysql.jdbc; import java.sql.ResultSet; import java.sql.RowIdLifetime; import java.sql.SQLException; import java.sql.Types; import java.util.ArrayList; import java.util.List; import com.mysql.jdbc.Field; public class JDBC4DatabaseMetaData extends DatabaseMetaData { public JDBC4DatabaseMetaData(ConnectionImpl connToSet, String databaseToSet) { super(connToSet, databaseToSet); } public RowIdLifetime getRowIdLifetime() throws SQLException { return RowIdLifetime.ROWID_UNSUPPORTED; } /** * 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 interfaces 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 */ public boolean isWrapperFor(Class iface) throws SQLException { // This works for classes that aren't actually wrapping // anything return iface.isInstance(this); } /** * Returns an object that implements the given interface to allow access to non-standard methods, * or standard methods not exposed by the proxy. * The result may be either the object found to implement the interface or a proxy for that object. * If the receiver implements the interface then that is the object. If the receiver is a wrapper * and the wrapped object implements the interface then that is the object. Otherwise the object is * the result of calling unwrap recursively on the wrapped object. 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 */ public T unwrap(java.lang.Class iface) throws java.sql.SQLException { try { // This works for classes that aren't actually wrapping // anything return iface.cast(this); } catch (ClassCastException cce) { throw SQLError.createSQLException("Unable to unwrap to " + iface.toString(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } /** * 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 *

* @return A ResultSet object; each row is a supported client info * property *

* @exception SQLException if a database access error occurs *

* @since 1.6 */ public ResultSet getClientInfoProperties() throws SQLException { // We don't have any built-ins, we actually support whatever // the client wants to provide, however we don't have a way // to express this with the interface given Field[] fields = new Field[4]; fields[0] = new Field("", "NAME", Types.VARCHAR, 255); fields[1] = new Field("", "MAX_LEN", Types.INTEGER, 10); fields[2] = new Field("", "DEFAULT_VALUE", Types.VARCHAR, 255); fields[3] = new Field("", "DESCRIPTION", Types.VARCHAR, 255); ArrayList tuples = new ArrayList(); return buildResultSet(fields, tuples, this.conn); } public boolean autoCommitFailureClosesAllResultSets() throws SQLException { return false; } /** * 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 * @exception SQLException if a database access error occurs * @see #getSearchStringEscape * @since 1.6 */ public java.sql.ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { Field[] fields = new Field[6]; fields[0] = new Field("", "FUNCTION_CAT", Types.CHAR, 255); fields[1] = new Field("", "FUNCTION_SCHEM", Types.CHAR, 255); fields[2] = new Field("", "FUNCTION_NAME", Types.CHAR, 255); fields[3] = new Field("", "REMARKS", Types.CHAR, 255); fields[4] = new Field("", "FUNCTION_TYPE", Types.SMALLINT, 6); fields[5] = new Field("", "SPECIFIC_NAME", Types.CHAR, 255); return getProceduresAndOrFunctions( fields, catalog, schemaPattern, functionNamePattern, false, true); } protected int getJDBC4FunctionNoTableConstant() { return functionNoTable; } }