Search in sources :

Example 11 with Iterator

use of org.hsqldb_voltpatches.lib.Iterator in project voltdb by VoltDB.

the class DatabaseInformationMain method TABLES.

Table TABLES() {
    Table t = sysTables[TABLES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[TABLES]);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        addColumn(t, "TABLE_TYPE", CHARACTER_DATA);
        addColumn(t, "SELF_REFERENCING_COLUMN_NAME", SQL_IDENTIFIER);
        addColumn(t, "REFERENCE_GENERATION", CHARACTER_DATA);
        addColumn(t, "USER_DEFINED_TYPE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "USER_DEFINED_TYPE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "USER_DEFINED_TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "IS_INSERTABLE_INTO", YES_OR_NO);
        addColumn(t, "IS_TYPED", YES_OR_NO);
        addColumn(t, "COMMIT_ACTION", CHARACTER_DATA);
        //
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[TABLES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // intermediate holders
    Iterator tables;
    Table table;
    Object[] row;
    final int table_catalog = 0;
    final int table_schema = 1;
    final int table_name = 2;
    final int table_type = 3;
    final int self_referencing_column_name = 4;
    final int reference_generation = 5;
    final int user_defined_type_catalog = 6;
    final int user_defined_type_schema = 7;
    final int user_defined_type_name = 8;
    final int is_insertable_into = 9;
    final int is_typed = 10;
    final int commit_action = 11;
    // Initialization
    tables = allTables();
    // Do it.
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (!isAccessibleTable(table)) {
            continue;
        }
        row = t.getEmptyRowData();
        row[table_catalog] = database.getCatalogName().name;
        row[table_schema] = table.getSchemaName().name;
        row[table_name] = table.getName().name;
        switch(table.getTableType()) {
            case TableBase.SYSTEM_TABLE:
            case TableBase.VIEW_TABLE:
                row[table_type] = "VIEW";
                row[is_insertable_into] = "NO";
                break;
            case TableBase.TEMP_TABLE:
            case TableBase.TEMP_TEXT_TABLE:
                row[table_type] = "GLOBAL TEMPORARY";
                row[is_insertable_into] = "YES";
                break;
            default:
                row[table_type] = "BASE TABLE";
                row[is_insertable_into] = table.isWritable() ? "YES" : "NO";
                break;
        }
        row[self_referencing_column_name] = null;
        row[reference_generation] = null;
        row[user_defined_type_catalog] = null;
        row[user_defined_type_schema] = null;
        row[user_defined_type_name] = null;
        row[is_typed] = "NO";
        row[commit_action] = table.isTemp() ? (table.onCommitPreserve() ? "PRESERVE" : "DELETE") : null;
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) 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)

Example 12 with Iterator

use of org.hsqldb_voltpatches.lib.Iterator in project voltdb by VoltDB.

the class DatabaseInformationMain method SYSTEM_INDEXINFO.

/**
     * Retrieves a <code>Table</code> object describing the visible
     * <code>Index</code> objects for each accessible table defined
     * within this database.<p>
     *
     * Each row is an index column description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * TABLE_CAT        VARCHAR   table's catalog
     * TABLE_SCHEM      VARCHAR   simple name of table's schema
     * TABLE_NAME       VARCHAR   simple name of the table using the index
     * NON_UNIQUE       BOOLEAN   can index values be non-unique?
     * INDEX_QUALIFIER  VARCHAR   catalog in which the index is defined
     * INDEX_NAME       VARCHAR   simple name of the index
     * TYPE             SMALLINT  index type: { Clustered | Hashed | Other }
     * ORDINAL_POSITION SMALLINT  column sequence number within index
     * COLUMN_NAME      VARCHAR   simple column name
     * ASC_OR_DESC      VARCHAR   col. sort sequence: {"A" (Asc) | "D" (Desc)}
     * CARDINALITY      INTEGER   # of unique values in index (not implemented)
     * PAGES            INTEGER   index page use (not implemented)
     * FILTER_CONDITION VARCHAR   filter condition, if any (not implemented)
     * // HSQLDB-extension
     * ROW_CARDINALITY  INTEGER   total # of rows in index (not implemented)
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the visible
     *        <code>Index</code> objects for each accessible
     *        table defined within this database.
     */
final Table SYSTEM_INDEXINFO() {
    Table t = sysTables[SYSTEM_INDEXINFO];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_INDEXINFO]);
        // JDBC
        addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
        // NOT NULL
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // NOT NULL
        addColumn(t, "NON_UNIQUE", Type.SQL_BOOLEAN);
        addColumn(t, "INDEX_QUALIFIER", SQL_IDENTIFIER);
        addColumn(t, "INDEX_NAME", SQL_IDENTIFIER);
        // NOT NULL
        addColumn(t, "TYPE", Type.SQL_SMALLINT);
        // NOT NULL
        addColumn(t, "ORDINAL_POSITION", Type.SQL_SMALLINT);
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        addColumn(t, "ASC_OR_DESC", CHARACTER_DATA);
        addColumn(t, "CARDINALITY", Type.SQL_INTEGER);
        addColumn(t, "PAGES", Type.SQL_INTEGER);
        addColumn(t, "FILTER_CONDITION", CHARACTER_DATA);
        // HSQLDB extension
        addColumn(t, "ROW_CARDINALITY", Type.SQL_INTEGER);
        // order: NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION.
        // added for unique: INDEX_QUALIFIER, TABLE_NAME
        // false PK, as INDEX_QUALIFIER may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_INDEXINFO].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 3, 6, 5, 7, 4, 2, 1 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    String tableCatalog;
    String tableSchema;
    String tableName;
    Boolean nonUnique;
    String indexQualifier;
    String indexName;
    Integer indexType;
    //Integer ordinalPosition;
    //String  columnName;
    //String  ascOrDesc;
    Integer cardinality;
    Integer pages;
    String filterCondition;
    Integer rowCardinality;
    // Intermediate holders
    Iterator tables;
    Table table;
    int indexCount;
    int[] cols;
    int col;
    int colCount;
    Object[] row;
    DITableInfo ti;
    HsqlProperties p;
    // column number mappings
    final int itable_cat = 0;
    final int itable_schem = 1;
    final int itable_name = 2;
    final int inon_unique = 3;
    final int iindex_qualifier = 4;
    final int iindex_name = 5;
    final int itype = 6;
    final int iordinal_position = 7;
    final int icolumn_name = 8;
    final int iasc_or_desc = 9;
    final int icardinality = 10;
    final int ipages = 11;
    final int ifilter_condition = 12;
    final int irow_cardinality = 13;
    // Initialization
    ti = new DITableInfo();
    p = database.getProperties();
    tables = p.isPropertyTrue("hsqldb.system_table_indexinfo") ? allTables() : database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    // Do it.
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (table.isView() || !isAccessibleTable(table)) {
            continue;
        }
        ti.setTable(table);
        tableCatalog = table.getCatalogName().name;
        tableSchema = table.getSchemaName().name;
        tableName = ti.getName();
        // not supported yet
        filterCondition = null;
        // different cat for index not supported yet
        indexQualifier = tableCatalog;
        indexCount = table.getIndexCount();
        // process all of the visible indices for this table
        for (int i = 0; i < indexCount; i++) {
            colCount = ti.getIndexVisibleColumns(i);
            if (colCount < 1) {
                continue;
            }
            indexName = ti.getIndexName(i);
            nonUnique = ti.isIndexNonUnique(i);
            cardinality = ti.getIndexCardinality(i);
            pages = ValuePool.INTEGER_0;
            rowCardinality = ti.getIndexRowCardinality(i);
            cols = ti.getIndexColumns(i);
            indexType = ti.getIndexType(i);
            for (int k = 0; k < colCount; k++) {
                col = cols[k];
                row = t.getEmptyRowData();
                row[itable_cat] = tableCatalog;
                row[itable_schem] = tableSchema;
                row[itable_name] = tableName;
                row[inon_unique] = nonUnique;
                row[iindex_qualifier] = indexQualifier;
                row[iindex_name] = indexName;
                row[itype] = indexType;
                row[iordinal_position] = ValuePool.getInt(k + 1);
                row[icolumn_name] = ti.getColName(col);
                row[iasc_or_desc] = ti.getIndexColDirection(i, col);
                row[icardinality] = cardinality;
                row[ipages] = pages;
                row[irow_cardinality] = rowCardinality;
                row[ifilter_condition] = filterCondition;
                t.insertSys(store, row);
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Constraint(org.hsqldb_voltpatches.Constraint) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) HsqlProperties(org.hsqldb_voltpatches.persist.HsqlProperties) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject)

Example 13 with Iterator

use of org.hsqldb_voltpatches.lib.Iterator in project voltdb by VoltDB.

the class DatabaseInformationFull method ENABLED_ROLES.

/**
     * ENABLED_ROLES<p>
     *
     * <b>Function</b><p>
     *
     * Identify the enabled roles for the current SQL-session.<p>
     *
     * Definition<p>
     *
     * <pre class="SqlCodeExample">
     * CREATE RECURSIVE VIEW ENABLED_ROLES ( ROLE_NAME ) AS
     *      VALUES ( CURRENT_ROLE )
     *      UNION
     *      SELECT RAD.ROLE_NAME
     *        FROM DEFINITION_SCHEMA.ROLE_AUTHORIZATION_DESCRIPTORS RAD
     *        JOIN ENABLED_ROLES R
     *          ON RAD.GRANTEE = R.ROLE_NAME;
     *
     * GRANT SELECT ON TABLE ENABLED_ROLES
     *    TO PUBLIC WITH GRANT OPTION;
     * </pre>
     */
Table ENABLED_ROLES() {
    Table t = sysTables[ENABLED_ROLES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ENABLED_ROLES]);
        addColumn(t, "ROLE_NAME", SQL_IDENTIFIER);
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ENABLED_ROLES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // Intermediate holders
    Iterator grantees;
    Grantee grantee;
    Object[] row;
    // initialization
    grantees = session.getGrantee().getAllRoles().iterator();
    while (grantees.hasNext()) {
        grantee = (Grantee) grantees.next();
        row = t.getEmptyRowData();
        row[0] = grantee.getNameString();
        t.insertSys(store, row);
    }
    return t;
}
Also used : Grantee(org.hsqldb_voltpatches.rights.Grantee) 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)

Example 14 with Iterator

use of org.hsqldb_voltpatches.lib.Iterator in project voltdb by VoltDB.

the class Grantee method addToFullRights.

/**
     * Full or partial rights are added to existing
     */
void addToFullRights(MultiValueHashMap map) {
    Iterator it = map.keySet().iterator();
    while (it.hasNext()) {
        Object key = it.next();
        Iterator values = map.get(key);
        Right existing = (Right) fullRightsMap.get(key);
        while (values.hasNext()) {
            Right add = (Right) values.next();
            if (existing == null) {
                existing = add.duplicate();
                fullRightsMap.put(key, existing);
            } else {
                existing.add(add);
            }
            if (add.grantableRights == null) {
                continue;
            }
            if (existing.grantableRights == null) {
                existing.grantableRights = add.grantableRights.duplicate();
            } else {
                existing.grantableRights.add(add.grantableRights);
            }
        }
    }
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) SchemaObject(org.hsqldb_voltpatches.SchemaObject)

Example 15 with Iterator

use of org.hsqldb_voltpatches.lib.Iterator in project voltdb by VoltDB.

the class Grantee method visibleGrantees.

/**
     * Iteration of all visible grantees, including self. <p>
     *
     * For grantees with admin, this is all grantees.
     * For regular grantees, this is self plus all roles granted directly
     * or indirectly
     */
public Set visibleGrantees() {
    HashSet grantees = new HashSet();
    GranteeManager gm = granteeManager;
    if (isAdmin()) {
        grantees.addAll(gm.getGrantees());
    } else {
        grantees.add(this);
        Iterator it = getAllRoles().iterator();
        while (it.hasNext()) {
            grantees.add(it.next());
        }
    }
    return grantees;
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) HashSet(org.hsqldb_voltpatches.lib.HashSet) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Aggregations

Iterator (org.hsqldb_voltpatches.lib.Iterator)102 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)74 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)64 SchemaObject (org.hsqldb_voltpatches.SchemaObject)57 Table (org.hsqldb_voltpatches.Table)55 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)51 Constraint (org.hsqldb_voltpatches.Constraint)50 TextTable (org.hsqldb_voltpatches.TextTable)39 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)28 HsqlException (org.hsqldb_voltpatches.HsqlException)18 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)14 NumberType (org.hsqldb_voltpatches.types.NumberType)10 HashSet (org.hsqldb_voltpatches.lib.HashSet)9 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 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6 IntervalType (org.hsqldb_voltpatches.types.IntervalType)6