📄 jdbcdatabasemetadata.java
字号:
/* Copyright (c) 2001-2005, The HSQL Development Group * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the HSQL Development Group nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG, * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package org.hsqldb.jdbc;import java.sql.Connection;import java.sql.DatabaseMetaData;import java.sql.ResultSet;import java.sql.SQLException;import org.hsqldb.Column;import org.hsqldb.Library;import org.hsqldb.Trace;import org.hsqldb.lib.StringUtil;import org.hsqldb.persist.HsqlDatabaseProperties;// fredt@users 20020320 - patch 1.7.0 - JDBC 2 support and error trapping// JDBC 2 methods can now be called from jdk 1.1.x - see javadoc comments// boucherb@users 20020509 - added "throws SQLException" to all methods where// it was missing here but specified in the java.sql.DatabaseMetaData interface,// updated generic documentation to JDK 1.4, and added JDBC3 methods and docs// boucherb@users and fredt@users 20020409/20020505 extensive review and update// of docs and behaviour to comply with previous and latest java.sql// specification// boucherb@users 2002-20030121 - extensive rewrite to support new// 1.7.2 metadata features.// boucherb@users 20040422 - doc 1.7.2 - javadoc updates toward 1.7.2 final// boucherb@users 200404xx - misc changes// fredt@users 20050505 - patch 1.8.0 - enforced JDBC rules for non-pattern params/** Comprehensive information about the database as a whole. * <P> * This interface is implemented by driver vendors to let users know the * capabilities of a Database Management System (DBMS) in combination with * the driver based on JDBC<sup><font size=-2>TM</font></sup> technology * ("JDBC driver") that is used with it. Different relational DBMSs often * support different features, implement features in different ways, and use * different data types. In addition, a driver may implement a feature on * top of what the DBMS offers. Information returned by methods in this * interface applies to the capabilities of a particular driver and a * particular DBMS working together. Note that as used in this documentation, * the term "database" is used generically to refer to both the driver and DBMS. * <P> * A user for this interface is commonly a tool that needs to discover how to * deal with the underlying DBMS. This is especially true for applications * that are intended to be used with more than one DBMS. For example, a tool * might use the method <code>getTypeInfo</code> to find out what data types * can be used in a <code>CREATE TABLE</code> statement. Or a user might call * the method <code>supportsCorrelatedSubqueries</code> to see if it is possible * to use a correlated subquery or <code>supportsBatchUpdates</code> to see if * it is possible to use batch updates. * <P> * Some <code>DatabaseMetaData</code> methods return lists of information * in the form of <code>ResultSet</code> objects. Regular <code>ResultSet</code> * methods, such as <code>getString</code> and <code>getInt</code>, can be used * to retrieve the data from these <code>ResultSet</code> objects. If a given * form of metadata is not available, the <code>ResultSet</code> getter methods * throw an <code>SQLException</code>. * <P> * Some <code>DatabaseMetaData</code> methods take arguments that are * String patterns. These arguments all have names such as fooPattern. * Within a pattern String, "%" means match any substring of 0 or more * characters, and "_" means match any one character. Only metadata * entries matching the search pattern are returned. If a search pattern * argument is set to <code>null</code>, that argument's criterion will * be dropped from the search. * <P> * A method that gets information about a feature that the driver does not * support will throw an <code>SQLException</code>. * In the case of methods that return a <code>ResultSet</code> * object, either a <code>ResultSet</code> object (which may be empty) is * returned or an <code>SQLException</code> is thrown.<p> * * <!-- start release-specific documentation --> * <div class="ReleaseSpecificDocumentation"> * <h3>HSQLDB-Specific Information:</h3> <p> * * Starting with HSQLDB 1.7.2, an option is provided to allow alternate * system table production implementations. In this distribution, there are * three implementations whose behaviour ranges from producing no system * tables at all to producing a richer and more complete body of information * about an HSQLDB database than was previously available. The information * provided through the default implementation is, unlike previous * versions, accessible to all database users, regardless of admin status. * This is now possible because the table content it produces for each * user is pre-filtered, based on the user's access rights. That is, each * system table now acts like a security-aware View.<p> * * The process of installing a system table production class is transparent and * occurs dynamically at runtime during the opening sequence of a * <code>Database</code> instance, in the newDatabaseInformation() factory * method of the revised DatabaseInformation class, using the following * steps: <p> * * <div class="GeneralExample"> * <ol> * <li>If a class whose fully qualified name is org.hsqldb.DatabaseInformationFull * can be found and it has an accesible constructor that takes an * org.hsqldb.Database object as its single parameter, then an instance of * that class is reflectively instantiated and is used by the database * instance to produce its system tables. <p> * * <li>If 1.) fails, then the process is repeated, attempting to create an * instance of org.hsqldb.DatabaseInformationMain (which provides just the * core set of system tables required to service this class, but now does * so in a more security aware and comprehensive fashion). <p> * * <li>If 2.) fails, then an instance of org.hsqldb.DatabaseInformation is * installed (that, by default, produces no system tables, meaning that * calls to all related methods in this class will fail, throwing an * SQLException stating that a required system table is not found). <p> * * </ol> * </div> <p> * * The process of searching for alternate implementations of database * support classes, ending with the installation of a minimal but functional * default will be refered to henceforth as <i>graceful degradation</i>. * This process is advantageous in that it allows developers and administrators * to easily choose packaging options, simply by adding to or deleting concerned * classes from an HSQLDB installation, without worry over providing complex * initialization properties or disrupting the core operation of the engine. * In this particular context, <i>graceful degradation</i> allows easy choices * regarding database metadata, spanning the range of full (design-time), * custom-written, minimal (production-time) or <CODE>null</CODE> * (space-constrained) system table production implementations. <p> * * In the default full implementation, a number of new system tables are * provided that, although not used directly by this class, present previously * unavailable information about the database, such as about its triggers and * aliases. <p> * * In order to better support graphical database exploration tools and as an * experimental intermediate step toward more fully supporting SQL9n and * SQL200n, the default installed DatabaseInformation implementation * is also capable of reporting pseudo name space information, such as * the catalog (database URI) of database objects. <p> * * The catalog reporting feature is turned off by default but * can be turned on by providing the appropriate entries in the database * properties file (see the advanced topics section of the product * documentation). <p> * * When the feature is turned on, catalog is reported using * the following conventions: <p> * * <ol> * <li>All objects are reported as having a catalog equal to the URI of the * database, which is equivalent to the catenation of the * <b><type></b> and <b><path></b> portions of the HSQLDB * internal JDBC connection URL.<p> * * Examples: <p> * * <pre class="JavaCodeExample"> * <span class="JavaStringLiteral">"jdbc:hsqldb:file:test"</span> => <span class="JavaStringLiteral">"file:test"</span> * <span class="JavaStringLiteral">"jdbc:hsqldb:mem:."</span> => <span class="JavaStringLiteral">"mem:."</span> * <span class="JavaStringLiteral">"jdbc:hsqldb:hsql:/host/<alias>..."</span> => URI of aliased database * <span class="JavaStringLiteral">"jdbc:hsqldb:http:/host/<alias>..."</span> => URI of aliased database * </pre> * * <b>Note:</b> No provision is made for qualifying database objects * by catalog in DML or DDL SQL. This feature is functional only with * respect to browsing the database through the DatabaseMetaData and system * table interfaces. <p> * * </ol> * * Again, it should be well understood that this feature provide an * <i>emulation</i> of catalog support and is intended only * as an experimental implementation to enhance the browsing experience * when using graphical database explorers and to make a first foray * into tackling the issue of implementing true catalog support * in the future. <p> * * Due the nature of the new database system table production process, fewer * assumptions can be made by this class about what information is made * available in the system tables supporting <code>DatabaseMetaData</code> * methods. Because of this, the SQL queries behind the <code>ResultSet</code> * producing methods have been cleaned up and made to adhere more strictly to * the JDBC contracts specified in relation to the method parameters. <p> * * One of the remaining assumptions concerns the <code>approximate</code> * argument of {@link #getIndexInfo getIndexInfo()}. This parameter is still * ignored since there is not yet any process in place to internally gather * and persist table and index statistics. A primitive version of a statistics * gathering and reporting subsystem <em>may</em> be introduced some time in the * 1.7.x series of releases, but no hard decision has yet been made. <p> * * Another assumption is that simple select queries against certain system * tables will return rows in JDBC contract order in the absence of an * "ORDER BY" clause. The reason for this is that results * come back much faster when no "ORDER BY" clause is used. * Developers wishing to extend or replace an existing system table production * class should be aware of this, either adding the contract * "ORDER BY" clause to the SQL in corresponding methods in this class, * or, better, by maintaing rows in the correct order in the underlying * system tables, prefereably by creating appropriate primary indices. <p> * * <hr> * * <b>JRE 1.1.x Notes:</b> <p> * * In general, JDBC 2 support requires Java 1.2 and above, and JDBC3 requires * Java 1.4 and above. In HSQLDB, support for methods introduced in different * versions of JDBC depends on the JDK version used for compiling and building * HSQLDB.<p> * * Since 1.7.0, it is possible to build the product so that * all JDBC 2 methods can be called while executing under the version 1.1.x * <em>Java Runtime Environment</em><sup><font size="-2">TM</font></sup>. * However, some of these method calls require <code>int</code> values that * are defined only in the JDBC 2 or greater version of the * {@link java.sql.ResultSet ResultSet} interface. For this reason, when the * product is compiled under JDK 1.1.x, these values are defined in * {@link jdbcResultSet jdbcResultSet}.<p> * * In a JRE 1.1.x environment, calling JDBC 2 methods that take or return the * JDBC2-only <code>ResultSet</code> values can be achieved by referring * to them in parameter specifications and return value comparisons, * respectively, as follows: <p> * * <pre class="JavaCodeExample"> * jdbcResultSet.FETCH_FORWARD * jdbcResultSet.TYPE_FORWARD_ONLY * jdbcResultSet.TYPE_SCROLL_INSENSITIVE * jdbcResultSet.CONCUR_READ_ONLY * // etc * </pre> * * However, please note that code written in such a manner will not be * compatible for use with other JDBC 2 drivers, since they expect and use * <code>ResultSet</code>, rather than <code>jdbcResultSet</code>. Also * note, this feature is offered solely as a convenience to developers * who must work under JDK 1.1.x due to operating constraints, yet wish to * use some of the more advanced features available under the JDBC 2 * specification.<p> * * (fredt@users)<br> * (boucherb@users) * </div> * <!-- end release-specific documentation --> * * @author boucherb@users * @author fredt@users * @version 1.7.2 * @see org.hsqldb.DatabaseInformation * @see org.hsqldb.DatabaseInformationMain * @see org.hsqldb.DatabaseInformationFull */public class jdbcDatabaseMetaData implements DatabaseMetaData { /** Used by getBestRowIdentifier to avoid extra object construction */ static final Integer INT_COLUMNS_NO_NULLS = new Integer(columnNoNulls); // ----------------------------------------------------------------------- // private attributes // ----------------------------------------------------------------------- /** * The connection this object uses to retrieve database instance-specific * metadata. */ private jdbcConnection connection; /** * Connection property for schema reporting. */ private boolean useSchemaDefault; /** * A CSV list representing the SQL IN list to use when generating * queries for <code>getBestRowIdentifier</code> when the * <code>scope</code> argument is <code>bestRowSession</code>. * @since HSQLDB 1.7.2 */ private static final String BRI_SESSION_SCOPE_IN_LIST = "(" + bestRowSession + ")"; /** * A CSV list representing the SQL IN list to use when generating * queries for <code>getBestRowIdentifier</code> when the * <code>scope</code> argument is <code>bestRowTemporary</code>. * @since HSQLDB 1.7.2 */ private static final String BRI_TEMPORARY_SCOPE_IN_LIST = "(" + bestRowTemporary + "," + bestRowTransaction + "," + bestRowSession + ")"; /** * A CSV list representing the SQL IN list to use when generating * queries for <code>getBestRowIdentifier</code> when the * <code>scope</code> argument is <code>bestRowTransaction</code>. * @since HSQLDB 1.7.2 */ private static final String BRI_TRANSACTION_SCOPE_IN_LIST = "(" + bestRowTransaction + "," + bestRowSession + ")"; /** * "SELECT * FROM ". <p> * * This attribute is in support of methods that use SQL SELECT statements to * generate returned <code>ResultSet</code> objects. <p> * * @since HSQLDB 1.7.2 */ private static final String selstar = "SELECT * FROM INFORMATION_SCHEMA.";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -