Search in sources :

Example 26 with Table

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

the class DatabaseInformationFull method DOMAINS.

/**
     * The DOMAINS view has one row for each domain. <p>
     *
     *
     * <pre class="SqlCodeExample">
     *
     * </pre>
     *
     * @return Table
     */
Table DOMAINS() {
    Table t = sysTables[DOMAINS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[DOMAINS]);
        addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_TYPE", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
        addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
        addColumn(t, "CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
        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, "DATETIME_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "INTERVAL_TYPE", CHARACTER_DATA);
        addColumn(t, "INTERVAL_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "DOMAIN_DEFAULT", CHARACTER_DATA);
        addColumn(t, "MAXIMUM_CARDINALITY", SQL_IDENTIFIER);
        addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
        addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[DOMAINS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 4, 5, 6 }, false);
        return t;
    }
    final int domain_catalog = 0;
    final int domain_schema = 1;
    final int domain_name = 2;
    final int data_type = 3;
    final int character_maximum_length = 4;
    final int character_octet_length = 5;
    final int character_set_catalog = 6;
    final int character_set_schema = 7;
    final int character_set_name = 8;
    final int collation_catalog = 9;
    final int collation_schema = 10;
    final int collation_name = 11;
    final int numeric_precision = 12;
    final int numeric_precision_radix = 13;
    final int numeric_scale = 14;
    final int datetime_precision = 15;
    final int interval_type = 16;
    final int interval_precision = 17;
    final int domain_default = 18;
    final int maximum_cardinality = 19;
    final int dtd_identifier = 20;
    final int declared_data_type = 21;
    final int declared_numeric_precision = 22;
    final int declared_numeric_scale = 23;
    //
    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().isAccessible(domain)) {
            continue;
        }
        Object[] data = t.getEmptyRowData();
        data[domain_catalog] = database.getCatalogName().name;
        data[domain_schema] = domain.getSchemaName().name;
        data[domain_name] = domain.getName().name;
        data[data_type] = domain.getFullNameString();
        if (domain.isCharacterType()) {
            data[character_maximum_length] = ValuePool.getLong(domain.precision);
            data[character_octet_length] = ValuePool.getLong(domain.precision * 2);
            data[character_set_catalog] = database.getCatalogName().name;
            data[character_set_schema] = ((CharacterType) domain).getCharacterSet().getSchemaName().name;
            data[character_set_name] = ((CharacterType) domain).getCharacterSet().getName().name;
            data[collation_catalog] = database.getCatalogName().name;
            data[collation_schema] = ((CharacterType) domain).getCollation().getSchemaName().name;
            data[collation_name] = ((CharacterType) domain).getCollation().getName().name;
        } else if (domain.isNumberType()) {
            data[numeric_precision] = ValuePool.getLong(((NumberType) domain).getPrecision());
            data[declared_numeric_precision] = data[numeric_precision];
            if (domain.typeCode != Types.SQL_DOUBLE) {
                data[numeric_scale] = ValuePool.getLong(domain.scale);
                data[declared_numeric_scale] = data[numeric_scale];
            }
            data[numeric_precision_radix] = ValuePool.getLong(((NumberType) domain).getPrecisionRadix());
        } else if (domain.isBooleanType()) {
        } else if (domain.isDateTimeType()) {
            data[datetime_precision] = ValuePool.getLong(domain.scale);
        } else if (domain.isIntervalType()) {
            data[interval_precision] = ValuePool.getLong(domain.precision);
            data[interval_type] = domain.getFullNameString();
            data[datetime_precision] = ValuePool.getLong(domain.scale);
        } else if (domain.isBinaryType()) {
            data[character_maximum_length] = ValuePool.getLong(domain.precision);
            data[character_octet_length] = ValuePool.getLong(domain.precision);
        } else if (domain.isBitType()) {
            data[character_maximum_length] = ValuePool.getLong(domain.precision);
            data[character_octet_length] = ValuePool.getLong(domain.precision);
        }
        Expression defaultExpression = domain.userTypeModifier.getDefaultClause();
        if (defaultExpression != null) {
            data[domain_default] = defaultExpression.getSQL();
        }
        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) Expression(org.hsqldb_voltpatches.Expression) 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 27 with Table

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

the class DatabaseInformationFull method ROLE_USAGE_GRANTS.

Table ROLE_USAGE_GRANTS() {
    Table t = sysTables[ROLE_USAGE_GRANTS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROLE_USAGE_GRANTS]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", SQL_IDENTIFIER);
        addColumn(t, "OBJECT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "OBJECT_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "OBJECT_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "OBJECT_TYPE", CHARACTER_DATA);
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_USAGE_GRANTS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, 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 GRANTOR, GRANTEE, OBJECT_CATALOG, OBJECT_SCHEMA, OBJECT_NAME, " + "OBJECT_TYPE, PRIVILEGE_TYPE, IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.USAGE_PRIVILEGES " + "JOIN INFORMATION_SCHEMA.APPLICABLE_ROLES ON GRANTEE = ROLE_NAME;");
    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 28 with Table

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

the class DatabaseInformationFull method TRANSLATIONS.

Table TRANSLATIONS() {
    Table t = sysTables[TRANSLATIONS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[TRANSLATIONS]);
        addColumn(t, "TRANSLATION_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TRANSLATION_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TRANSLATION_NAME", SQL_IDENTIFIER);
        addColumn(t, "SOURCE_CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SOURCE_CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "SOURCE_CHARACTER_SET_NAME", SQL_IDENTIFIER);
        addColumn(t, "TARGET_CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TARGET_CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TARGET_CHARACTER_SET_NAME", SQL_IDENTIFIER);
        addColumn(t, "TRANSLATION_SOURCE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TRANSLATION_SOURCE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TRANSLATION_SOURCE_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[TRANSLATIONS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
        return t;
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 29 with Table

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

the class DatabaseInformationFull method VIEW_COLUMN_USAGE.

/**
     * The VIEW_COLUMN_USAGE table has one row for each column of a
     * table that is explicitly or implicitly referenced in the
     * &lt;query expression&gt; of the view being described. <p>
     *
     * <b>Definition:</b> <p>
     *
     * <pre class="SqlCodeExample">
     * CREATE TABLE SYSTEM_VIEW_COLUMN_USAGE (
     *      VIEW_CATALOG    VARCHAR NULL,
     *      VIEW_SCHEMA     VARCHAR NULL,
     *      VIEW_NAME       VARCHAR NOT NULL,
     *      TABLE_CATALOG   VARCHAR NULL,
     *      TABLE_SCHEMA    VARCHAR NULL,
     *      TABLE_NAME      VARCHAR NOT NULL,
     *      COLUMN_NAME     VARCHAR NOT NULL,
     *      UNIQUE ( VIEW_CATALOG, VIEW_SCHEMA, VIEW_NAME,
     *               TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME,
     *               COLUMN_NAME )
     * )
     * </pre>
     *
     * <b>Description:</b> <p>
     *
     * <ol>
     * <li> The values of VIEW_CATALOG, VIEW_SCHEMA, and VIEW_NAME are the
     *      catalog name, unqualified schema name, and qualified identifier,
     *      respectively, of the view being described. <p>
     *
     * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, and
     *      COLUMN_NAME are the catalog name, unqualified schema name,
     *      qualified identifier, and column name, respectively, of a column
     *      of a table that is explicitly or implicitly referenced in the
     *      &lt;query expression&gt; of the view being described.
     * </ol>
     *
     * @return Table
     */
Table VIEW_COLUMN_USAGE() {
    Table t = sysTables[VIEW_COLUMN_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[VIEW_COLUMN_USAGE]);
        addColumn(t, "VIEW_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "VIEW_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "VIEW_NAME", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[VIEW_COLUMN_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);
    // Calculated column values
    String viewCatalog;
    String viewSchema;
    String viewName;
    // Intermediate holders
    Iterator tables;
    View view;
    Table table;
    Object[] row;
    Iterator iterator;
    // Column number mappings
    final int view_catalog = 0;
    final int view_schema = 1;
    final int view_name = 2;
    final int table_catalog = 3;
    final int table_schema = 4;
    final int table_name = 5;
    final int column_name = 6;
    // Initialization
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    // Do it.
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (table.isView() && session.getGrantee().isFullyAccessibleByRole(table)) {
        // $FALL-THROUGH$
        } else {
            continue;
        }
        viewCatalog = database.getCatalogName().name;
        viewSchema = table.getSchemaName().name;
        viewName = table.getName().name;
        view = (View) table;
        OrderedHashSet references = view.getReferences();
        iterator = references.iterator();
        while (iterator.hasNext()) {
            HsqlName refName = (HsqlName) iterator.next();
            if (refName.type == SchemaObject.COLUMN) {
                row = t.getEmptyRowData();
                row[view_catalog] = viewCatalog;
                row[view_schema] = viewSchema;
                row[view_name] = viewName;
                row[table_catalog] = viewCatalog;
                row[table_schema] = refName.parent.schema.name;
                row[table_name] = refName.parent.name;
                row[column_name] = refName.name;
                try {
                    t.insertSys(store, row);
                } catch (HsqlException e) {
                }
            }
        }
    }
    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) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) View(org.hsqldb_voltpatches.View) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 30 with Table

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

the class DatabaseInformationFull method ROUTINE_PRIVILEGES.

Table ROUTINE_PRIVILEGES() {
    Table t = sysTables[ROUTINE_PRIVILEGES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROUTINE_PRIVILEGES]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        //
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINE_PRIVILEGES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, false);
        return t;
    }
    // column number mappings
    final int grantor = 0;
    final int grantee = 1;
    final int specific_catalog = 2;
    final int specific_schema = 3;
    final int specific_name = 4;
    final int routine_catalog = 5;
    final int routine_schema = 6;
    final int routine_name = 7;
    final int privilege_type = 8;
    final int is_grantable = 9;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    Grantee granteeObject;
    String privilege;
    // intermediate holders
    Iterator routines;
    RoutineSchema routine;
    Object[] row;
    OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
    routines = database.schemaManager.databaseObjectIterator(SchemaObject.ROUTINE);
    while (routines.hasNext()) {
        routine = (RoutineSchema) routines.next();
        for (int i = 0; i < grantees.size(); i++) {
            granteeObject = (Grantee) grantees.get(i);
            OrderedHashSet rights = granteeObject.getAllDirectPrivileges(routine);
            OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(routine);
            if (!grants.isEmpty()) {
                grants.addAll(rights);
                rights = grants;
            }
            for (int j = 0; j < rights.size(); j++) {
                Right right = (Right) rights.get(j);
                Right grantableRight = right.getGrantableRights();
                for (int k = 0; k < Right.privilegeTypes.length; k++) {
                    if (!right.canAccess(Right.privilegeTypes[k])) {
                        continue;
                    }
                    Routine[] specifics = routine.getSpecificRoutines();
                    for (int m = 0; m < specifics.length; m++) {
                        privilege = Right.privilegeNames[k];
                        row = t.getEmptyRowData();
                        //
                        row[grantor] = right.getGrantor().getName().name;
                        row[grantee] = right.getGrantee().getName().name;
                        row[specific_catalog] = database.getCatalogName().name;
                        row[specific_schema] = specifics[m].getSchemaName().name;
                        row[specific_name] = specifics[m].getName().name;
                        row[routine_catalog] = database.getCatalogName().name;
                        row[routine_schema] = routine.getSchemaName().name;
                        row[routine_name] = routine.getName().name;
                        row[privilege_type] = privilege;
                        row[is_grantable] = right.getGrantee() == routine.getOwner() || grantableRight.canAccess(Right.privilegeTypes[k]) ? "YES" : "NO";
                        try {
                            t.insertSys(store, row);
                        } catch (HsqlException e) {
                        }
                    }
                }
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Right(org.hsqldb_voltpatches.rights.Right) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Routine(org.hsqldb_voltpatches.Routine) Constraint(org.hsqldb_voltpatches.Constraint) Grantee(org.hsqldb_voltpatches.rights.Grantee) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlException(org.hsqldb_voltpatches.HsqlException) RoutineSchema(org.hsqldb_voltpatches.RoutineSchema)

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