Search in sources :

Example 31 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class DatabaseInformationMain method SYSTEM_TABLETYPES.

/**
     * Retrieves a <code>Table</code> object describing the table types
     * available in this database. <p>
     *
     * In general, the range of values that may be commonly encounted across
     * most DBMS implementations is: <p>
     *
     * <UL>
     *   <LI><FONT color='#FF00FF'>"TABLE"</FONT>
     *   <LI><FONT color='#FF00FF'>"VIEW"</FONT>
     *   <LI><FONT color='#FF00FF'>"SYSTEM TABLE"</FONT>
     *   <LI><FONT color='#FF00FF'>"GLOBAL TEMPORARY"</FONT>
     *   <LI><FONT color='#FF00FF'>"LOCAL TEMPORARY"</FONT>
     *   <LI><FONT color='#FF00FF'>"ALIAS"</FONT>
     *   <LI><FONT color='#FF00FF'>"SYNONYM"</FONT>
     * </UL> <p>
     *
     * As of HSQLDB 1.7.2, the engine supports and thus this method reports
     * only a subset of the range above: <p>
     *
     * <UL>
     *   <LI><FONT color='#FF00FF'>"TABLE"</FONT>
     *    (HSQLDB MEMORY, CACHED and TEXT tables)
     *   <LI><FONT color='#FF00FF'>"VIEW"</FONT>  (Views)
     *   <LI><FONT color='#FF00FF'>"SYSTEM TABLE"</FONT>
     *    (The tables generated by this object)
     *   <LI><FONT color='#FF00FF'>"GLOBAL TEMPORARY"</FONT>
     *    (HSQLDB TEMP and TEMP TEXT tables)
     * </UL> <p>
     *
     * @return a <code>Table</code> object describing the table types
     *        available in this database
     */
Table SYSTEM_TABLETYPES() {
    Table t = sysTables[SYSTEM_TABLETYPES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_TABLETYPES]);
        // not null
        addColumn(t, "TABLE_TYPE", SQL_IDENTIFIER);
        // order: TABLE_TYPE
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_TABLETYPES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Object[] row;
    for (int i = 0; i < tableTypes.length; i++) {
        row = t.getEmptyRowData();
        row[0] = tableTypes[i];
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Example 32 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class DatabaseInformationMain method SYSTEM_PRIMARYKEYS.

/**
     * Retrieves a <code>Table</code> object describing the visible
     * primary key columns of each accessible table defined within
     * this database. <p>
     *
     * Each row is a PRIMARY KEY 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
     * KEY_SEQ     SMALLINT  sequence number within primary key
     * PK_NAME     VARCHAR   primary key constraint name
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the visible
     *        primary key columns of each accessible table
     *        defined within this database.
     */
final Table SYSTEM_PRIMARYKEYS() {
    Table t = sysTables[SYSTEM_PRIMARYKEYS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_PRIMARYKEYS]);
        addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "KEY_SEQ", Type.SQL_SMALLINT);
        addColumn(t, "PK_NAME", SQL_IDENTIFIER);
        // order: COLUMN_NAME
        // added for unique: TABLE_NAME, TABLE_SCHEM, TABLE_CAT
        // false PK, as  TABLE_SCHEM and/or TABLE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_PRIMARYKEYS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 3, 2, 1, 0 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    String tableCatalog;
    String tableSchema;
    String tableName;
    //String  columnName;
    //Integer keySequence;
    String primaryKeyName;
    // Intermediate holders
    Iterator tables;
    Table table;
    Object[] row;
    Constraint constraint;
    int[] cols;
    int colCount;
    HsqlProperties p;
    // column number mappings
    final int itable_cat = 0;
    final int itable_schem = 1;
    final int itable_name = 2;
    final int icolumn_name = 3;
    final int ikey_seq = 4;
    final int ipk_name = 5;
    // Initialization
    p = database.getProperties();
    tables = p.isPropertyTrue("hsqldb.system_table_primarykeys") ? allTables() : database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (table.isView() || !isAccessibleTable(table) || !table.hasPrimaryKey()) {
            continue;
        }
        constraint = table.getPrimaryConstraint();
        tableCatalog = table.getCatalogName().name;
        tableSchema = table.getSchemaName().name;
        tableName = table.getName().name;
        primaryKeyName = constraint.getName().name;
        cols = constraint.getMainColumns();
        colCount = cols.length;
        for (int j = 0; j < colCount; j++) {
            row = t.getEmptyRowData();
            row[itable_cat] = tableCatalog;
            row[itable_schem] = tableSchema;
            row[itable_name] = tableName;
            row[icolumn_name] = table.getColumn(cols[j]).getName().name;
            row[ikey_seq] = ValuePool.getInt(j + 1);
            row[ipk_name] = primaryKeyName;
            t.insertSys(store, row);
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) Constraint(org.hsqldb_voltpatches.Constraint) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) HsqlProperties(org.hsqldb_voltpatches.persist.HsqlProperties) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Example 33 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class DatabaseInformationMain method SYSTEM_ALLTYPEINFO.

/**
     * Retrieves a <code>Table</code> object describing, in an extended
     * fashion, all of the system or formal specification SQL types known to
     * this database, including its level of support for them (which may
     * be no support at all) in various capacities. <p>
     *
     * <pre class="SqlCodeExample">
     * TYPE_NAME          VARCHAR   the canonical name used in DDL statements.
     * DATA_TYPE          SMALLINT  data type code from Types
     * PRECISION          INTEGER   max column size.
     *                              number => max. precision.
     *                              character => max characters.
     *                              datetime => max chars incl. frac. component.
     * LITERAL_PREFIX     VARCHAR   char(s) prefixing literal of this type.
     * LITERAL_SUFFIX     VARCHAR   char(s) terminating literal of this type.
     * CREATE_PARAMS      VARCHAR   Localized syntax-order list of domain
     *                              create parameter keywords.
     *                              - for human consumption only
     * NULLABLE           SMALLINT  { No Nulls | Nullable | Unknown }
     * CASE_SENSITIVE     BOOLEAN   case-sensitive in collations/comparisons?
     * SEARCHABLE         SMALLINT  { None | Char (Only WHERE .. LIKE) |
     *                                Basic (Except WHERE .. LIKE) |
     *                                Searchable (All forms) }
     * UNSIGNED_ATTRIBUTE BOOLEAN   { TRUE  (unsigned) | FALSE (signed) |
     *                                NULL (non-numeric or not applicable) }
     * FIXED_PREC_SCALE   BOOLEAN   { TRUE (fixed) | FALSE (variable) |
     *                                NULL (non-numeric or not applicable) }
     * AUTO_INCREMENT     BOOLEAN   automatic unique value generated for
     *                              inserts and updates when no value or
     *                              NULL specified?
     * LOCAL_TYPE_NAME    VARCHAR   Localized name of data type;
     *                              - NULL => not supported (no resource avail).
     *                              - for human consumption only
     * MINIMUM_SCALE      SMALLINT  minimum scale supported.
     * MAXIMUM_SCALE      SMALLINT  maximum scale supported.
     * SQL_DATA_TYPE      INTEGER   value expected in SQL CLI SQL_DESC_TYPE
     *                              field of the SQLDA.
     * SQL_DATETIME_SUB   INTEGER   SQL CLI datetime/interval subcode
     * NUM_PREC_RADIX     INTEGER   numeric base w.r.t # of digits reported
     *                              in PRECISION column (typically 10)
     * INTERVAL_PRECISION INTEGER   interval leading precision (not implemented)
     * AS_TAB_COL         BOOLEAN   type supported as table column?
     * AS_PROC_COL        BOOLEAN   type supported as procedure column?
     * MAX_PREC_ACT       BIGINT    like PRECISION unless value would be
     *                              truncated using INTEGER
     * MIN_SCALE_ACT      INTEGER   like MINIMUM_SCALE unless value would be
     *                              truncated using SMALLINT
     * MAX_SCALE_ACT      INTEGER   like MAXIMUM_SCALE unless value would be
     *                              truncated using SMALLINT
     * COL_ST_CLS_NAME    VARCHAR   Java Class FQN of in-memory representation
     * COL_ST_IS_SUP      BOOLEAN   is COL_ST_CLS_NAME supported under the
     *                              hosting JVM and engine build option?
     * STD_MAP_CLS_NAME   VARCHAR   Java class FQN of standard JDBC mapping
     * STD_MAP_IS_SUP     BOOLEAN   Is STD_MAP_CLS_NAME supported under the
     *                              hosting JVM?
     * CST_MAP_CLS_NAME   VARCHAR   Java class FQN of HSQLDB-provided JDBC
     *                              interface representation
     * CST_MAP_IS_SUP     BOOLEAN   is CST_MAP_CLS_NAME supported under the
     *                              hosting JVM and engine build option?
     * MCOL_JDBC          INTEGER   maximum character octet length representable
     *                              via JDBC interface
     * MCOL_ACT           BIGINT    like MCOL_JDBC unless value would be
     *                              truncated using INTEGER
     * DEF_OR_FIXED_SCALE INTEGER   default or fixed scale for numeric types
     * REMARKS            VARCHAR   localized comment on the data type
     * TYPE_SUB           INTEGER   From Types:
     *                              {TYPE_SUB_DEFAULT | TYPE_SUB_IGNORECASE}
     *                              deprecated: TYPE_SUB_IDENTITY
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing all of the
     *        standard SQL types known to this database
     */
final Table SYSTEM_ALLTYPEINFO() {
    Table t = sysTables[SYSTEM_ALLTYPEINFO];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_ALLTYPEINFO]);
        //-------------------------------------------
        // same as SYSTEM_TYPEINFO:
        // ------------------------------------------
        addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
        addColumn(t, "PRECISION", Type.SQL_INTEGER);
        addColumn(t, "LITERAL_PREFIX", CHARACTER_DATA);
        addColumn(t, "LITERAL_SUFFIX", CHARACTER_DATA);
        addColumn(t, "CREATE_PARAMS", CHARACTER_DATA);
        addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
        addColumn(t, "CASE_SENSITIVE", Type.SQL_BOOLEAN);
        addColumn(t, "SEARCHABLE", Type.SQL_SMALLINT);
        addColumn(t, "UNSIGNED_ATTRIBUTE", Type.SQL_BOOLEAN);
        addColumn(t, "FIXED_PREC_SCALE", Type.SQL_BOOLEAN);
        addColumn(t, "AUTO_INCREMENT", Type.SQL_BOOLEAN);
        addColumn(t, "LOCAL_TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "MINIMUM_SCALE", Type.SQL_SMALLINT);
        addColumn(t, "MAXIMUM_SCALE", Type.SQL_SMALLINT);
        addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
        addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
        addColumn(t, "NUM_PREC_RADIX", Type.SQL_INTEGER);
        //-------------------------------------------
        // SQL CLI / ODBC - not in JDBC spec
        // ------------------------------------------
        addColumn(t, "INTERVAL_PRECISION", Type.SQL_INTEGER);
        //-------------------------------------------
        // extended:
        //-------------------------------------------
        // level of support
        //-------------------------------------------
        addColumn(t, "AS_TAB_COL", Type.SQL_BOOLEAN);
        // for instance, some executable methods take Connection
        // or return non-serializable Object such as ResultSet, neither
        // of which maps to a supported table column type but which
        // we show as JAVA_OBJECT in SYSTEM_PROCEDURECOLUMNS.
        // Also, triggers take Object[] row, which we show as ARRAY
        // presently, although STRUCT would probably be better in the
        // future, as the row can actually contain mixed data types.
        addColumn(t, "AS_PROC_COL", Type.SQL_BOOLEAN);
        //-------------------------------------------
        // actual values for attributes that cannot be represented
        // within the limitations of the SQL CLI / JDBC interface
        //-------------------------------------------
        addColumn(t, "MAX_PREC_ACT", Type.SQL_BIGINT);
        addColumn(t, "MIN_SCALE_ACT", Type.SQL_INTEGER);
        addColumn(t, "MAX_SCALE_ACT", Type.SQL_INTEGER);
        //-------------------------------------------
        // how do we store this internally as a column value?
        //-------------------------------------------
        addColumn(t, "COL_ST_CLS_NAME", SQL_IDENTIFIER);
        addColumn(t, "COL_ST_IS_SUP", Type.SQL_BOOLEAN);
        //-------------------------------------------
        // what is the standard Java mapping for the type?
        //-------------------------------------------
        addColumn(t, "STD_MAP_CLS_NAME", SQL_IDENTIFIER);
        addColumn(t, "STD_MAP_IS_SUP", Type.SQL_BOOLEAN);
        //-------------------------------------------
        // what, if any, custom mapping do we provide?
        // (under the current build options and hosting VM)
        //-------------------------------------------
        addColumn(t, "CST_MAP_CLS_NAME", SQL_IDENTIFIER);
        addColumn(t, "CST_MAP_IS_SUP", Type.SQL_BOOLEAN);
        //-------------------------------------------
        // what is the max representable and actual
        // character octet length, if applicable?
        //-------------------------------------------
        addColumn(t, "MCOL_JDBC", Type.SQL_INTEGER);
        addColumn(t, "MCOL_ACT", Type.SQL_BIGINT);
        //-------------------------------------------
        // what is the default or fixed scale, if applicable?
        //-------------------------------------------
        addColumn(t, "DEF_OR_FIXED_SCALE", Type.SQL_INTEGER);
        //-------------------------------------------
        // Any type-specific, localized remarks can go here
        //-------------------------------------------
        addColumn(t, "REMARKS", CHARACTER_DATA);
        //-------------------------------------------
        // required for JDBC sort contract:
        //-------------------------------------------
        addColumn(t, "TYPE_SUB", Type.SQL_INTEGER);
        // order:  DATA_TYPE, TYPE_SUB
        // true primary key
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_ALLTYPEINFO].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 1, 34 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Object[] row;
    int type;
    DITypeInfo ti;
    //-----------------------------------------
    // Same as SYSTEM_TYPEINFO
    //-----------------------------------------
    final int itype_name = 0;
    final int idata_type = 1;
    final int iprecision = 2;
    final int iliteral_prefix = 3;
    final int iliteral_suffix = 4;
    final int icreate_params = 5;
    final int inullable = 6;
    final int icase_sensitive = 7;
    final int isearchable = 8;
    final int iunsigned_attribute = 9;
    final int ifixed_prec_scale = 10;
    final int iauto_increment = 11;
    final int ilocal_type_name = 12;
    final int iminimum_scale = 13;
    final int imaximum_scale = 14;
    final int isql_data_type = 15;
    final int isql_datetime_sub = 16;
    final int inum_prec_radix = 17;
    //------------------------------------------
    // Extensions
    //------------------------------------------
    // not in JDBC, but in SQL CLI SQLDA / ODBC
    //------------------------------------------
    final int iinterval_precision = 18;
    //------------------------------------------
    // HSQLDB/Java-specific:
    //------------------------------------------
    final int iis_sup_as_tcol = 19;
    final int iis_sup_as_pcol = 20;
    //------------------------------------------
    final int imax_prec_or_len_act = 21;
    final int imin_scale_actual = 22;
    final int imax_scale_actual = 23;
    //------------------------------------------
    final int ics_cls_name = 24;
    final int ics_cls_is_supported = 25;
    //------------------------------------------
    final int ism_cls_name = 26;
    final int ism_cls_is_supported = 27;
    //------------------------------------------
    final int icm_cls_name = 28;
    final int icm_cls_is_supported = 29;
    //------------------------------------------
    final int imax_char_oct_len_jdbc = 30;
    final int imax_char_oct_len_act = 31;
    //------------------------------------------
    final int idef_or_fixed_scale = 32;
    //------------------------------------------
    final int iremarks = 33;
    //------------------------------------------
    final int itype_sub = 34;
    ti = new DITypeInfo();
    for (int i = 0; i < Types.ALL_TYPES.length; i++) {
        ti.setTypeCode(Types.ALL_TYPES[i][0]);
        ti.setTypeSub(Types.ALL_TYPES[i][1]);
        row = t.getEmptyRowData();
        row[itype_name] = ti.getTypeName();
        row[idata_type] = ti.getDataType();
        row[iprecision] = ti.getPrecision();
        row[iliteral_prefix] = ti.getLiteralPrefix();
        row[iliteral_suffix] = ti.getLiteralSuffix();
        row[icreate_params] = ti.getCreateParams();
        row[inullable] = ti.getNullability();
        row[icase_sensitive] = ti.isCaseSensitive();
        row[isearchable] = ti.getSearchability();
        row[iunsigned_attribute] = ti.isUnsignedAttribute();
        row[ifixed_prec_scale] = ti.isFixedPrecisionScale();
        row[iauto_increment] = ti.isAutoIncrement();
        row[ilocal_type_name] = ti.getLocalName();
        row[iminimum_scale] = ti.getMinScale();
        row[imaximum_scale] = ti.getMaxScale();
        row[isql_data_type] = ti.getSqlDataType();
        row[isql_datetime_sub] = ti.getSqlDateTimeSub();
        row[inum_prec_radix] = ti.getNumPrecRadix();
        //------------------------------------------
        row[iinterval_precision] = ti.getIntervalPrecision();
        //------------------------------------------
        row[iis_sup_as_tcol] = ti.isSupportedAsTCol();
        row[iis_sup_as_pcol] = ti.isSupportedAsPCol();
        //------------------------------------------
        row[imax_prec_or_len_act] = ti.getPrecisionAct();
        row[imin_scale_actual] = ti.getMinScaleAct();
        row[imax_scale_actual] = ti.getMaxScaleAct();
        //------------------------------------------
        row[ics_cls_name] = ti.getColStClsName();
        row[ics_cls_is_supported] = ti.isColStClsSupported();
        //------------------------------------------
        row[ism_cls_name] = ti.getStdMapClsName();
        row[ism_cls_is_supported] = ti.isStdMapClsSupported();
        //------------------------------------------
        row[icm_cls_name] = ti.getCstMapClsName();
        try {
            if (row[icm_cls_name] != null) {
                ns.classForName((String) row[icm_cls_name]);
                row[icm_cls_is_supported] = Boolean.TRUE;
            }
        } catch (Exception e) {
            row[icm_cls_is_supported] = Boolean.FALSE;
        }
        //------------------------------------------
        row[imax_char_oct_len_jdbc] = ti.getCharOctLen();
        row[imax_char_oct_len_act] = ti.getCharOctLenAct();
        //------------------------------------------
        row[idef_or_fixed_scale] = ti.getDefaultScale();
        //------------------------------------------
        row[iremarks] = ti.getRemarks();
        //------------------------------------------
        row[itype_sub] = ti.getDataTypeSub();
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 34 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class DatabaseInformationMain method getSystemTable.

/**
     * Retrieves the system <code>Table</code> object corresponding to
     * the given <code>name</code> and <code>session</code> arguments. <p>
     *
     * @param session the Session object requesting the table
     * @param name a String identifying the desired table
     *      database access error occurs
     * @return a system table corresponding to the <code>name</code> and
     *      <code>session</code> arguments
     */
public final Table getSystemTable(Session session, String name) {
    Table t;
    int tableIndex;
    // must come first...many methods depend on this being set properly
    this.session = session;
    if (!isSystemTable(name)) {
        return null;
    }
    tableIndex = getSysTableID(name);
    t = sysTables[tableIndex];
    // fredt - any system table that is not supported will be null here
    if (t == null) {
        return t;
    }
    // open phase under such cases.
    if (!withContent) {
        return t;
    }
    if (isDirty) {
        cacheClear();
    }
    HsqlName oldUser = sysTableSessions[tableIndex];
    boolean tableValid = oldUser != null;
    // user has changed and table is user-dependent
    if (session.getGrantee().getName() != oldUser && sysTableSessionDependent[tableIndex]) {
        tableValid = false;
    }
    if (nonCachedTablesSet.contains(name)) {
        tableValid = false;
    }
    // any valid cached table will be returned here
    if (tableValid) {
        return t;
    }
    // fredt - clear the contents of table and set new User
    t.clearAllData(session);
    sysTableSessions[tableIndex] = session.getGrantee().getName();
    // match and if found, generate.
    t = generateTable(tableIndex);
    // send back what we found or generated
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Constraint(org.hsqldb_voltpatches.Constraint)

Example 35 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class DatabaseInformationFull method SYSTEM_CACHEINFO.

/**
     * Retrieves a <code>Table</code> object describing the current
     * state of all row caching objects for the accessible
     * tables defined within this database. <p>
     *
     * Currently, the row caching objects for which state is reported are: <p>
     *
     * <OL>
     * <LI> the system-wide <code>Cache</code> object used by CACHED tables.
     * <LI> any <code>TextCache</code> objects in use by [TEMP] TEXT tables.
     * </OL> <p>
     *
     * Each row is a cache object state description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * CACHE_FILE          CHARACTER_DATA   absolute path of cache data file
     * MAX_CACHE_SIZE      INTEGER   maximum allowable cached Row objects
     * MAX_CACHE_BYTE_SIZE INTEGER   maximum allowable size of cached Row objects
     * CACHE_LENGTH        INTEGER   number of data bytes currently cached
     * CACHE_SIZE          INTEGER   number of rows currently cached
     * FREE_BYTES          INTEGER   total bytes in available file allocation units
     * FREE_COUNT          INTEGER   total # of allocation units available
     * FREE_POS            INTEGER   largest file position allocated + 1
     * </pre> <p>
     *
     * <b>Notes:</b> <p>
     *
     * <code>TextCache</code> objects do not maintain a free list because
     * deleted rows are only marked deleted and never reused. As such, the
     * columns FREE_BYTES, SMALLEST_FREE_ITEM, LARGEST_FREE_ITEM, and
     * FREE_COUNT are always reported as zero for rows reporting on
     * <code>TextCache</code> objects. <p>
     *
     * Currently, CACHE_SIZE, FREE_BYTES, SMALLEST_FREE_ITEM, LARGEST_FREE_ITEM,
     * FREE_COUNT and FREE_POS are the only dynamically changing values.
     * All others are constant for the life of a cache object. In a future
     * release, other column values may also change over the life of a cache
     * object, as SQL syntax may eventually be introduced to allow runtime
     * modification of certain cache properties. <p>
     *
     * @return a description of the current state of all row caching
     *      objects associated with the accessible tables of the database
     */
Table SYSTEM_CACHEINFO() {
    Table t = sysTables[SYSTEM_CACHEINFO];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_CACHEINFO]);
        // not null
        addColumn(t, "CACHE_FILE", CHARACTER_DATA);
        // not null
        addColumn(t, "MAX_CACHE_COUNT", CARDINAL_NUMBER);
        // not null
        addColumn(t, "MAX_CACHE_BYTES", CARDINAL_NUMBER);
        // not null
        addColumn(t, "CACHE_SIZE", CARDINAL_NUMBER);
        // not null
        addColumn(t, "CACHE_BYTES", CARDINAL_NUMBER);
        // not null
        addColumn(t, "FILE_FREE_BYTES", CARDINAL_NUMBER);
        // not null
        addColumn(t, "FILE_FREE_COUNT", CARDINAL_NUMBER);
        // not null
        addColumn(t, "FILE_FREE_POS", CARDINAL_NUMBER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_CACHEINFO].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    // column number mappings
    final int icache_file = 0;
    final int imax_cache_sz = 1;
    final int imax_cache_bytes = 2;
    final int icache_size = 3;
    final int icache_length = 4;
    final int ifree_bytes = 5;
    final int ifree_count = 6;
    final int ifree_pos = 7;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    DataFileCache cache = null;
    Object[] row;
    HashSet cacheSet;
    Iterator caches;
    Iterator tables;
    Table table;
    int iFreeBytes;
    int iLargestFreeItem;
    long lSmallestFreeItem;
    // Initialization
    cacheSet = new HashSet();
    // dynamic system tables are never cached
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    while (tables.hasNext()) {
        table = (Table) tables.next();
        PersistentStore currentStore = database.persistentStoreCollection.getStore(t);
        if (session.getGrantee().isFullyAccessibleByRole(table)) {
            if (currentStore != null) {
                cache = currentStore.getCache();
            }
            if (cache != null) {
                cacheSet.add(cache);
            }
        }
    }
    caches = cacheSet.iterator();
    // Do it.
    while (caches.hasNext()) {
        cache = (DataFileCache) caches.next();
        row = t.getEmptyRowData();
        row[icache_file] = FileUtil.getDefaultInstance().canonicalOrAbsolutePath(cache.getFileName());
        row[imax_cache_sz] = ValuePool.getInt(cache.capacity());
        row[imax_cache_bytes] = ValuePool.getLong(cache.bytesCapacity());
        row[icache_size] = ValuePool.getInt(cache.getCachedObjectCount());
        row[icache_length] = ValuePool.getLong(cache.getTotalCachedBlockSize());
        row[ifree_bytes] = ValuePool.getInt(cache.getTotalFreeBlockSize());
        row[ifree_count] = ValuePool.getInt(cache.getFreeBlockCount());
        row[ifree_pos] = ValuePool.getLong(cache.getFileFreePos());
        t.insertSys(store, row);
    }
    return t;
}
Also used : DataFileCache(org.hsqldb_voltpatches.persist.DataFileCache) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint) HashSet(org.hsqldb_voltpatches.lib.HashSet) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Aggregations

HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)204 Table (org.hsqldb_voltpatches.Table)86 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)73 TextTable (org.hsqldb_voltpatches.TextTable)65 Iterator (org.hsqldb_voltpatches.lib.Iterator)64 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)61 SchemaObject (org.hsqldb_voltpatches.SchemaObject)60 Constraint (org.hsqldb_voltpatches.Constraint)59 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)48 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)22 HsqlException (org.hsqldb_voltpatches.HsqlException)20 Type (org.hsqldb_voltpatches.types.Type)20 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)15 Grantee (org.hsqldb_voltpatches.rights.Grantee)12 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 Index (org.hsqldb_voltpatches.index.Index)6