Search in sources :

Example 61 with PersistentStore

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

the class DatabaseInformationMain method SYSTEM_TYPEINFO.

/**
     * Retrieves a <code>Table</code> object describing the
     * result expected by the JDBC DatabaseMetaData interface implementation
     * for system-defined SQL types supported as table columns.
     *
     * <pre class="SqlCodeExample">
     * TYPE_NAME          VARCHAR   the canonical name for DDL statements.
     * DATA_TYPE          SMALLINT  data type code from DITypes.
     * PRECISION          INTEGER   max column size.
     *                              number => max precision.
     *                              character => max characters.
     *                              datetime => max chars incl. frac. component.
     * LITERAL_PREFIX     VARCHAR   char(s) prefixing literal of this type.
     * LITERAL_SUFFIX     VARCHAR   char(s) terminating literal of this type.
     * CREATE_PARAMS      VARCHAR   Localized syntax-order list of domain
     *                              create parameter keywords.
     *                              - for human consumption only
     * NULLABLE           SMALLINT  {No Nulls | Nullable | Unknown}
     * CASE_SENSITIVE     BOOLEAN   case-sensitive in collations/comparisons?
     * SEARCHABLE         SMALLINT  {None | Char (Only WHERE .. LIKE) |
     *                               Basic (Except WHERE .. LIKE) |
     *                               Searchable (All forms)}
     * UNSIGNED_ATTRIBUTE BOOLEAN   {TRUE  (unsigned) | FALSE (signed) |
     *                               NULL (non-numeric or not applicable)}
     * FIXED_PREC_SCALE   BOOLEAN   {TRUE (fixed) | FALSE (variable) |
     *                               NULL (non-numeric or not applicable)}
     * AUTO_INCREMENT     BOOLEAN   automatic unique value generated for
     *                              inserts and updates when no value or
     *                              NULL specified?
     * LOCAL_TYPE_NAME    VARCHAR   localized name of data type;
     *                              - NULL if not supported.
     *                              - for human consuption only
     * MINIMUM_SCALE      SMALLINT  minimum scale supported.
     * MAXIMUM_SCALE      SMALLINT  maximum scale supported.
     * SQL_DATA_TYPE      INTEGER   value expected in SQL CLI SQL_DESC_TYPE
     *                              field of the SQLDA.
     * SQL_DATETIME_SUB   INTEGER   SQL CLI datetime/interval subcode.
     * NUM_PREC_RADIX     INTEGER   numeric base w.r.t # of digits reported in
     *                              PRECISION column (typically 10).
     * TYPE_SUB           INTEGER   From DITypes:
     *                              {TYPE_SUB_DEFAULT | TYPE_SUB_IDENTITY |
     *                               TYPE_SUB_IGNORECASE}
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the
     *      system-defined SQL types supported as table columns
     */
final Table SYSTEM_TYPEINFO() {
    Table t = sysTables[SYSTEM_TYPEINFO];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_TYPEINFO]);
        //-------------------------------------------
        // required by JDBC:
        // ------------------------------------------
        addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_TYPE", Type.SQL_SMALLINT);
        addColumn(t, "PRECISION", Type.SQL_INTEGER);
        addColumn(t, "LITERAL_PREFIX", CHARACTER_DATA);
        addColumn(t, "LITERAL_SUFFIX", CHARACTER_DATA);
        addColumn(t, "CREATE_PARAMS", CHARACTER_DATA);
        addColumn(t, "NULLABLE", Type.SQL_SMALLINT);
        addColumn(t, "CASE_SENSITIVE", Type.SQL_BOOLEAN);
        addColumn(t, "SEARCHABLE", Type.SQL_INTEGER);
        addColumn(t, "UNSIGNED_ATTRIBUTE", Type.SQL_BOOLEAN);
        addColumn(t, "FIXED_PREC_SCALE", Type.SQL_BOOLEAN);
        addColumn(t, "AUTO_INCREMENT", Type.SQL_BOOLEAN);
        addColumn(t, "LOCAL_TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "MINIMUM_SCALE", Type.SQL_SMALLINT);
        addColumn(t, "MAXIMUM_SCALE", Type.SQL_SMALLINT);
        addColumn(t, "SQL_DATA_TYPE", Type.SQL_INTEGER);
        addColumn(t, "SQL_DATETIME_SUB", Type.SQL_INTEGER);
        addColumn(t, "NUM_PREC_RADIX", Type.SQL_INTEGER);
        //-------------------------------------------
        // for JDBC sort contract:
        //-------------------------------------------
        addColumn(t, "TYPE_SUB", Type.SQL_INTEGER);
        // order: DATA_TYPE, TYPE_SUB
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_TYPEINFO].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 1, 18 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    Result rs = sys.executeDirectStatement("select TYPE_NAME, DATA_TYPE, PRECISION, LITERAL_PREFIX," + "LITERAL_SUFFIX, CREATE_PARAMS, NULLABLE, CASE_SENSITIVE," + "SEARCHABLE," + "UNSIGNED_ATTRIBUTE, FIXED_PREC_SCALE, AUTO_INCREMENT, LOCAL_TYPE_NAME, MINIMUM_SCALE, " + "MAXIMUM_SCALE, SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX, TYPE_SUB " + "from INFORMATION_SCHEMA.SYSTEM_ALLTYPEINFO  where AS_TAB_COL = true;");
    t.insertSys(store, rs);
    sys.close();
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Session(org.hsqldb_voltpatches.Session) Result(org.hsqldb_voltpatches.result.Result)

Example 62 with PersistentStore

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

the class DatabaseInformationFull method ROUTINE_SEQUENCE_USAGE.

Table ROUTINE_SEQUENCE_USAGE() {
    Table t = sysTables[ROUTINE_SEQUENCE_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROUTINE_SEQUENCE_USAGE]);
        addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINE_SEQUENCE_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
        return t;
    }
    // column number mappings
    final int specific_catalog = 0;
    final int specific_schema = 1;
    final int specific_name = 2;
    final int sequence_catalog = 3;
    final int sequence_schema = 4;
    final int sequence_name = 5;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Iterator it;
    Object[] row;
    it = database.schemaManager.databaseObjectIterator(SchemaObject.ROUTINE);
    while (it.hasNext()) {
        RoutineSchema routine = (RoutineSchema) it.next();
        if (!session.getGrantee().isAccessible(routine)) {
            continue;
        }
        Routine[] specifics = routine.getSpecificRoutines();
        for (int m = 0; m < specifics.length; m++) {
            OrderedHashSet set = specifics[m].getReferences();
            for (int i = 0; i < set.size(); i++) {
                HsqlName refName = (HsqlName) set.get(i);
                if (refName.type != SchemaObject.SEQUENCE) {
                    continue;
                }
                if (!session.getGrantee().isAccessible(refName)) {
                    continue;
                }
                row = t.getEmptyRowData();
                row[specific_catalog] = database.getCatalogName().name;
                row[specific_schema] = specifics[m].getSchemaName().name;
                row[specific_name] = specifics[m].getName().name;
                row[sequence_catalog] = database.getCatalogName().name;
                row[sequence_schema] = refName.schema.name;
                row[sequence_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) Routine(org.hsqldb_voltpatches.Routine) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException) RoutineSchema(org.hsqldb_voltpatches.RoutineSchema)

Example 63 with PersistentStore

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

the class DatabaseInformationFull method ROLE_COLUMN_GRANTS.

Table ROLE_COLUMN_GRANTS() {
    Table t = sysTables[ROLE_COLUMN_GRANTS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROLE_COLUMN_GRANTS]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", 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);
        // not null
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        // order: COLUMN_NAME, PRIVILEGE
        // for unique: GRANTEE, GRANTOR, TABLE_NAME, TABLE_SCHEMA, TABLE_CAT
        // false PK, as TABLE_SCHEMA and/or TABLE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROLE_COLUMN_GRANTS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 5, 6, 1, 0, 4, 3, 2 }, 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, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, PRIVILEGE_TYPE, IS_GRANTABLE " + "FROM INFORMATION_SCHEMA.COLUMN_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 64 with PersistentStore

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

the class DatabaseInformationFull method SQL_PACKAGES.

Table SQL_PACKAGES() {
    Table t = sysTables[SQL_PACKAGES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SQL_PACKAGES]);
        addColumn(t, "ID", CHARACTER_DATA);
        addColumn(t, "NAME", CHARACTER_DATA);
        addColumn(t, "IS_SUPPORTED", YES_OR_NO);
        addColumn(t, "IS_VERIFIED_BY", CHARACTER_DATA);
        addColumn(t, "COMMENTS", CHARACTER_DATA);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SQL_PACKAGES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
    String sql = (String) statementMap.get("/*sql_packages*/");
    Result rs = sys.executeDirectStatement(sql);
    t.insertSys(store, rs);
    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 65 with PersistentStore

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

the class DatabaseInformationMain method COLUMN_PRIVILEGES.

// -----------------------------------------------------------------------------
// SQL SCHEMATA VIEWS
// limited to views used in JDBC DatabaseMetaData
/**
     * Retrieves a <code>Table</code> object describing the visible
     * access rights for all visible columns of all accessible
     * tables defined within this database.<p>
     *
     * Each row is a column privilege description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * TABLE_CAT    VARCHAR   table catalog
     * TABLE_SCHEM  VARCHAR   table schema
     * TABLE_NAME   VARCHAR   table name
     * COLUMN_NAME  VARCHAR   column name
     * GRANTOR      VARCHAR   grantor of access
     * GRANTEE      VARCHAR   grantee of access
     * PRIVILEGE    VARCHAR   name of access
     * IS_GRANTABLE VARCHAR   grantable?: "YES" - grant to others, else "NO"
     * </pre>
     *
     * <b>Note:</b> From 1.9.0, HSQLDB supports column level
     * privileges. <p>
     *
     * @return a <code>Table</code> object describing the visible
     *        access rights for all visible columns of
     *        all accessible tables defined within this
     *        database
     */
final Table COLUMN_PRIVILEGES() {
    Table t = sysTables[COLUMN_PRIVILEGES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[COLUMN_PRIVILEGES]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", 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);
        // not null
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMN_PRIVILEGES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 2, 3, 4, 5, 6, 1, 0 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    String tableCatalog;
    String tableSchema;
    String tableName;
    Grantee granteeObject;
    // intermediate holders
    User user;
    Iterator tables;
    Table table;
    Object[] row;
    // column number mappings
    final int grantor = 0;
    final int grantee = 1;
    final int table_catalog = 2;
    final int table_schema = 3;
    final int table_name = 4;
    final int column_name = 5;
    final int privilege_type = 6;
    final int is_grantable = 7;
    // enumerations
    OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
    // Initialization
    tables = allTables();
    while (tables.hasNext()) {
        table = (Table) tables.next();
        tableName = table.getName().name;
        tableCatalog = database.getCatalogName().name;
        tableSchema = table.getSchemaName().name;
        for (int i = 0; i < grantees.size(); i++) {
            granteeObject = (Grantee) grantees.get(i);
            OrderedHashSet rights = granteeObject.getAllDirectPrivileges(table);
            OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(table);
            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++) {
                    OrderedHashSet columnList = right.getColumnsForPrivilege(table, Right.privilegeTypes[k]);
                    OrderedHashSet grantableList = grantableRight.getColumnsForPrivilege(table, Right.privilegeTypes[k]);
                    for (int l = 0; l < columnList.size(); l++) {
                        HsqlName fullName = ((HsqlName) columnList.get(l));
                        row = t.getEmptyRowData();
                        row[grantor] = right.getGrantor().getName().name;
                        row[grantee] = right.getGrantee().getName().name;
                        row[table_catalog] = tableCatalog;
                        row[table_schema] = tableSchema;
                        row[table_name] = tableName;
                        row[column_name] = fullName.name;
                        row[privilege_type] = Right.privilegeNames[k];
                        row[is_grantable] = right.getGrantee() == table.getOwner() || grantableList.contains(fullName) ? "YES" : "NO";
                        try {
                            t.insertSys(store, row);
                        } catch (HsqlException e) {
                        }
                    }
                }
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) User(org.hsqldb_voltpatches.rights.User) Right(org.hsqldb_voltpatches.rights.Right) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) 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)

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