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

📄 databaseinformation.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* Copyrights and Licenses * * This product includes Hypersonic SQL. * Originally developed by Thomas Mueller and the Hypersonic SQL Group.  * * Copyright (c) 1995-2000 by the Hypersonic SQL 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.  *     -  All advertising materials mentioning features or use of this software must display the *        following acknowledgment: "This product includes Hypersonic SQL."  *     -  Products derived from this software may not be called "Hypersonic SQL" nor may *        "Hypersonic SQL" appear in their names without prior written permission of the *         Hypersonic SQL Group.  *     -  Redistributions of any form whatsoever must retain the following acknowledgment: "This *          product includes Hypersonic SQL."  * This software is provided "as is" and any expressed 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 the Hypersonic SQL Group or its 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 any 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.  * This software consists of voluntary contributions made by many individuals on behalf of the * Hypersonic SQL Group. * * * For work added by the HSQL Development Group: * * Copyright (c) 2001-2002, 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, including earlier * license statements (above) and comply with all above license conditions. * * 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, including earlier * license statements (above) and comply with all above license conditions. * * 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.sql.SQLException;import java.sql.Types;import java.sql.DatabaseMetaData;import java.util.Hashtable;import java.util.Vector;// fredt@users 20020130 - patch 491987 by jimbag@users// applied to different parts// fredt@users 20020215 - patch 1.7.0 by fredt - quoted identifiers// applied to different parts to support the sql standard for// naming of columns and tables (use of quoted identifiers as names)// written for universal support of quoted names including the quote character// and speed improvements to avoid repetitive string comparisons// thanks to suggestions by boucherb@users// instigated by patch 489864 by jytou@users// fredt@users 20020218 - patch 1.7.0 by fredt - DEFAULT keyword// support for default values for table columns// fredt@users 20020225 - patch 489777 by fredt// restructuring for error trapping// fredt@users 20020225 - patch 1.7.0 - named constraints// fredt@users 20020225 - patch 1.7.0 - multi-column primary keys// fredt@users 20020523 - patch 1.7.0 - JDBC reporting of forgin keys// fredt@users 20020526 - patch 1.7.0 - JDBC reporting of best row identifier/** * Provides information about the database. * * * @version 1.7.0 */class DatabaseInformation {    private Database             dDatabase;    private UserManager          aAccess;    private Vector               tTable;    private static final Integer INTEGER_0 = new Integer(0);    /**     * Constructor declaration     *     *     * @param db     * @param tables     * @param access     */    DatabaseInformation(Database db, Vector tables, UserManager access) {        dDatabase = db;        tTable    = tables;        aAccess   = access;    }    // some drivers use the following titles:    // static final String META_SCHEM="OWNER";    // static final String META_CAT="QUALIFIER";    // static final String META_COLUMN_SIZE="PRECISION";    // static final String META_BUFFER_LENGTH="LENGTH";    // static final String META_DECIMAL_DIGITS="SCALE";    // static final String META_NUM_PREC_RADIX="RADIX";    // static final String META_FIXED_PREC_SCALE="MONEY";    // static final String META_ORDINAL_POSITION="SEQ_IN_INDEX";    // static final String META_ASC_OR_DESC="COLLATION";    static final String      META_SCHEM            = "SCHEM";    static final String      META_CAT              = "CAT";    static final String      META_COLUMN_SIZE      = "COLUMN_SIZE";    static final String      META_BUFFER_LENGTH    = "BUFFER_LENGTH";    static final String      META_DECIMAL_DIGITS   = "DECIMAL_DIGITS";    static final String      META_NUM_PREC_RADIX   = "NUM_PREC_RADIX";    static final String      META_FIXED_PREC_SCALE = "FIXED_PREC_SCALE";    static final String      META_ORDINAL_POSITION = "ORDINAL_POSITION";    static final String      META_ASC_OR_DESC      = "ASC_OR_DESC";    private static Hashtable sysTableNames;    private static final int SYSTEM_PROCEDURES        = 1;    private static final int SYSTEM_PROCEDURECOLUMNS  = 2;    private static final int SYSTEM_TABLES            = 3;    private static final int SYSTEM_SCHEMAS           = 4;    private static final int SYSTEM_CATALOGS          = 5;    private static final int SYSTEM_TABLETYPES        = 6;    private static final int SYSTEM_COLUMNS           = 7;    private static final int SYSTEM_COLUMNPRIVILEGES  = 8;    private static final int SYSTEM_TABLEPRIVILEGES   = 9;    private static final int SYSTEM_BESTROWIDENTIFIER = 10;    private static final int SYSTEM_VERSIONCOLUMNS    = 11;    private static final int SYSTEM_PRIMARYKEYS       = 12;    private static final int SYSTEM_IMPORTEDKEYS      = 13;    private static final int SYSTEM_EXPORTEDKEYS      = 14;    private static final int SYSTEM_CROSSREFERENCE    = 15;    private static final int SYSTEM_TYPEINFO          = 16;    private static final int SYSTEM_INDEXINFO         = 17;    private static final int SYSTEM_UDTS              = 18;    private static final int SYSTEM_CONNECTIONINFO    = 19;    private static final int SYSTEM_USERS             = 20;    // supported table types    private static final String[] tableTypes = new String[] {        "TABLE", "VIEW", "GLOBAL TEMPORARY"    };    static {        sysTableNames = new Hashtable(37);        String sysNames[] = {            "SYSTEM_PROCEDURES", "SYSTEM_PROCEDURECOLUMNS", "SYSTEM_TABLES",            "SYSTEM_SCHEMAS", "SYSTEM_CATALOGS", "SYSTEM_TABLETYPES",            "SYSTEM_COLUMNS", "SYSTEM_COLUMNPRIVILEGES",            "SYSTEM_TABLEPRIVILEGES", "SYSTEM_BESTROWIDENTIFIER",            "SYSTEM_VERSIONCOLUMNS", "SYSTEM_PRIMARYKEYS",            "SYSTEM_IMPORTEDKEYS", "SYSTEM_EXPORTEDKEYS",            "SYSTEM_CROSSREFERENCE", "SYSTEM_TYPEINFO", "SYSTEM_INDEXINFO",            "SYSTEM_UDTS", "SYSTEM_CONNECTIONINFO", "SYSTEM_USERS"        };        for (int i = 0; i < sysNames.length; i++) {            sysTableNames.put(sysNames[i], new Integer(i + 1));        }    }    static boolean isSystemTable(String name) {        return sysTableNames.get(name) == null ? false                                               : true;    }    /**     * Method declaration     *     *     * @param name     * @param session     *     * @return     *     * @throws SQLException     */    Table getSystemTable(String tablename,                         Session session) throws SQLException {        HsqlName name    = new HsqlName(tablename, false);        Integer  tableId = (Integer) sysTableNames.get(tablename);        if (tableId == null) {            return null;        }        int   tableIdValue = tableId.intValue();        Table t            = createTable(name);        switch (tableIdValue) {            case SYSTEM_PROCEDURES : {                t.addColumn("PROCEDURE_" + META_CAT, Types.VARCHAR);                t.addColumn("PROCEDURE_" + META_SCHEM, Types.VARCHAR);                t.addColumn("PROCEDURE_NAME", Types.VARCHAR);                t.addColumn("NUM_INPUT_PARAMS", Types.INTEGER);                t.addColumn("NUM_OUTPUT_PARAMS", Types.INTEGER);                t.addColumn("NUM_RESULT_SETS", Types.INTEGER);                t.addColumn("REMARKS", Types.VARCHAR);                t.addColumn("PROCEDURE_TYPE", Types.SMALLINT);                t.createPrimaryKey();                return t;            }            case SYSTEM_PROCEDURECOLUMNS : {                t.addColumn("PROCEDURE_" + META_CAT, Types.VARCHAR);                t.addColumn("PROCEDURE_" + META_SCHEM, Types.VARCHAR);                t.addColumn("PROCEDURE_NAME", Types.VARCHAR);                t.addColumn("COLUMN_NAME", Types.VARCHAR);                t.addColumn("COLUMN_TYPE", Types.SMALLINT);                t.addColumn("DATA_TYPE", Types.SMALLINT);                t.addColumn("TYPE_NAME", Types.VARCHAR);                t.addColumn("PRECISION", Types.INTEGER);                t.addColumn("LENGTH", Types.INTEGER);                t.addColumn("SCALE", Types.SMALLINT);                t.addColumn("RADIX", Types.SMALLINT);                t.addColumn("NULLABLE", Types.SMALLINT);                t.addColumn("REMARKS", Types.VARCHAR);                t.createPrimaryKey();                return t;            }            case SYSTEM_TABLES : {                t.addColumn("TABLE_" + META_CAT, Types.VARCHAR);                t.addColumn("TABLE_" + META_SCHEM, Types.VARCHAR);                t.addColumn("TABLE_NAME", Types.VARCHAR);                t.addColumn("TABLE_TYPE", Types.VARCHAR);                t.addColumn("REMARKS", Types.VARCHAR);// boucherb@users 20020415 added for JDBC 3 clients                t.addColumn("TYPE_" + META_CAT, Types.VARCHAR);                t.addColumn("TYPE_" + META_SCHEM, Types.VARCHAR);                t.addColumn("TYPE_NAME", Types.VARCHAR);                t.addColumn("SELF_REFERENCING_COL_NAME", Types.VARCHAR);                t.addColumn("REF_GENERATION", Types.VARCHAR);                t.createPrimaryKey();                for (int i = 0, tSize = tTable.size(); i < tSize; i++) {                    Table  table = (Table) tTable.elementAt(i);                    Object o[]   = t.getNewRow();                    o[0] = o[1] = "";                    o[2] = table.getName().name;                    switch (table.tableType) {                        case Table.VIEW :                            o[3] = "VIEW";                            break;                        case Table.TEMP_TABLE :                        case Table.TEMP_TEXT_TABLE :                            if (dDatabase.findUserTable(                                    table.getName().name, session) == null) {                                continue;                            }                            o[3] = "GLOBAL TEMPORARY";                            break;                        default :                            o[3] = "TABLE";                    }                    // sqlbob@users Set remarks to readonly status.                    if (table.isDataReadOnly()) {                        o[4] = "ReadOnlyData=true";                    }                    // sqlbob@users Add data source to remarks                    String dataSource = table.getDataSource();                    if (dataSource != null) {                        if (o[4] == null) {                            o[4] = "";

⌨️ 快捷键说明

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