⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 databaseinformationmain.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* 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 org.hsqldb.HsqlNameManager.HsqlName;import org.hsqldb.lib.HashMap;import org.hsqldb.lib.HashSet;import org.hsqldb.lib.HsqlArrayList;import org.hsqldb.lib.Iterator;import org.hsqldb.lib.WrapperIterator;import org.hsqldb.persist.HsqlProperties;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/** * Produces a collection of tables that form the system data dictionary. <p> * * Implementations use a group of arrays of equal size to store various * attributes or cached instances of system tables.<p> * * Two fixed static lists of reserved table names are kept in String[] and * HsqlName[] forms. These are shared by all implementations of * DatabaseInformtion.<p> * * Each implementation keeps a lookup set of names for those tables whose * contents are never cached (nonCachedTablesSet). <p> * * An instance of this class uses three lists named sysTablexxxx for caching * system tables.<p> * * sysTableSessionDependent indicates which tables contain data that is * dependent on the user rights of the User associatiod with the Session.<p> * * sysTableSessions contains the Session with whose rights each cached table * was built.<p> * * sysTables contains the cached tables.<p> * * At the time of instantiation, which is part of the Database.open() method * invocation, an empty table is created and placed in sysTables with calls to * generateTable(int) for each name in sysTableNames. Some of these * table entries may be null if an implementation does not produce them.<p> * * Calls to getSystemTable(String, Session) return a cached table if various * caching rules are met (see below), or it will delete all rows of the table * and rebuild the contents via generateTable(int).<p> * * generateTable(int) calls the appropriate single method for each table. * These methods either build and return an empty table (if sysTables * contains null for the table slot) or populate the table with up-to-date * rows. <p> * * When the setDirty() call is made externally, the internal isDirty flag * is set. This flag is used next time a call to * getSystemTable(String, Session) is made. <p> * * Rules for caching are applied as follows: <p> * * When a call to getSystemTable(String, Session) is made, if the isDirty flag * is true, then the contents of all cached tables are cleared and the * sysTableUsers slot for all tables is set to null. This also has the * effect of clearing the isDirty and isDirtyNextIdentity flags<p> * * if the isDirtyNextIdentity flag is true at this point, then the contents * of all next identity value dependent cached tables are cleared and the * sysTableUsers slot for these tables are set to null.  Currently, * the only member of this set is the SYSTEM_TABLES system table. * * If a table has non-cached contents, its contents are cleared and * rebuilt. <p> * * For the rest of the tables, if the sysTableSessions slot is null or if the * Session parameter is not the same as the Session object * in that slot, the table contents are cleared and rebuilt. <p> * * (fredt@users) <p> * @author boucherb@users * @version 1.8.0 * @since 1.7.2 */class DatabaseInformationMain extends DatabaseInformation {    // HsqlName objects for the system tables    /** The HsqlNames of the system tables. */    protected static final HsqlName[] sysTableHsqlNames;    /** Current user for each cached system table */    protected final int[] sysTableSessions = new int[sysTableNames.length];    /** true if the contents of a cached system table depends on the session */    protected final boolean[] sysTableSessionDependent =        new boolean[sysTableNames.length];    /** cache of system tables */    protected final Table[] sysTables = new Table[sysTableNames.length];    /** Set: { names of system tables that are not to be cached } */    protected static final HashSet nonCachedTablesSet;    /**     * Map: simple <code>Column</code> name <code>String</code> object =>     * <code>HsqlName</code> object.     */    protected static final HashMap columnNameMap;    /**     * The <code>Session</code> object under consideration in the current     * executution context.     */    protected Session session;    /** The table types HSQLDB supports. */    protected static final String[] tableTypes = new String[] {        "GLOBAL TEMPORARY", "SYSTEM TABLE", "TABLE", "VIEW"    };    /** Provides naming support. */    protected DINameSpace ns;    static {        columnNameMap      = new HashMap();        nonCachedTablesSet = new HashSet();        sysTableHsqlNames  = new HsqlName[sysTableNames.length];        for (int i = 0; i < sysTableNames.length; i++) {            sysTableHsqlNames[i] =                HsqlNameManager.newHsqlSystemObjectName(sysTableNames[i]);            sysTableHsqlNames[i].schema =                SchemaManager.INFORMATION_SCHEMA_HSQLNAME;        }        // build the set of non-cached tables        nonCachedTablesSet.add("SYSTEM_CACHEINFO");        nonCachedTablesSet.add("SYSTEM_SESSIONINFO");        nonCachedTablesSet.add("SYSTEM_SESSIONS");        nonCachedTablesSet.add("SYSTEM_PROPERTIES");        nonCachedTablesSet.add("SYSTEM_SEQUENCES");    }    /**     * Constructs a table producer which provides system tables     * for the specified <code>Database</code> object. <p>     *     * <b>Note:</b> before 1.7.2 Alpha N, it was important to observe that     * by specifying an instance of this class or one of its descendents to     * handle system table production, the new set of builtin permissions     * and aliases would overwrite those of an existing database, meaning that     * metadata reporting might have been rendered less secure if the same     * database were then opened again using a lower numbered system table     * producer instance (i.e. one in a 1.7.1 or earlier distribution).     * As of 1.7.2 Alpha N, system-generated permissions and aliases are no     * longer recorded in the checkpoint script, obseleting this issue.     * Checkpointing of system-generated grants and aliases was removed     * because their existence is very close to a core requirment for correct     * operation and they are reintroduced to the system at each startup.     * In a future release, it may even be an exception condition to attempt     * to remove or alter system-generated grants and aliases,     * respectvely. <p>     *     * @param db the <code>Database</code> object for which this object     *      produces system tables     * @throws HsqlException if a database access error occurs     */    DatabaseInformationMain(Database db) throws HsqlException {        super(db);        init();    }    /**     * Adds a <code>Column</code> object with the specified name, data type,     * data size and nullability to the specified <code>Table</code>     * object. <p>     *     * @param t the table to which to add the specified column     * @param name the name of the column     * @param type the data type of the column     * @param size the precision/length of the column     * @param nullable <code>true</code> if the column is to allow null values,     *      else <code>false</code>     * @throws HsqlException if a problem occurs when adding the     *      column (e.g. duplicate name)     */    protected final void addColumn(Table t, String name, int type, int size,                                   boolean nullable) throws HsqlException {        HsqlName cn;        Column   c;        cn = (HsqlName) columnNameMap.get(name);        if (cn == null) {            cn = database.nameManager.newHsqlName(name, false);            columnNameMap.put(name, cn);        }        c = new Column(cn, nullable, type, size, 0, false, null);        t.addColumn(c);    }    /**     * Adds a <code>Column</code> object with the specified name, data type     * and nullability to the specified <code>Table</code> object. <p>     *     * @param t the table to which to add the specified column     * @param name the name of the column     * @param type the data type of the column     * @param nullable <code>true</code> if the column is to allow null values,     *      else <code>false</code>     * @throws HsqlException if a problem occurs when adding the     *      column (e.g. duplicate name)     */    protected final void addColumn(Table t, String name, int type,                                   boolean nullable) throws HsqlException {        addColumn(t, name, type, 0, nullable);    }    /**     * Adds a nullable <code>Column</code> object with the specified name and     * data type to the specified <code>Table</code> object. <p>     *     * @param t the table to which to add the specified column     * @param name the name of the column     * @param type the data type of the column     * @throws HsqlException if a problem occurs when adding the     *      column (e.g. duplicate name)     */    protected final void addColumn(Table t, String name,                                   int type) throws HsqlException {        addColumn(t, name, type, true);    }    /**     * Retrieves an enumeration over all of the tables in this database.     * This means all user tables, views, system tables, system views,     * including temporary and text tables. <p>     *     * @return an enumeration over all of the tables in this database     */    protected final Iterator allTables() {        return new WrapperIterator(database.schemaManager.allTablesIterator(),                                   new WrapperIterator(sysTables, true));    }    /**     * Clears the contents of cached system tables and resets user slots     * to null. <p>     *     * @throws HsqlException if a database access error occurs     */    protected final void cacheClear() throws HsqlException {        int i = sysTables.length;        while (i-- > 0) {            Table t = sysTables[i];            if (t != null) {                t.clearAllRows(session);            }            sysTableSessions[i] = -1;        }        isDirty = false;    }    /**     * Retrieves the system table corresponding to the specified     * tableIndex value. <p>     *     * @param tableIndex int value identifying the system table to generate     * @throws HsqlException if a database access error occurs     * @return the system table corresponding to the specified tableIndex value     */    protected Table generateTable(int tableIndex) throws HsqlException {        Table t = sysTables[tableIndex];//        Please note that this class produces non-null tables for//        just those absolutely essential to the JDBC 1 spec and the//        HSQLDB core.  Also, all table producing methods except//        SYSTEM_PROCEDURES() and SYSTEM_PROCEDURECOLUMNS() are declared final;//        this class produces only an empty table for each, as per previous//        DatabaseInformation implementations, whereas//        DatabaseInformationFull produces comprehensive content for//        them).////        This break down of inheritance allows DatabaseInformation and//        DatabaseInformationMain (this class) to be made as small as possible

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -