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

📄 databaseinformationmain.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *     * Given the above definitions, the rules currently in effect for reporting     * best row identifier are as follows, in order of precedence: <p>     *     * <OL>     * <LI> if the table under consideration has a primary key contraint, then     *      the columns of the primary key are reported, with no consideration     *      given to the column set performance ranking over the set of     *      candidate keys. Each row has its IN_KEY column set to TRUE.     *     * <LI> if 1.) does not hold, then if there exits one or more alternate     *      keys, then the columns of the alternate key with the lowest column     *      count are reported, with no consideration given to the column set     *      performance ranking over the set of candidate keys. If there     *      exists a tie for lowest column count, then the columns of the     *      first such key encountered are reported.     *      Each row has its IN_KEY column set to TRUE.     *     * <LI> if both 1.) and 2.) do not hold, then, if possible, a unique     *      contraint/index is selected from the set of unique     *      contraints/indices containing at least one column having     *      a not null constraint, with no consideration given to the     *      column set performance ranking over the set of all such     *      candidate column sets. If there exists a tie for lowest non-zero     *      count of columns having a not null constraint, then the columns     *      of the first such encountered candidate set are reported. Each     *      row has its IN_KEY column set to FALSE. <p>     *     * <LI> Finally, if the set of candidate column sets in 3.) is the empty,     *      then no column set is reported for the table under consideration.     * </OL> <p>     *     * The scope reported for a best row identifier column set is determined     * thus: <p>     *     * <OL>     * <LI> if the database containing the table under consideration is in     *      read-only mode or the table under consideration is GLOBAL TEMPORARY     *      (a TEMP or TEMP TEXT table, in HSQLDB parlance), then the scope     *      is reported as     *      <code>java.sql.DatabaseMetaData.bestRowSession</code>.     *     * <LI> if 1.) does not hold, then the scope is reported as     *      <code>java.sql.DatabaseMetaData.bestRowTemporary</code>.     * </OL> <p>     *     * @return a <code>Table</code> object describing the optimal     * set of visible columns that uniquely identifies a row     * for each accessible table defined within this database     * @throws HsqlException if an error occurs while producing the table     */    final Table SYSTEM_BESTROWIDENTIFIER() throws HsqlException {        Table t = sysTables[SYSTEM_BESTROWIDENTIFIER];        if (t == null) {            t = createBlankTable(sysTableHsqlNames[SYSTEM_BESTROWIDENTIFIER]);            addColumn(t, "SCOPE", Types.SMALLINT, false);            // not null            addColumn(t, "COLUMN_NAME", Types.VARCHAR, false);       // not null            addColumn(t, "DATA_TYPE", Types.SMALLINT, false);        // not null            addColumn(t, "TYPE_NAME", Types.VARCHAR, 32, false);     // not null            addColumn(t, "COLUMN_SIZE", Types.INTEGER);            addColumn(t, "BUFFER_LENGTH", Types.INTEGER);            addColumn(t, "DECIMAL_DIGITS", Types.SMALLINT);            addColumn(t, "PSEUDO_COLUMN", Types.SMALLINT, false);    // not null            addColumn(t, "TABLE_CAT", Types.VARCHAR);            addColumn(t, "TABLE_SCHEM", Types.VARCHAR);            addColumn(t, "TABLE_NAME", Types.VARCHAR, false);        // not null            addColumn(t, "NULLABLE", Types.SMALLINT, false);         // not null            addColumn(t, "IN_KEY", Types.BOOLEAN, false);            // not null            // order: SCOPE            // for unique:  TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME            // false PK, as TABLE_CAT and/or TABLE_SCHEM may be null            t.createPrimaryKey(null, new int[] {                0, 8, 9, 10, 1            }, false);            return t;        }        // calculated column values        Integer scope;           // { temp, transaction, session }        Integer pseudo;        //-------------------------------------------        // required for restriction of results via        // DatabaseMetaData filter parameters, but        // not actually required to be included in        // DatabaseMetaData.getBestRowIdentifier()        // result set        //-------------------------------------------        String  tableCatalog;    // table calalog        String  tableSchema;     // table schema        String  tableName;       // table name        Boolean inKey;           // column participates in PK or AK?        //-------------------------------------------        // TODO:  Maybe include:        //        - backing index (constraint) name?        //        - column sequence in index (constraint)?        //-------------------------------------------        // Intermediate holders        Iterator       tables;        Table          table;        DITableInfo    ti;        int[]          cols;        Object[]       row;        HsqlProperties p;        // Column number mappings        final int iscope          = 0;        final int icolumn_name    = 1;        final int idata_type      = 2;        final int itype_name      = 3;        final int icolumn_size    = 4;        final int ibuffer_length  = 5;        final int idecimal_digits = 6;        final int ipseudo_column  = 7;        final int itable_cat      = 8;        final int itable_schem    = 9;        final int itable_name     = 10;        final int inullable       = 11;        final int iinKey          = 12;        // Initialization        ti     = new DITableInfo();        p      = database.getProperties();        tables = p.isPropertyTrue("hsqldb.system_table_bri") ? allTables()                                                             : database                                                             .schemaManager                                                                 .allTablesIterator();        // Do it.        while (tables.hasNext()) {            table = (Table) tables.next();            if (table.isView() ||!isAccessibleTable(table)) {                continue;            }            cols = table.getBestRowIdentifiers();            if (cols == null) {                continue;            }            ti.setTable(table);            inKey = ValuePool.getBoolean(table.isBestRowIdentifiersStrict());            tableCatalog = ns.getCatalogName(table);            tableSchema  = table.getSchemaName();            tableName    = ti.getName();            scope        = ti.getBRIScope();            pseudo       = ti.getBRIPseudo();            for (int i = 0; i < cols.length; i++) {                row                  = t.getEmptyRowData();                row[iscope]          = scope;                row[icolumn_name]    = ti.getColName(i);                row[idata_type]      = ti.getColDataType(i);                row[itype_name]      = ti.getColDataTypeName(i);                row[icolumn_size]    = ti.getColSize(i);                row[ibuffer_length]  = ti.getColBufLen(i);                row[idecimal_digits] = ti.getColScale(i);                row[ipseudo_column]  = pseudo;                row[itable_cat]      = tableCatalog;                row[itable_schem]    = tableSchema;                row[itable_name]     = tableName;                row[inullable]       = ti.getColNullability(i);                row[iinKey]          = inKey;                t.insertSys(row);            }        }        t.setDataReadOnly(true);        return t;    }    /**     * Retrieves a <code>Table</code> object naming the accessible catalogs     * defined within this database. <p>     *     * Each row is a catalog name description with the following column: <p>     *     * <pre class="SqlCodeExample">     * TABLE_CAT   VARCHAR   catalog name     * </pre> <p>     *     * @return a <code>Table</code> object naming the accessible     *        catalogs defined within this database     * @throws HsqlException if an error occurs while producing the table     */    final Table SYSTEM_CATALOGS() throws HsqlException {        Table t = sysTables[SYSTEM_CATALOGS];        if (t == null) {            t = createBlankTable(sysTableHsqlNames[SYSTEM_CATALOGS]);            addColumn(t, "TABLE_CAT", Types.VARCHAR, false);    // not null            // order:  TABLE_CAT            // true PK            t.createPrimaryKey(null, new int[]{ 0 }, true);            return t;        }        Object[] row;        Iterator catalogs;        catalogs = ns.iterateCatalogNames();        while (catalogs.hasNext()) {            row    = t.getEmptyRowData();            row[0] = (String) catalogs.next();            t.insertSys(row);        }        t.setDataReadOnly(true);        return t;    }    /**     * Retrieves a <code>Table</code> object describing the visible     * access rights for all visible columns of all accessible     * tables defined within this database.<p>     *     * Each row is a column privilege description with the following     * columns: <p>     *     * <pre class="SqlCodeExample">     * TABLE_CAT    VARCHAR   table catalog     * TABLE_SCHEM  VARCHAR   table schema     * TABLE_NAME   VARCHAR   table name     * COLUMN_NAME  VARCHAR   column name     * GRANTOR      VARCHAR   grantor of access     * GRANTEE      VARCHAR   grantee of access     * PRIVILEGE    VARCHAR   name of access     * IS_GRANTABLE VARCHAR   grantable?: "YES" - grant to others, else "NO"     * </pre>     *     * <b>Note:</b> As of 1.7.2, HSQLDB does not support column level     * privileges. However, it does support table-level privileges, so they     * are reflected here.  That is, the content of this table is equivalent     * to a projection of SYSTEM_TABLEPRIVILEGES and SYSTEM_COLUMNS joined by     * full table identifier. <p>     *     * @return a <code>Table</code> object describing the visible     *        access rights for all visible columns of     *        all accessible tables defined within this     *        database     * @throws HsqlException if an error occurs while producing the table     */    final Table SYSTEM_COLUMNPRIVILEGES() throws HsqlException {        Table t = sysTables[SYSTEM_COLUMNPRIVILEGES];        if (t == null) {            t = createBlankTable(sysTableHsqlNames[SYSTEM_COLUMNPRIVILEGES]);            addColumn(t, "TABLE_CAT", Types.VARCHAR);            addColumn(t, "TABLE_SCHEM", Types.VARCHAR);            addColumn(t, "TABLE_NAME", Types.VARCHAR, false);         // not null            addColumn(t, "COLUMN_NAME", Types.VARCHAR, false);        // not null            addColumn(t, "GRANTOR", Types.VARCHAR, false);            // not null            addColumn(t, "GRANTEE", Types.VARCHAR, false);            // not null            addColumn(t, "PRIVILEGE", Types.VARCHAR, 10, false);      // not null            addColumn(t, "IS_GRANTABLE", Types.VARCHAR, 3, false);    // not null            // order: COLUMN_NAME, PRIVILEGE            // for unique: GRANTEE, GRANTOR, TABLE_NAME, TABLE_SCHEM, TABLE_CAT            // false PK, as TABLE_SCHEM and/or TABLE_CAT may be null            t.createPrimaryKey(null, new int[] {                3, 6, 5, 4, 2, 1, 0            }, false);            return t;        }        Result rs;        // - saves ~ 100 bytes jar space        rs = session.sqlExecuteDirectNoPreChecks(            "select a.TABLE_CAT, a.TABLE_SCHEM, a.TABLE_NAME, b.COLUMN_NAME, "            + "a.GRANTOR, a.GRANTEE, a.PRIVILEGE, a.IS_GRANTABLE "            + "from  INFORMATION_SCHEMA.SYSTEM_TABLEPRIVILEGES a, INFORMATION_SCHEMA.SYSTEM_COLUMNS b where a.TABLE_NAME = b.TABLE_NAME;");        t.insertSys(rs);        t.setDataReadOnly(true);        return t;    }    /**     * Retrieves a <code>Table</code> object describing the     * visible columns of all accessible tables defined     * within this database.<p>     *     * Each row is a column description with the following columns: <p>     *     * <pre class="SqlCodeExample">     * TABLE_CAT         VARCHAR   table catalog     * TABLE_SCHEM       VARCHAR   table schema     * TABLE_NAME        VARCHAR   table name     * COLUMN_NAME       VARCHAR   column name     * DATA_TYPE         SMALLINT  SQL type from DITypes     * TYPE_NAME         VARCHAR   canonical type name     * COLUMN_SIZE       INTEGER   column size (length/precision)     * BUFFER_LENGTH     INTEGER   transfer size in bytes, if definitely known     * DECIMAL_DIGITS    INTEGER   # of fractional digits (scale)     * NUM_PREC_RADIX    INTEGER   Radix     * NULLABLE          INTEGER   is NULL allowed? (from DatabaseMetaData)     * REMARKS           VARCHAR   comment describing column     * COLUMN_DEF        VARCHAR   default value (possibly expression)     * SQL_DATA_TYPE     VARCHAR   type code as expected in the SQL CLI SQLDA     * SQL_DATETIME_SUB  INTEGER   the SQL CLI subtype for DATETIME types     * CHAR_OCTET_LENGTH INTEGER   for char types, max # of bytes in column     * ORDINAL_POSITION  INTEGER   1-based index of column in table     * IS_NULLABLE       VARCHAR   is column nullable? ("YES"|"NO"|""}     * SCOPE_CATLOG      VARCHAR   catalog of REF attribute scope table     * SCOPE_SCHEMA      VARCHAR   schema of REF attribute scope table     * SCOPE_TABLE       VARCHAR   name of REF attribute scope table

⌨️ 快捷键说明

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