Search in sources :

Example 6 with Table

use of org.hsqldb_voltpatches.Table 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 7 with Table

use of org.hsqldb_voltpatches.Table 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)

Example 8 with Table

use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.

the class DatabaseInformationFull method JAR_JAR_USAGE.

Table JAR_JAR_USAGE() {
    Table t = sysTables[JAR_JAR_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[JAR_JAR_USAGE]);
        addColumn(t, "PATH_JAR_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "PATH_JAR_SCHAMA", SQL_IDENTIFIER);
        addColumn(t, "PATH_JAR_NAME", SQL_IDENTIFIER);
        addColumn(t, "JAR_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "JAR_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "JAR_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[JAR_JAR_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
        return t;
    }
    // column number mappings
    final int path_jar_catalog = 0;
    final int path_jar_schema = 1;
    final int path_jar_name = 2;
    final int jar_catalog = 3;
    final int jar_schema = 4;
    final int jar_name = 5;
    //
    Iterator it;
    Object[] row;
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Example 9 with Table

use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.

the class DatabaseInformationFull method COLUMN_UDT_USAGE.

/**
     * UDT's are shown if the authorization is the user or a role given to the
     * user.
     *
     * <p>
     *
     * @return Table
     */
Table COLUMN_UDT_USAGE() {
    Table t = sysTables[COLUMN_UDT_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[COLUMN_UDT_USAGE]);
        addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMN_UDT_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    Result rs = sys.executeDirectStatement("SELECT UDT_CATALOG, UDT_SCHEMA, UDT_NAME, TABLE_CATALOG, " + "TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE UDT_NAME IS NOT NULL;");
    t.insertSys(store, rs);
    sys.close();
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 10 with Table

use of org.hsqldb_voltpatches.Table in project voltdb by VoltDB.

the class DatabaseInformationMain method SYSTEM_PROCEDURECOLUMNS.

/**
     * Retrieves a <code>Table</code> object describing the
     * return, parameter and result columns of the accessible
     * routines defined within this database.<p>
     *
     * Each row is a procedure column description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * PROCEDURE_CAT   VARCHAR   routine catalog
     * PROCEDURE_SCHEM VARCHAR   routine schema
     * PROCEDURE_NAME  VARCHAR   routine name
     * COLUMN_NAME     VARCHAR   column/parameter name
     * COLUMN_TYPE     SMALLINT  kind of column/parameter
     * DATA_TYPE       SMALLINT  SQL type from DITypes
     * TYPE_NAME       VARCHAR   SQL type name
     * PRECISION       INTEGER   precision (length) of type
     * LENGTH          INTEGER   transfer size, in bytes, if definitely known
     *                           (roughly equivalent to BUFFER_SIZE for table
     *                           columns)
     * SCALE           SMALLINT  scale
     * RADIX           SMALLINT  radix
     * NULLABLE        SMALLINT  can column contain NULL?
     * REMARKS         VARCHAR   explanatory comment on column
     * // JDBC 4.0
     * COLUMN_DEF        VARCHAR The default column value.
     *                           The string NULL (not enclosed in quotes)
     *                           - If NULL was specified as the default value
     *                           TRUNCATE (not enclosed in quotes)
     *                           - If the specified default value cannot be
     *                           represented without truncation
     *                           NULL
     *                           - If a default value was not specified
     * SQL_DATA_TYPE     INTEGER CLI type list from SQL 2003 Table 37,
     *                           tables 6-9 Annex A1, and/or addendums in other
     *                           documents, such as:
     *                           SQL 2003 Part 9: Management of External Data (SQL/MED) : DATALINK
     *                           SQL 2003 Part 14: XML-Related Specifications (SQL/XML) : XML
     * SQL_DATETIME_SUB  INTEGER SQL 2003 CLI datetime/interval subcode.
     * CHAR_OCTET_LENGTH INTEGER The maximum length of binary and character
     *                           based columns.  For any other datatype the
     *                           returned value is a NULL
     * ORDINAL_POSITION  INTEGER The ordinal position, starting from 1, for the
     *                           input and output parameters for a procedure.
     *                           A value of 0 is returned if this row describes
     *                           the procedure's return value.
     * IS_NULLABLE       VARCHAR ISO rules are used to determinte the nulliblity
     *                           for a column.
     *
     *                           YES (enclosed in quotes)  --- if the column can include NULLs
     *                           NO  (enclosed in quotes)  --- if the column cannot include NULLs
     *                           empty string              --- if the nullability for the column is unknown
     *
     * SPECIFIC_NAME     VARCHAR The name which uniquely identifies this
     *                           procedure within its schema.
     *                           Typically (but not restricted to) a
     *                           fully qualified Java Method name and
     *                           signature
     * // HSQLDB extension
     * JDBC_SEQ          INTEGER The JDBC-specified order within
     *                           runs of PROCEDURE_SCHEM, PROCEDURE_NAME,
     *                           SPECIFIC_NAME, which is:
     *
     *                           return value (0), if any, first, followed
     *                           by the parameter descriptions in call order
     *                           (1..n1), followed by the result column
     *                           descriptions in column number order
     *                           (n1 + 1..n1 + n2)
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the
     *        return, parameter and result columns
     *        of the accessible routines defined
     *        within this database.
     */
Table SYSTEM_PROCEDURECOLUMNS() {
    Table t = sysTables[SYSTEM_PROCEDURECOLUMNS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_PROCEDURECOLUMNS]);
        // ----------------------------------------------------------------
        // required
        // ----------------------------------------------------------------
        // 0
        addColumn(t, "PROCEDURE_CAT", SQL_IDENTIFIER);
        // 1
        addColumn(t, "PROCEDURE_SCHEM", SQL_IDENTIFIER);
        // not null
        addColumn(t, "PROCEDURE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "COLUMN_TYPE", Type.SQL_SMALLINT);
        // not null
        addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
        // not null
        addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
        // 7
        addColumn(t, "PRECISION", Type.SQL_INTEGER);
        // 8
        addColumn(t, "LENGTH", Type.SQL_INTEGER);
        // 9
        addColumn(t, "SCALE", Type.SQL_SMALLINT);
        // 10
        addColumn(t, "RADIX", Type.SQL_SMALLINT);
        // not null
        addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
        // 12
        addColumn(t, "REMARKS", CHARACTER_DATA);
        // ----------------------------------------------------------------
        // JDBC 4.0
        // ----------------------------------------------------------------
        // 13
        addColumn(t, "COLUMN_DEF", CHARACTER_DATA);
        // 14
        addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
        // 15
        addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
        // 16
        addColumn(t, "CHAR_OCTET_LENGTH", Type.SQL_INTEGER);
        // not null
        addColumn(t, "ORDINAL_POSITION", Type.SQL_INTEGER);
        // not null
        addColumn(t, "IS_NULLABLE", CHARACTER_DATA);
        // not null
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        // ----------------------------------------------------------------
        // just for JDBC sort contract
        // ----------------------------------------------------------------
        // not null
        addColumn(t, "JDBC_SEQ", Type.SQL_INTEGER);
        // ----------------------------------------------------------------
        // order: PROCEDURE_SCHEM, PROCEDURE_NAME, SPECIFIC_NAME, SEQ
        // added for unique: PROCEDURE_CAT
        // false PK, as PROCEDURE_SCHEM and/or PROCEDURE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_PROCEDURECOLUMNS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 1, 2, 19, 20, 0 }, false);
        return t;
    }
    // calculated column values
    String procedureCatalog;
    String procedureSchema;
    String procedureName;
    String columnName;
    Integer columnType;
    Integer dataType;
    String dataTypeName;
    Integer precision;
    Integer length;
    Integer scale;
    Integer radix;
    Integer nullability;
    String remark;
    // JDBC 4.0
    String colDefault;
    Integer sqlDataType;
    Integer sqlDateTimeSub;
    Integer charOctetLength;
    Integer ordinalPosition;
    String isNullable;
    String specificName;
    // extended
    int jdbcSequence;
    // intermediate holders
    int colCount;
    HsqlArrayList aliasList;
    Object[] info;
    Method method;
    Iterator methods;
    Object[] row;
    DITypeInfo ti;
    // Initialization
    // and aliases
    methods = ns.iterateAllAccessibleMethods(session, true);
    ti = new DITypeInfo();
    // no such thing as identity or ignorecase return/parameter
    // procedure columns.  Future: may need to worry about this if
    // result columns are ever reported
    ti.setTypeSub(Types.TYPE_SUB_DEFAULT);
    // JDBC 4.0
    /**
         * @todo we do not yet support declarative p-column defaults.
         * In essence, the default value for a procedure column is NULL
         */
    colDefault = null;
    procedureCatalog = database.getCatalogName().name;
    procedureSchema = database.schemaManager.getDefaultSchemaHsqlName().name;
    // Do it.
    while (methods.hasNext()) {
        info = (Object[]) methods.next();
        method = (Method) info[0];
        aliasList = (HsqlArrayList) info[1];
        pi.setMethod(method);
        specificName = pi.getSpecificName();
        procedureName = pi.getFQN();
        colCount = pi.getColCount();
        for (int i = 0; i < colCount; i++) {
            ti.setTypeCode(pi.getColTypeCode(i));
            columnName = pi.getColName(i);
            columnType = pi.getColUsage(i);
            dataType = pi.getColJDBCDataType(i);
            dataTypeName = ti.getTypeName();
            precision = ti.getPrecision();
            length = pi.getColLen(i);
            scale = ti.getDefaultScale();
            radix = ti.getNumPrecRadix();
            nullability = pi.getColNullability(i);
            remark = pi.getColRemark(i);
            // JDBC 4.0
            //colDefault    = null;
            sqlDataType = ti.getSqlDataType();
            sqlDateTimeSub = ti.getSqlDateTimeSub();
            charOctetLength = ti.getCharOctLen();
            ordinalPosition = pi.getColOrdinalPosition(i);
            isNullable = pi.getColIsNullable(i);
            // extended
            jdbcSequence = pi.getColSequence(i);
            addPColRows(t, aliasList, procedureCatalog, procedureSchema, procedureName, columnName, columnType, dataType, dataTypeName, precision, length, scale, radix, nullability, remark, colDefault, sqlDataType, sqlDateTimeSub, charOctetLength, ordinalPosition, isNullable, specificName, jdbcSequence);
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Method(java.lang.reflect.Method) Constraint(org.hsqldb_voltpatches.Constraint)

Aggregations

Table (org.hsqldb_voltpatches.Table)94 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)86 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)74 TextTable (org.hsqldb_voltpatches.TextTable)65 Constraint (org.hsqldb_voltpatches.Constraint)61 SchemaObject (org.hsqldb_voltpatches.SchemaObject)60 Iterator (org.hsqldb_voltpatches.lib.Iterator)55 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)54 HsqlException (org.hsqldb_voltpatches.HsqlException)20 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)19 Session (org.hsqldb_voltpatches.Session)17 Result (org.hsqldb_voltpatches.result.Result)14 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Type (org.hsqldb_voltpatches.types.Type)9 Grantee (org.hsqldb_voltpatches.rights.Grantee)8 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6