Search in sources :

Example 31 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method COLUMN_DOMAIN_USAGE.

/**
     * Domains are shown if the authorization is the user or a role given to the
     * user.
     *
     * <p>
     *
     * @return Table
     */
Table COLUMN_DOMAIN_USAGE() {
    Table t = sysTables[COLUMN_DOMAIN_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[COLUMN_DOMAIN_USAGE]);
        addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_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_DOMAIN_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 DOMAIN_CATALOG, DOMAIN_SCHEMA, DOMAIN_NAME, TABLE_CATALOG, " + "TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE DOMAIN_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 32 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method DOMAIN_CONSTRAINTS.

/**
     * a DEFINITION_SCHEMA table. Not in the INFORMATION_SCHEMA list
     */
/*
    Table DATA_TYPE_DESCRIPTOR() {

        Table t = sysTables[DATA_TYPE_DESCRIPTOR];

        if (t == null) {
            t = createBlankTable(sysTableHsqlNames[DATA_TYPE_DESCRIPTOR]);

            addColumn(t, "OBJECT_CATALOG", SQL_IDENTIFIER);
            addColumn(t, "OBJECT_SCHEMA", SQL_IDENTIFIER);
            addColumn(t, "OBJECT_NAME", SQL_IDENTIFIER);
            addColumn(t, "OBJECT_TYPE", CHARACTER_DATA);
            addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
            addColumn(t, "DATA_TYPE", CHARACTER_DATA);
            addColumn(t, "CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
            addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
            addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
            addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
            addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
            addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
            addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
            addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
            addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
            addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
            addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
            addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
            addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
            addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
            addColumn(t, "DATETIME_PRECISION", CARDINAL_NUMBER);
            addColumn(t, "INTERVAL_TYPE", CHARACTER_DATA);
            addColumn(t, "INTERVAL_PRECISION", CARDINAL_NUMBER);
            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, "SCOPE_CATALOG", SQL_IDENTIFIER);
            addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
            addColumn(t, "SCOPE_NAME", SQL_IDENTIFIER);
            addColumn(t, "MAXIMUM_CARDINALITY", SQL_IDENTIFIER);
            t.createPrimaryKey(null, new int[] {
                0, 1, 2, 4, 5, 6
            }, false);

            return t;
        }

        PersistentStore store = database.persistentStoreCollection.getStore(t);
        final int       object_catalog             = 0;
        final int       object_schema              = 1;
        final int       object_name                = 2;
        final int       object_type                = 3;
        final int       dtd_identifier             = 4;
        final int       data_type                  = 5;
        final int       character_set_catalog      = 6;
        final int       character_set_schema       = 7;
        final int       character_set_name         = 8;
        final int       character_maximum_length   = 9;
        final int       character_octet_length     = 10;
        final int       collation_catalog          = 11;
        final int       collation_schema           = 12;
        final int       collation_name             = 13;
        final int       numeric_precision          = 14;
        final int       numeric_precision_radix    = 15;
        final int       numeric_scale              = 16;
        final int       declared_data_type         = 17;
        final int       declared_numeric_precision = 18;
        final int       declared_numeric_scale     = 19;
        final int       datetime_precision         = 20;
        final int       interval_type              = 21;
        final int       interval_precision         = 22;
        final int       user_defined_type_catalog  = 23;
        final int       user_defined_type_schema   = 24;
        final int       user_defined_type_name     = 25;
        final int       scope_catalog              = 26;
        final int       scope_schema               = 27;
        final int       scope_name                 = 28;
        final int       maximum_cardinality        = 29;
        return t;
    }
*/
/**
     *
     * @return Table
     */
Table DOMAIN_CONSTRAINTS() {
    Table t = sysTables[DOMAIN_CONSTRAINTS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[DOMAIN_CONSTRAINTS]);
        addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_NAME", SQL_IDENTIFIER);
        addColumn(t, "IS_DEFERRABLE", YES_OR_NO);
        addColumn(t, "INITIALLY_DEFERRED", YES_OR_NO);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[DOMAIN_CONSTRAINTS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 4, 5, 6 }, false);
        return t;
    }
    final int constraint_catalog = 0;
    final int constraint_schema = 1;
    final int constraint_name = 2;
    final int domain_catalog = 3;
    final int domain_schema = 4;
    final int domain_name = 5;
    final int is_deferrable = 6;
    final int initially_deferred = 7;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    //
    Iterator it = database.schemaManager.databaseObjectIterator(SchemaObject.DOMAIN);
    while (it.hasNext()) {
        Type domain = (Type) it.next();
        if (!domain.isDomainType()) {
            continue;
        }
        if (!session.getGrantee().isFullyAccessibleByRole(domain)) {
            continue;
        }
        Constraint[] constraints = domain.userTypeModifier.getConstraints();
        for (int i = 0; i < constraints.length; i++) {
            Object[] data = t.getEmptyRowData();
            data[constraint_catalog] = data[domain_catalog] = database.getCatalogName().name;
            data[constraint_schema] = data[domain_schema] = domain.getSchemaName().name;
            data[constraint_name] = constraints[i].getName().name;
            data[domain_name] = domain.getName().name;
            data[is_deferrable] = Tokens.T_NO;
            data[initially_deferred] = Tokens.T_NO;
            t.insertSys(store, data);
        }
    }
    return t;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) CharacterType(org.hsqldb_voltpatches.types.CharacterType) NumberType(org.hsqldb_voltpatches.types.NumberType) IntervalType(org.hsqldb_voltpatches.types.IntervalType) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Constraint(org.hsqldb_voltpatches.Constraint) 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 33 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method CHARACTER_SETS.

Table CHARACTER_SETS() {
    Table t = sysTables[CHARACTER_SETS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[CHARACTER_SETS]);
        addColumn(t, "CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_REPERTOIRE", SQL_IDENTIFIER);
        addColumn(t, "FORM_OF_USE", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_COLLATE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_COLLATE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_COLLATE_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CHARACTER_SETS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
        return t;
    }
    final int character_set_catalog = 0;
    final int character_set_schema = 1;
    final int character_set_name = 2;
    final int character_repertoire = 3;
    final int form_of_use = 4;
    final int default_collate_catalog = 5;
    final int default_collate_schema = 6;
    final int default_collate_name = 7;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Iterator it = database.schemaManager.databaseObjectIterator(SchemaObject.CHARSET);
    while (it.hasNext()) {
        Charset charset = (Charset) it.next();
        if (!session.getGrantee().isAccessible(charset)) {
            continue;
        }
        Object[] data = t.getEmptyRowData();
        data[character_set_catalog] = database.getCatalogName().name;
        data[character_set_schema] = charset.getSchemaName().name;
        data[character_set_name] = charset.getName().name;
        data[character_repertoire] = "UCS";
        data[form_of_use] = "UTF16";
        data[default_collate_catalog] = data[character_set_catalog];
        if (charset.base == null) {
            data[default_collate_schema] = data[character_set_schema];
            data[default_collate_name] = data[character_set_name];
        } else {
            data[default_collate_schema] = charset.base.schema.name;
            data[default_collate_name] = charset.base.name;
        }
        t.insertSys(store, data);
    }
    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) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Charset(org.hsqldb_voltpatches.types.Charset) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Example 34 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method CHECK_CONSTRAINT_ROUTINE_USAGE.

/**
     * The CHECK_CONSTRAINT_ROUTINE_USAGE view has one row for each
     * SQL-invoked routine identified as the subject routine of either a
     * &lt;routine invocation&gt;, a &lt;method reference&gt;, a
     * &lt;method invocation&gt;, or a &lt;static method invocation&gt;
     * contained in an &lt;assertion definition&gt;, a &lt;domain
     * constraint&gt;, or a &lt;table constraint definition&gt;. <p>
     *
     * <b>Definition:</b> <p>
     *
     * <pre class="SqlCodeExample">
     * CREATE TABLE SYSTEM_CHECK_ROUTINE_USAGE (
     *      CONSTRAINT_CATALOG      VARCHAR NULL,
     *      CONSTRAINT_SCHEMA       VARCHAR NULL,
     *      CONSTRAINT_NAME         VARCHAR NOT NULL,
     *      SPECIFIC_CATALOG        VARCHAR NULL,
     *      SPECIFIC_SCHEMA         VARCHAR NULL,
     *      SPECIFIC_NAME           VARCHAR NOT NULL,
     *      UNIQUE( CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME,
     *              SPECIFIC_CATALOG, SPECIFIC_SCHEMA, SPECIFIC_NAME )
     * )
     * </pre>
     *
     * <b>Description:</b> <p>
     *
     * <ol>
     * <li> The CHECK_ROUTINE_USAGE table has one row for each
     *      SQL-invoked routine R identified as the subject routine of either a
     *      &lt;routine invocation&gt;, a &lt;method reference&gt;, a &lt;method
     *      invocation&gt;, or a &lt;static method invocation&gt; contained in
     *      an &lt;assertion definition&gt; or in the &lt;check constraint
     *      definition&gt; contained in either a &lt;domain constraint&gt; or a
     *      &lt;table constraint definition&gt;. <p>
     *
     * <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
     *      CONSTRAINT_NAME are the catalog name, unqualified schema name, and
     *      qualified identifier, respectively, of the assertion or check
     *     constraint being described. <p>
     *
     * <li> The values of SPECIFIC_CATALOG, SPECIFIC_SCHEMA, and SPECIFIC_NAME
     *      are the catalog name, unqualified schema name, and qualified
     *      identifier, respectively, of the specific name of R. <p>
     *
     * </ol>
     *
     * @return Table
     */
Table CHECK_CONSTRAINT_ROUTINE_USAGE() {
    Table t = sysTables[CHECK_CONSTRAINT_ROUTINE_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[CHECK_CONSTRAINT_ROUTINE_USAGE]);
        addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CHECK_CONSTRAINT_ROUTINE_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
        return t;
    }
    // column number mappings
    final int constraint_catalog = 0;
    final int constraint_schema = 1;
    final int constraint_name = 2;
    final int specific_catalog = 3;
    final int specific_schema = 4;
    final int specific_name = 5;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    String constraintCatalog;
    String constraintSchema;
    String constraintName;
    String specificSchema;
    // Intermediate holders
    Iterator tables;
    Table table;
    Constraint[] constraints;
    int constraintCount;
    Constraint constraint;
    OrderedHashSet collector;
    Iterator iterator;
    OrderedHashSet methodSet;
    Method method;
    Object[] row;
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    collector = new OrderedHashSet();
    while (tables.hasNext()) {
        collector.clear();
        table = (Table) tables.next();
        if (table.isView() || !session.getGrantee().isFullyAccessibleByRole(table)) {
            continue;
        }
        constraints = table.getConstraints();
        constraintCount = constraints.length;
        constraintCatalog = database.getCatalogName().name;
        constraintSchema = table.getSchemaName().name;
        specificSchema = database.schemaManager.getDefaultSchemaHsqlName().name;
        for (int i = 0; i < constraintCount; i++) {
            constraint = constraints[i];
            if (constraint.getConstraintType() != Constraint.CHECK) {
                continue;
            }
            constraintName = constraint.getName().name;
            constraint.getCheckExpression().collectAllFunctionExpressions(collector);
            methodSet = new OrderedHashSet();
            iterator = collector.iterator();
            while (iterator.hasNext()) {
            /*
                    Function expression = (Function) iterator.next();
                    String className =
                        expression.getMethod().getDeclaringClass().getName();
                    String schema =
                        database.schemaManager.getDefaultSchemaHsqlName().name;
                    SchemaObject object =
                        database.schemaManager.getSchemaObject(className,
                            schema, SchemaObject.FUNCTION);

                    if (!session.getGrantee().isAccessible(object)) {
                        continue;
                    }

                    methodSet.add(expression.getMethod());
*/
            }
            iterator = methodSet.iterator();
            while (iterator.hasNext()) {
                method = (Method) iterator.next();
                row = t.getEmptyRowData();
                row[constraint_catalog] = constraintCatalog;
                row[constraint_schema] = constraintSchema;
                row[constraint_name] = constraintName;
                row[specific_catalog] = database.getCatalogName();
                row[specific_schema] = specificSchema;
                row[specific_name] = DINameSpace.getMethodSpecificName(method);
                t.insertSys(store, row);
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Constraint(org.hsqldb_voltpatches.Constraint) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Method(java.lang.reflect.Method) Constraint(org.hsqldb_voltpatches.Constraint)

Example 35 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class DatabaseInformationFull method insertRoles.

private void insertRoles(Table t, Grantee role, boolean isGrantable) {
    final int grantee = 0;
    final int role_name = 1;
    final int is_grantable = 2;
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    if (isGrantable) {
        Set roles = database.getGranteeManager().getRoleNames();
        Iterator it = roles.iterator();
        while (it.hasNext()) {
            String roleName = (String) it.next();
            Object[] row = t.getEmptyRowData();
            row[grantee] = role.getNameString();
            row[role_name] = roleName;
            row[is_grantable] = "YES";
            t.insertSys(store, row);
        }
    } else {
        OrderedHashSet roles = role.getDirectRoles();
        for (int i = 0; i < roles.size(); i++) {
            String roleName = (String) roles.get(i);
            Object[] row = t.getEmptyRowData();
            row[grantee] = role.getNameString();
            row[role_name] = roleName;
            row[is_grantable] = Tokens.T_NO;
            t.insertSys(store, row);
            role = database.getGranteeManager().getRole(roleName);
            insertRoles(t, role, isGrantable);
        }
    }
}
Also used : SchemaObjectSet(org.hsqldb_voltpatches.SchemaObjectSet) HashSet(org.hsqldb_voltpatches.lib.HashSet) Set(org.hsqldb_voltpatches.lib.Set) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Aggregations

PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)103 Table (org.hsqldb_voltpatches.Table)74 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)73 SchemaObject (org.hsqldb_voltpatches.SchemaObject)59 Constraint (org.hsqldb_voltpatches.Constraint)57 TextTable (org.hsqldb_voltpatches.TextTable)56 Iterator (org.hsqldb_voltpatches.lib.Iterator)51 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)51 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)20 HsqlException (org.hsqldb_voltpatches.HsqlException)19 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)16 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Grantee (org.hsqldb_voltpatches.rights.Grantee)8 Type (org.hsqldb_voltpatches.types.Type)8 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 CachedObject (org.hsqldb_voltpatches.persist.CachedObject)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6