📄 databaseinformationfull.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;import java.lang.reflect.Method;import org.hsqldb.lib.FileUtil;import org.hsqldb.lib.HashMap;import org.hsqldb.lib.HashSet;import org.hsqldb.lib.HsqlArrayList;import org.hsqldb.lib.Iterator;import org.hsqldb.persist.DataFileCache;import org.hsqldb.persist.HsqlDatabaseProperties;import org.hsqldb.persist.HsqlProperties;import org.hsqldb.persist.Log;import org.hsqldb.persist.TextCache;import org.hsqldb.scriptio.ScriptWriterBase;import org.hsqldb.store.ValuePool;// fredt@users - 1.7.2 - structural modifications to allow inheritance// boucherb@users - 1.7.2 - 20020225// - factored out all reusable code into DIXXX support classes// - completed Fred's work on allowing inheritance// boucherb@users - 1.7.2 - 20020304 - bug fixes, refinements, better java docs// fredt@users - 1.8.0 - updated to report latest enhancements and changes// boucherb@users - 1.8.0 - 20050515 - furhter SQL 2003 metadata support/** * Extends DatabaseInformationMain to provide additional system table * support. <p> * * @author boucherb@users * @version 1.8.0 * @since 1.7.2 */final class DatabaseInformationFullextends org.hsqldb.DatabaseInformationMain { /** Provides SQL function/procedure reporting support. */ protected DIProcedureInfo pi; /** * Constructs a new DatabaseInformationFull instance. <p> * * @param db the database for which to produce system tables. * @throws HsqlException if a database access error occurs. */ DatabaseInformationFull(Database db) throws HsqlException { super(db); pi = new DIProcedureInfo(ns); } /** * Retrieves the system table corresponding to the specified index. <p> * * @param tableIndex index identifying the system table to generate * @throws HsqlException if a database access error occurs * @return the system table corresponding to the specified index */ protected Table generateTable(int tableIndex) throws HsqlException { switch (tableIndex) { case SYSTEM_PROCEDURECOLUMNS : return SYSTEM_PROCEDURECOLUMNS(); case SYSTEM_PROCEDURES : return SYSTEM_PROCEDURES(); case SYSTEM_SUPERTABLES : return SYSTEM_SUPERTABLES(); case SYSTEM_SUPERTYPES : return SYSTEM_SUPERTYPES(); case SYSTEM_UDTATTRIBUTES : return SYSTEM_UDTATTRIBUTES(); case SYSTEM_UDTS : return SYSTEM_UDTS(); case SYSTEM_VERSIONCOLUMNS : return SYSTEM_VERSIONCOLUMNS(); // HSQLDB-specific case SYSTEM_ALIASES : return SYSTEM_ALIASES(); case SYSTEM_CACHEINFO : return SYSTEM_CACHEINFO(); case SYSTEM_CLASSPRIVILEGES : return SYSTEM_CLASSPRIVILEGES(); case SYSTEM_SESSIONINFO : return SYSTEM_SESSIONINFO(); case SYSTEM_PROPERTIES : return SYSTEM_PROPERTIES(); case SYSTEM_SESSIONS : return SYSTEM_SESSIONS(); case SYSTEM_TRIGGERCOLUMNS : return SYSTEM_TRIGGERCOLUMNS(); case SYSTEM_TRIGGERS : return SYSTEM_TRIGGERS(); case SYSTEM_VIEWS : return SYSTEM_VIEWS(); case SYSTEM_TEXTTABLES : return SYSTEM_TEXTTABLES(); case SYSTEM_USAGE_PRIVILEGES : return SYSTEM_USAGE_PRIVILEGES(); case SYSTEM_CHECK_COLUMN_USAGE : return SYSTEM_CHECK_COLUMN_USAGE(); case SYSTEM_CHECK_ROUTINE_USAGE : return SYSTEM_CHECK_ROUTINE_USAGE(); case SYSTEM_CHECK_TABLE_USAGE : return SYSTEM_CHECK_TABLE_USAGE(); case SYSTEM_TABLE_CONSTRAINTS : return SYSTEM_TABLE_CONSTRAINTS(); case SYSTEM_VIEW_TABLE_USAGE : return SYSTEM_VIEW_TABLE_USAGE(); case SYSTEM_VIEW_COLUMN_USAGE : return SYSTEM_VIEW_COLUMN_USAGE(); case SYSTEM_VIEW_ROUTINE_USAGE : return SYSTEM_VIEW_ROUTINE_USAGE(); case SYSTEM_AUTHORIZATIONS : { return SYSTEM_AUTHORIZATIONS(); } case SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS : { return SYSTEM_ROLE_AUTHORIZATION_DESCRIPTORS(); } case SYSTEM_SCHEMATA : { return SYSTEM_SCHEMATA(); } case SYSTEM_COLLATIONS : { return SYSTEM_COLLATIONS(); } default : return super.generateTable(tableIndex); } } /** * Retrieves a <code>Table</code> object describing the aliases defined * within this database. <p> * * Currently two types of alias are reported: DOMAIN alaises (alternate * names for column data types when issuing "CREATE TABLE" DDL) and * ROUTINE aliases (alternate names that can be used when invoking * routines as SQL functions or stored procedures). <p> * * Each row is an alias description with the following columns: <p> * * <pre class="SqlCodeExample"> * OBJECT_TYPE VARCHAR type of the aliased object * OBJECT_CAT VARCHAR catalog of the aliased object * OBJECT_SCHEM VARCHAR schema of the aliased object * OBJECT_NAME VARCHAR simple identifier of the aliased object * ALIAS_CAT VARCHAR catalog in which alias is defined * ALIAS_SCHEM VARCHAR schema in which alias is defined * ALIAS VARCHAR alias for the indicated object * </pre> <p> * * <b>Note:</b> Up to and including HSQLDB 1.7.2, user-defined aliases * are supported only for SQL function and stored procedure calls * (indicated by the value "ROUTINE" in the OBJECT_TYPE * column), and there is no syntax for dropping aliases, only for * creating them. <p> * @return a Table object describing the accessisble * aliases in the context of the calling session * @throws HsqlException if an error occurs while producing the table */ Table SYSTEM_ALIASES() throws HsqlException { Table t = sysTables[SYSTEM_ALIASES]; if (t == null) { t = createBlankTable(sysTableHsqlNames[SYSTEM_ALIASES]); addColumn(t, "OBJECT_TYPE", Types.VARCHAR, 32, false); // not null addColumn(t, "OBJECT_CAT", Types.VARCHAR); addColumn(t, "OBJECT_SCHEM", Types.VARCHAR); addColumn(t, "OBJECT_NAME", Types.VARCHAR, false); // not null addColumn(t, "ALIAS_CAT", Types.VARCHAR); addColumn(t, "ALIAS_SCHEM", Types.VARCHAR); addColumn(t, "ALIAS", Types.VARCHAR, false); // not null // order: OBJECT_TYPE, OBJECT_NAME, ALIAS. // true PK. t.createPrimaryKey(null, new int[] { 0, 3, 6 }, true); return t; } // Holders for calculated column values String cat; String schem; String alias; String objName; String objType; // Intermediate holders String className; HashMap hAliases; Iterator aliases; Object[] row; int pos; // Column number mappings final int ialias_object_type = 0; final int ialias_object_cat = 1; final int ialias_object_schem = 2; final int ialias_object_name = 3; final int ialias_cat = 4; final int ialias_schem = 5; final int ialias = 6; // Initialization hAliases = database.getAliasMap(); aliases = hAliases.keySet().iterator(); objType = "ROUTINE"; // Do it. while (aliases.hasNext()) { row = t.getEmptyRowData(); alias = (String) aliases.next(); objName = (String) hAliases.get(alias); // must have class grant to see method call aliases pos = objName.lastIndexOf('.'); if (pos <= 0) { // should never occur in practice, as this is typically a Java // method name, but there's nothing preventing a user from // creating an alias entry that is not in method FQN form; // such entries are not illegal, only useless. Probably, // we should eventually try to disallow them. continue; } className = objName.substring(0, pos); if (!session.isAccessible(className)) { continue; } cat = ns.getCatalogName(objName); schem = ns.getSchemaName(className); row[ialias_object_type] = objType; row[ialias_object_cat] = cat; row[ialias_object_schem] = schem; row[ialias_object_name] = objName; row[ialias_cat] = cat; row[ialias_schem] = schem; row[ialias] = alias; t.insertSys(row); } // must have create/alter table rights to see domain aliases if (session.isAdmin()) { Iterator typeAliases = Types.typeAliases.keySet().iterator(); objType = "DOMAIN"; while (typeAliases.hasNext()) { row = t.getEmptyRowData(); alias = (String) typeAliases.next(); int tn = Types.typeAliases.get(alias, Integer.MIN_VALUE); objName = Types.getTypeString(tn); if (alias.equals(objName)) { continue; } cat = ns.getCatalogName(objName); schem = ns.getSchemaName(objName); row[ialias_object_type] = objType; row[ialias_object_cat] = cat; row[ialias_object_schem] = schem; row[ialias_object_name] = objName; row[ialias_cat] = cat; row[ialias_schem] = schem; row[ialias] = alias;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -