Search in sources :

Example 26 with OrderedHashSet

use of org.hsqldb_voltpatches.lib.OrderedHashSet 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 27 with OrderedHashSet

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

Example 28 with OrderedHashSet

use of org.hsqldb_voltpatches.lib.OrderedHashSet 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 29 with OrderedHashSet

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

Example 30 with OrderedHashSet

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

the class DatabaseInformationFull method COLUMNS.

Table COLUMNS() {
    Table t = sysTables[COLUMNS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[COLUMNS]);
        //0
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        addColumn(t, "ORDINAL_POSITION", CARDINAL_NUMBER);
        addColumn(t, "COLUMN_DEFAULT", CHARACTER_DATA);
        addColumn(t, "IS_NULLABLE", YES_OR_NO);
        addColumn(t, "DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
        addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
        //10
        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, "CHARACTER_SET_CATALOG", CHARACTER_DATA);
        addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
        addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
        //20
        addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DOMAIN_NAME", SQL_IDENTIFIER);
        addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
        addColumn(t, "SCOPE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
        //30
        addColumn(t, "SCOPE_NAME", SQL_IDENTIFIER);
        // NULL (only for array tyes)
        addColumn(t, "MAXIMUM_CARDINALITY", CARDINAL_NUMBER);
        addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
        addColumn(t, "IS_SELF_REFERENCING", YES_OR_NO);
        addColumn(t, "IS_IDENTITY", YES_OR_NO);
        // ALLWAYS / BY DEFAULT
        addColumn(t, "IDENTITY_GENERATION", CHARACTER_DATA);
        addColumn(t, "IDENTITY_START", CHARACTER_DATA);
        addColumn(t, "IDENTITY_INCREMENT", CHARACTER_DATA);
        addColumn(t, "IDENTITY_MAXIMUM", CHARACTER_DATA);
        addColumn(t, "IDENTITY_MINIMUM", CHARACTER_DATA);
        //40
        addColumn(t, "IDENTITY_CYCLE", YES_OR_NO);
        // ALLWAYS / NEVER
        addColumn(t, "IS_GENERATED", CHARACTER_DATA);
        addColumn(t, "GENERATION_EXPRESSION", CHARACTER_DATA);
        addColumn(t, "IS_UPDATABLE", YES_OR_NO);
        addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
        // order: TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION
        // added for unique: TABLE_CAT
        // false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMNS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 3, 2, 1, 4 }, false);
        return t;
    }
    // column number mappings
    final int table_cat = 0;
    final int table_schem = 1;
    final int table_name = 2;
    final int column_name = 3;
    final int ordinal_position = 4;
    final int column_default = 5;
    final int is_nullable = 6;
    final int data_type = 7;
    final int character_maximum_length = 8;
    final int character_octet_length = 9;
    final int numeric_precision = 10;
    final int numeric_precision_radix = 11;
    final int numeric_scale = 12;
    final int datetime_precision = 13;
    final int interval_type = 14;
    final int interval_precision = 15;
    final int character_set_catalog = 16;
    final int character_set_schema = 17;
    final int character_set_name = 18;
    final int collation_catalog = 19;
    final int collation_schema = 20;
    final int collation_name = 21;
    final int domain_catalog = 22;
    final int domain_schema = 23;
    final int domain_name = 24;
    final int udt_catalog = 25;
    final int udt_schema = 26;
    final int udt_name = 27;
    final int scope_catalog = 28;
    final int scope_schema = 29;
    final int scope_name = 30;
    final int maximum_cardinality = 31;
    final int dtd_identifier = 32;
    final int is_self_referencing = 33;
    final int is_identity = 34;
    final int identity_generation = 35;
    final int identity_start = 36;
    final int identity_increment = 37;
    final int identity_maximum = 38;
    final int identity_minimum = 39;
    final int identity_cycle = 40;
    final int is_generated = 41;
    final int generation_expression = 42;
    final int is_updatable = 43;
    final int declared_data_type = 44;
    final int declared_numeric_precision = 45;
    final int declared_numeric_scale = 46;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // intermediate holders
    int columnCount;
    Iterator tables;
    Table table;
    Object[] row;
    DITableInfo ti;
    OrderedHashSet columnList;
    Type type;
    // Initialization
    tables = allTables();
    ti = new DITableInfo();
    while (tables.hasNext()) {
        table = (Table) tables.next();
        columnList = session.getGrantee().getColumnsForAllPrivileges(table);
        if (columnList.isEmpty()) {
            continue;
        }
        ti.setTable(table);
        columnCount = table.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            ColumnSchema column = table.getColumn(i);
            type = column.getDataType();
            if (!columnList.contains(column.getName())) {
                continue;
            }
            row = t.getEmptyRowData();
            row[table_cat] = table.getCatalogName().name;
            row[table_schem] = table.getSchemaName().name;
            row[table_name] = table.getName().name;
            row[column_name] = column.getName().name;
            row[ordinal_position] = ValuePool.getInt(i + 1);
            row[column_default] = column.getDefaultSQL();
            row[is_nullable] = column.isNullable() ? "YES" : "NO";
            row[data_type] = type.getFullNameString();
            if (type.isCharacterType()) {
                row[character_maximum_length] = ValuePool.getLong(type.precision);
                row[character_octet_length] = ValuePool.getLong(type.precision * 2);
                row[character_set_catalog] = database.getCatalogName().name;
                row[character_set_schema] = ((CharacterType) type).getCharacterSet().getSchemaName().name;
                row[character_set_name] = ((CharacterType) type).getCharacterSet().getName().name;
                row[collation_catalog] = database.getCatalogName().name;
                row[collation_schema] = ((CharacterType) type).getCollation().getSchemaName().name;
                row[collation_name] = ((CharacterType) type).getCollation().getName().name;
            }
            if (type.isBinaryType()) {
                row[character_maximum_length] = ValuePool.getLong(type.precision);
                row[character_octet_length] = ValuePool.getLong(type.precision);
            }
            if (type.isNumberType()) {
                row[numeric_precision] = ValuePool.getLong(type.precision);
                row[numeric_precision_radix] = ValuePool.getLong(((NumberType) type).getPrecisionRadix());
                row[numeric_scale] = ValuePool.getLong(type.scale);
            }
            if (type.isDateTimeType()) {
                row[datetime_precision] = ValuePool.getLong(type.scale);
            }
            if (type.isIntervalType()) {
                row[interval_type] = IntervalType.getQualifier(type.typeCode);
                row[interval_precision] = ValuePool.getLong(type.precision);
                row[datetime_precision] = ValuePool.getLong(type.scale);
            }
            if (type.isDomainType()) {
                row[domain_catalog] = database.getCatalogName().name;
                row[domain_schema] = type.getSchemaName().name;
                row[domain_name] = type.getName().name;
            }
            if (type.isDistinctType()) {
                row[udt_catalog] = database.getCatalogName().name;
                row[udt_schema] = type.getSchemaName().name;
                row[udt_name] = type.getName().name;
            }
            row[scope_catalog] = null;
            row[scope_schema] = null;
            row[scope_name] = null;
            row[maximum_cardinality] = null;
            row[dtd_identifier] = null;
            row[is_self_referencing] = null;
            row[is_identity] = column.isIdentity() ? "YES" : "NO";
            if (column.isIdentity()) {
                NumberSequence sequence = column.getIdentitySequence();
                row[identity_generation] = sequence.isAlways() ? "ALWAYS" : "BY DEFAULT";
                row[identity_start] = Long.toString(sequence.getStartValue());
                row[identity_increment] = Long.toString(sequence.getIncrement());
                row[identity_maximum] = Long.toString(sequence.getMaxValue());
                row[identity_minimum] = Long.toString(sequence.getMinValue());
                row[identity_cycle] = sequence.isCycle() ? "YES" : "NO";
            }
            row[is_generated] = "NEVER";
            row[generation_expression] = null;
            row[is_updatable] = table.isWritable() ? "YES" : "NO";
            row[declared_data_type] = row[data_type];
            if (type.isNumberType()) {
                row[declared_numeric_precision] = row[numeric_precision];
                row[declared_numeric_scale] = row[numeric_scale];
            }
            t.insertSys(store, row);
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) NumberSequence(org.hsqldb_voltpatches.NumberSequence) ColumnSchema(org.hsqldb_voltpatches.ColumnSchema) Constraint(org.hsqldb_voltpatches.Constraint) Type(org.hsqldb_voltpatches.types.Type) CharacterType(org.hsqldb_voltpatches.types.CharacterType) NumberType(org.hsqldb_voltpatches.types.NumberType) IntervalType(org.hsqldb_voltpatches.types.IntervalType) NumberType(org.hsqldb_voltpatches.types.NumberType) 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)

Aggregations

OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)86 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)47 Iterator (org.hsqldb_voltpatches.lib.Iterator)26 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)24 Constraint (org.hsqldb_voltpatches.Constraint)19 SchemaObject (org.hsqldb_voltpatches.SchemaObject)19 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)19 Table (org.hsqldb_voltpatches.Table)18 HsqlException (org.hsqldb_voltpatches.HsqlException)16 TextTable (org.hsqldb_voltpatches.TextTable)16 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)11 HsqlList (org.hsqldb_voltpatches.lib.HsqlList)8 Grantee (org.hsqldb_voltpatches.rights.Grantee)6 Routine (org.hsqldb_voltpatches.Routine)5 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)5 Right (org.hsqldb_voltpatches.rights.Right)5 TriggerDef (org.hsqldb_voltpatches.TriggerDef)4 OrderedIntHashSet (org.hsqldb_voltpatches.lib.OrderedIntHashSet)3 Type (org.hsqldb_voltpatches.types.Type)3 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2