Search in sources :

Example 51 with Iterator

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

the class DatabaseInformationMain method SYSTEM_SCHEMAS.

/**
     * Retrieves a <code>Table</code> object describing the accessible schemas
     * defined within this database. <p>
     *
     * Each row is a schema description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * TABLE_SCHEM      VARCHAR   simple schema name
     * TABLE_CATALOG    VARCHAR   catalog in which schema is defined
     * IS_DEFAULT       BOOLEAN   is the schema the default for new sessions
     * </pre> <p>
     *
     * @return table containing information about schemas defined
     *      within this database
     */
final Table SYSTEM_SCHEMAS() {
    Table t = sysTables[SYSTEM_SCHEMAS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_SCHEMAS]);
        // not null
        addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "IS_DEFAULT", Type.SQL_BOOLEAN);
        // order: TABLE_SCHEM
        // true PK, as rows never have null TABLE_SCHEM
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_SCHEMAS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Iterator schemas;
    Object[] row;
    // Initialization
    schemas = database.schemaManager.fullSchemaNamesIterator();
    String defschema = database.schemaManager.getDefaultSchemaHsqlName().name;
    // Do it.
    while (schemas.hasNext()) {
        row = t.getEmptyRowData();
        String schema = (String) schemas.next();
        row[0] = schema;
        row[1] = database.getCatalogName().name;
        row[2] = schema.equals(defschema) ? Boolean.TRUE : Boolean.FALSE;
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject)

Example 52 with Iterator

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

the class DatabaseInformationFull method TRIGGER_COLUMN_USAGE.

Table TRIGGER_COLUMN_USAGE() {
    Table t = sysTables[TRIGGER_COLUMN_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[TRIGGER_COLUMN_USAGE]);
        addColumn(t, "TRIGGER_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TRIGGER_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TRIGGER_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[TRIGGER_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);
    // column number mappings
    final int trigger_catalog = 0;
    final int trigger_schema = 1;
    final int trigger_name = 2;
    final int table_catalog = 3;
    final int table_schema = 4;
    final int table_name = 5;
    final int column_name = 6;
    Iterator it;
    Object[] row;
    it = database.schemaManager.databaseObjectIterator(SchemaObject.TRIGGER);
    while (it.hasNext()) {
        TriggerDef trigger = (TriggerDef) it.next();
        if (!session.getGrantee().isAccessible(trigger)) {
            continue;
        }
        OrderedHashSet set = trigger.getReferences();
        for (int i = 0; i < set.size(); i++) {
            HsqlName refName = (HsqlName) set.get(i);
            if (refName.type != SchemaObject.COLUMN) {
                continue;
            }
            if (!session.getGrantee().isAccessible(refName)) {
                continue;
            }
            row = t.getEmptyRowData();
            //
            row[trigger_catalog] = database.getCatalogName().name;
            row[trigger_schema] = trigger.getSchemaName().name;
            row[trigger_name] = trigger.getName().name;
            row[table_catalog] = database.getCatalogName().name;
            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) {
            }
        }
    }
    // Initialization
    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) TriggerDef(org.hsqldb_voltpatches.TriggerDef) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 53 with Iterator

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

the class DatabaseInformationFull method ROUTINES.

Table ROUTINES() {
    Table t = sysTables[ROUTINES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROUTINES]);
        addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_TYPE", CHARACTER_DATA);
        addColumn(t, "MODULE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "MODULE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "MODULE_NAME", SQL_IDENTIFIER);
        addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_TYPE", CHARACTER_DATA);
        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, "TYPE_UDT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TYPE_UDT_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TYPE_UDT_NAME", SQL_IDENTIFIER);
        addColumn(t, "SCOPE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
        //
        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, "ROUTINE_BODY", CHARACTER_DATA);
        addColumn(t, "ROUTINE_DEFINITION", CHARACTER_DATA);
        addColumn(t, "EXTERNAL_NAME", CHARACTER_DATA);
        addColumn(t, "EXTERNAL_LANGUAGE", CHARACTER_DATA);
        addColumn(t, "PARAMETER_STYLE", CHARACTER_DATA);
        addColumn(t, "IS_DETERMINISTIC", YES_OR_NO);
        addColumn(t, "SQL_DATA_ACCESS", CHARACTER_DATA);
        addColumn(t, "IS_NULL_CALL", YES_OR_NO);
        addColumn(t, "SQL_PATH", CHARACTER_DATA);
        //
        addColumn(t, "SCHEMA_LEVEL_ROUTINE", YES_OR_NO);
        addColumn(t, "MAX_DYNAMIC_RESULT_SETS", CARDINAL_NUMBER);
        addColumn(t, "IS_USER_DEFINED_CAST", YES_OR_NO);
        addColumn(t, "IS_IMPLICITLY_INVOCABLE", YES_OR_NO);
        addColumn(t, "SECURITY_TYPE", CHARACTER_DATA);
        addColumn(t, "TO_SQL_SPECIFIC_CATALOG", SQL_IDENTIFIER);
        //
        addColumn(t, "TO_SQL_SPECIFIC_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TO_SQL_SPECIFIC_NAME", SQL_IDENTIFIER);
        addColumn(t, "AS_LOCATOR", YES_OR_NO);
        addColumn(t, "CREATED", TIME_STAMP);
        addColumn(t, "LAST_ALTERED", TIME_STAMP);
        addColumn(t, "NEW_SAVEPOINT_LEVEL", YES_OR_NO);
        addColumn(t, "IS_UDT_DEPENDENT", YES_OR_NO);
        addColumn(t, "RESULT_CAST_FROM_DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "RESULT_CAST_AS_LOCATOR", YES_OR_NO);
        addColumn(t, "RESULT_CAST_CHAR_MAX_LENGTH", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_CHAR_OCTET_LENGTH", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_CHAR_SET_CATALOG", CHARACTER_DATA);
        addColumn(t, "RESULT_CAST_CHAR_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_CHARACTER_SET_NAME", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_COLLATION_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_COLLATION_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_COLLATION_NAME", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_NUMERIC_RADIX", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_NUMERIC_SCALE", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_DATETIME_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_INTERVAL_TYPE", CHARACTER_DATA);
        addColumn(t, "RESULT_CAST_INTERVAL_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_TYPE_UDT_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_TYPE_UDT_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_TYPE_UDT_NAME", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_SCOPE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_SCOPE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_SCOPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "RESULT_CAST_MAX_CARDINALITY", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_DTD_IDENTIFIER", CHARACTER_DATA);
        addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_FROM_DECLARED_DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "RESULT_CAST_DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "RESULT_CAST_DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 3, 4, 5, 0, 1, 2 }, false);
        return t;
    }
    // column number mappings
    final int specific_catalog = 0;
    final int specific_schema = 1;
    final int specific_name = 2;
    final int routine_catalog = 3;
    final int routine_schema = 4;
    final int routine_name = 5;
    final int routine_type = 6;
    final int module_catalog = 7;
    final int module_schema = 8;
    final int module_name = 9;
    final int udt_catalog = 10;
    final int udt_schema = 11;
    final int udt_name = 12;
    final int data_type = 13;
    final int character_maximum_length = 14;
    final int character_octet_length = 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 numeric_precision = 22;
    final int numeric_precision_radix = 23;
    final int numeric_scale = 24;
    final int datetime_precision = 25;
    final int interval_type = 26;
    final int interval_precision = 27;
    final int type_udt_catalog = 28;
    final int type_udt_schema = 29;
    final int type_udt_name = 30;
    final int scope_catalog = 31;
    final int scope_schema = 32;
    final int scope_name = 33;
    final int maximum_cardinality = 34;
    final int dtd_identifier = 35;
    final int routine_body = 36;
    final int routine_definition = 37;
    final int external_name = 38;
    final int external_language = 39;
    final int parameter_style = 40;
    final int is_deterministic = 41;
    final int sql_data_access = 42;
    final int is_null_call = 43;
    final int sql_path = 44;
    final int schema_level_routine = 45;
    final int max_dynamic_result_sets = 46;
    final int is_user_defined_cast = 47;
    final int is_implicitly_invocable = 48;
    final int security_type = 49;
    final int to_sql_specific_catalog = 50;
    final int to_sql_specific_schema = 51;
    final int to_sql_specific_name = 52;
    final int as_locator = 53;
    final int created = 54;
    final int last_altered = 55;
    final int new_savepoint_level = 56;
    final int is_udt_dependent = 57;
    final int result_cast_from_data_type = 58;
    final int result_cast_as_locator = 59;
    final int result_cast_char_max_length = 60;
    final int result_cast_char_octet_length = 61;
    final int result_cast_char_set_catalog = 62;
    final int result_cast_char_set_schema = 63;
    final int result_cast_character_set_name = 64;
    final int result_cast_collation_catalog = 65;
    final int result_cast_collation_schema = 66;
    final int result_cast_collation_name = 67;
    final int result_cast_numeric_precision = 68;
    final int result_cast_numeric_radix = 69;
    final int result_cast_numeric_scale = 70;
    final int result_cast_datetime_precision = 71;
    final int result_cast_interval_type = 72;
    final int result_cast_interval_precision = 73;
    final int result_cast_type_udt_catalog = 74;
    final int result_cast_type_udt_schema = 75;
    final int result_cast_type_udt_name = 76;
    final int result_cast_scope_catalog = 77;
    final int result_cast_scope_schema = 78;
    final int result_cast_scope_name = 79;
    final int result_cast_max_cardinality = 80;
    final int result_cast_dtd_identifier = 81;
    final int declared_data_type = 82;
    final int declared_numeric_precision = 83;
    final int declared_numeric_scale = 84;
    final int result_cast_from_declared_data_type = 85;
    final int result_cast_declared_numeric_precision = 86;
    final int result_cast_declared_numeric_scale = 87;
    //
    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++) {
            row = t.getEmptyRowData();
            Routine specific = specifics[m];
            Type type = specific.isProcedure() ? null : specific.getReturnType();
            //
            row[specific_catalog] = database.getCatalogName().name;
            row[specific_schema] = specific.getSchemaName().name;
            row[specific_name] = specific.getSpecificName().name;
            row[routine_catalog] = database.getCatalogName().name;
            row[routine_schema] = routine.getSchemaName().name;
            row[routine_name] = specific.getName().name;
            row[routine_type] = specific.isProcedure() ? "PROCEDURE" : "FUNCTION";
            row[module_catalog] = null;
            row[module_schema] = null;
            row[module_name] = null;
            row[udt_catalog] = null;
            row[udt_schema] = null;
            row[udt_name] = null;
            row[data_type] = type == null ? null : type.getNameString();
            if (type != null && 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 != null && type.isNumberType()) {
                row[numeric_precision] = ValuePool.getLong(type.precision);
                row[numeric_precision_radix] = ValuePool.getLong(((NumberType) type).getPrecisionRadix());
                row[numeric_scale] = ValuePool.getLong(type.precision);
            }
            if (type != null && (type.isIntervalType() || type.isDateTimeType())) {
                row[datetime_precision] = ValuePool.getLong(type.scale);
            }
            if (type != null && type.isIntervalType()) {
                row[interval_type] = IntervalType.getQualifier(type.typeCode);
                row[interval_precision] = ValuePool.getLong(type.precision);
            }
            row[type_udt_catalog] = null;
            row[type_udt_schema] = null;
            row[type_udt_name] = null;
            row[scope_catalog] = null;
            row[scope_schema] = null;
            row[scope_name] = null;
            row[maximum_cardinality] = null;
            //**
            row[dtd_identifier] = null;
            row[routine_body] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? "EXTERNAL" : "SQL";
            row[routine_definition] = specific.getSQL();
            row[external_name] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? specific.getMethod().getName() : null;
            row[external_language] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? "JAVA" : null;
            row[parameter_style] = specific.getLanguage() == Routine.LANGUAGE_JAVA ? "JAVA" : null;
            row[is_deterministic] = specific.isDeterministic() ? "YES" : "NO";
            row[sql_data_access] = specific.getDataImpactString();
            row[is_null_call] = type == null ? null : specific.isNullInputOutput() ? "YES" : "NO";
            row[sql_path] = null;
            row[schema_level_routine] = "YES";
            row[max_dynamic_result_sets] = ValuePool.getLong(0);
            row[is_user_defined_cast] = type == null ? null : "NO";
            row[is_implicitly_invocable] = null;
            row[security_type] = "DEFINER";
            row[to_sql_specific_catalog] = null;
            row[to_sql_specific_schema] = null;
            row[to_sql_specific_name] = null;
            row[as_locator] = type == null ? null : "NO";
            row[created] = null;
            row[last_altered] = null;
            row[new_savepoint_level] = "YES";
            row[is_udt_dependent] = null;
            row[result_cast_from_data_type] = null;
            row[result_cast_as_locator] = null;
            row[result_cast_char_max_length] = null;
            row[result_cast_char_octet_length] = null;
            row[result_cast_char_set_catalog] = null;
            row[result_cast_char_set_schema] = null;
            row[result_cast_character_set_name] = null;
            row[result_cast_collation_catalog] = null;
            row[result_cast_collation_schema] = null;
            row[result_cast_collation_name] = null;
            row[result_cast_numeric_precision] = null;
            row[result_cast_numeric_radix] = null;
            row[result_cast_numeric_scale] = null;
            row[result_cast_datetime_precision] = null;
            row[result_cast_interval_type] = null;
            row[result_cast_interval_precision] = null;
            row[result_cast_type_udt_catalog] = null;
            row[result_cast_type_udt_schema] = null;
            row[result_cast_type_udt_name] = null;
            row[result_cast_scope_catalog] = null;
            row[result_cast_scope_schema] = null;
            row[result_cast_scope_name] = null;
            row[result_cast_max_cardinality] = null;
            row[result_cast_dtd_identifier] = null;
            row[declared_data_type] = row[data_type];
            row[declared_numeric_precision] = row[numeric_precision];
            row[declared_numeric_scale] = row[numeric_scale];
            row[result_cast_from_declared_data_type] = null;
            row[result_cast_declared_numeric_precision] = null;
            row[result_cast_declared_numeric_scale] = null;
            t.insertSys(store, row);
        }
    }
    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) NumberType(org.hsqldb_voltpatches.types.NumberType) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Routine(org.hsqldb_voltpatches.Routine) Constraint(org.hsqldb_voltpatches.Constraint) RoutineSchema(org.hsqldb_voltpatches.RoutineSchema)

Example 54 with Iterator

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

the class DatabaseInformationFull method USAGE_PRIVILEGES.

/**
     * The USAGE_PRIVILEGES view has one row for each usage privilege
     * descriptor. <p>
     *
     * It effectively contains a representation of the usage privilege
     * descriptors. <p>
     *
     * <b>Definition:</b> <p>
     *
     * <pre class="SqlCodeExample">
     * CREATE TABLE SYSTEM_USAGE_PRIVILEGES (
     *      GRANTOR         VARCHAR NOT NULL,
     *      GRANTEE         VARCHAR NOT NULL,
     *      OBJECT_CATALOG  VARCHAR NULL,
     *      OBJECT_SCHEMA   VARCHAR NULL,
     *      OBJECT_NAME     VARCHAR NOT NULL,
     *      OBJECT_TYPE     VARCHAR NOT NULL
     *
     *          CHECK ( OBJECT_TYPE IN (
     *                      'DOMAIN',
     *                      'CHARACTER SET',
     *                      'COLLATION',
     *                      'TRANSLATION',
     *                      'SEQUENCE' ) ),
     *
     *      IS_GRANTABLE    VARCHAR NOT NULL
     *
     *          CHECK ( IS_GRANTABLE IN ( 'YES', 'NO' ) ),
     *
     *      UNIQUE( GRANTOR, GRANTEE, OBJECT_CATALOG,
     *              OBJECT_SCHEMA, OBJECT_NAME, OBJECT_TYPE )
     * )
     * </pre>
     *
     * <b>Description:</b><p>
     *
     * <ol>
     * <li> The value of GRANTOR is the &lt;authorization identifier&gt; of the
     *      user or role who granted usage privileges on the object of the type
     *      identified by OBJECT_TYPE that is identified by OBJECT_CATALOG,
     *      OBJECT_SCHEMA, and OBJECT_NAME, to the user or role identified by the
     *      value of GRANTEE forthe usage privilege being described. <p>
     *
     * <li> The value of GRANTEE is the &lt;authorization identifier&gt; of some
     *      user or role, or PUBLIC to indicate all users, to whom the usage
     *      privilege being described is granted. <p>
     *
     * <li> The values of OBJECT_CATALOG, OBJECT_SCHEMA, and OBJECT_NAME are the
     *      catalog name, unqualified schema name, and qualified identifier,
     *      respectively, of the object to which the privilege applies. <p>
     *
     * <li> The values of OBJECT_TYPE have the following meanings: <p>
     *
     *      <table border cellpadding="3">
     *          <tr>
     *              <td nowrap>DOMAIN</td>
     *              <td nowrap>The object to which the privilege applies is
     *                         a domain.</td>
     *          <tr>
     *          <tr>
     *              <td nowrap>CHARACTER SET</td>
     *              <td nowrap>The object to which the privilege applies is a
     *                         character set.</td>
     *          <tr>
     *          <tr>
     *              <td nowrap>COLLATION</td>
     *              <td nowrap>The object to which the privilege applies is a
     *                         collation.</td>
     *          <tr>
     *          <tr>
     *              <td nowrap>TRANSLATION</td>
     *              <td nowrap>The object to which the privilege applies is a
     *                         transliteration.</td>
     *          <tr>
     *          <tr>
     *              <td nowrap>SEQUENCE</td>
     *              <td nowrap>The object to which the privilege applies is a
     *                         sequence generator.</td>
     *          <tr>
     *      </table> <p>
     *
     * <li> The values of IS_GRANTABLE have the following meanings: <p>
     *
     *      <table border cellpadding="3">
     *          <tr>
     *              <td nowrap>YES</td>
     *              <td nowrap>The privilege being described was granted
     *                         WITH GRANT OPTION and is thus grantable.</td>
     *          <tr>
     *          <tr>
     *              <td nowrap>NO</td>
     *              <td nowrap>The privilege being described was not granted
     *                  WITH GRANT OPTION and is thus not grantable.</td>
     *          <tr>
     *      </table> <p>
     * <ol>
     *
     * @return Table
     */
Table USAGE_PRIVILEGES() {
    Table t = sysTables[USAGE_PRIVILEGES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[USAGE_PRIVILEGES]);
        // 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);
        // order: COLUMN_NAME, PRIVILEGE
        // for unique: GRANTEE, GRANTOR, TABLE_NAME, TABLE_SCHEM, TABLE_CAT
        // false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[USAGE_PRIVILEGES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }, false);
        return t;
    }
    //
    Object[] row;
    //
    final int grantor = 0;
    final int grantee = 1;
    final int object_catalog = 2;
    final int object_schema = 3;
    final int object_name = 4;
    final int object_type = 5;
    final int privilege_type = 6;
    final int is_grantable = 7;
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Iterator objects = new WrapperIterator(database.schemaManager.databaseObjectIterator(SchemaObject.SEQUENCE), database.schemaManager.databaseObjectIterator(SchemaObject.COLLATION));
    objects = new WrapperIterator(objects, database.schemaManager.databaseObjectIterator(SchemaObject.CHARSET));
    objects = new WrapperIterator(objects, database.schemaManager.databaseObjectIterator(SchemaObject.DOMAIN));
    /*
        objects = new WrapperIterator(
            objects,
            database.schemaManager.databaseObjectIterator(SchemaObject.TYPE));
*/
    OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
    while (objects.hasNext()) {
        SchemaObject object = (SchemaObject) objects.next();
        for (int i = 0; i < grantees.size(); i++) {
            Grantee granteeObject = (Grantee) grantees.get(i);
            OrderedHashSet rights = granteeObject.getAllDirectPrivileges(object);
            OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(object);
            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();
                row = t.getEmptyRowData();
                row[grantor] = right.getGrantor().getName().name;
                row[grantee] = right.getGrantee().getName().name;
                row[object_catalog] = database.getCatalogName().name;
                row[object_schema] = object.getSchemaName().name;
                row[object_name] = object.getName().name;
                row[object_type] = SchemaObjectSet.getName(object.getName().type);
                row[privilege_type] = Tokens.T_USAGE;
                row[is_grantable] = right.getGrantee() == object.getOwner() || grantableRight.isFull() ? Tokens.T_YES : Tokens.T_NO;
                ;
                try {
                    t.insertSys(store, row);
                } catch (HsqlException e) {
                }
            }
        }
    }
    return t;
}
Also used : SchemaObject(org.hsqldb_voltpatches.SchemaObject) Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Right(org.hsqldb_voltpatches.rights.Right) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) 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)

Example 55 with Iterator

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

the class DatabaseInformationMain method SEQUENCES.

/**
     * The SEQUENCES view has one row for each external sequence
     * generator. <p>
     *
     * <b>Definition:</b> <p>
     *
     * <pre class="SqlCodeExample">
     *
     *      SEQUENCE_CATALOG     VARCHAR NULL,
     *      SEQUENCE_SCHEMA      VARCHAR NULL,
     *      SEQUENCE_NAME        VARCHAR NOT NULL,
     *      DATA_TYPE            CHARACTER_DATA
     *      DATA_TYPE            CHARACTER_DATA
     *      NUMERIC_PRECISION    CARDINAL_NUMBER
     *      NUMERIC_PRECISION_RADIX CARDINAL_NUMBER
     *      NUMERIC_SCALE        CARDINAL_NUMBER
     *      MAXIMUM_VALUE        VARCHAR NOT NULL,
     *      MINIMUM_VALUE        VARCHAR NOT NULL,
     *      INCREMENT            VARCHAR NOT NULL,
     *      CYCLE_OPTION         VARCHAR {'YES', 'NO'},
     *      START_WITH           VARCHAR NOT NULL,
     *      DECLARED_DATA_TYPE   CHARACTER_DATA
     *      DECLARED_NUMERIC_PRECISION CARDINAL_NUMBER
     *      DECLARED_NUMERIC_SCLAE     CARDINAL_NUMBER
     *
     * </pre>
     *
     * <b>DESCRIPTION:</b><p>
     *
     * <ol>
     * <li> The values of SEQUENCE_CATALOG, SEQUENCE_SCHEMA, and
     *      SEQUENCE_NAME are the catalog name, unqualified schema name,
     *      and qualified identifier, respectively, of the sequence generator
     *      being described. <p>
     *
     * <li> The values of SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME, and
     *      DTD_IDENTIFIER are the values of OBJECT_CATALOG, OBJECT_SCHEMA,
     *      OBJECT_NAME, and DTD_IDENTIFIER, respectively, of the row in
     *      DATA_TYPE_DESCRIPTOR (not yet implemented) that describes the data
     *      type of the sequence generator. <p>
     *
     * <li> The values of MAXIMUM_VALUE, MINIMUM_VALUE, and INCREMENT are the
     *      character representations of maximum value, minimum value,
     *      and increment, respectively, of the sequence generator being
     *      described. <p>
     *
     * <li> The values of CYCLE_OPTION have the following meanings: <p>
     *
     *      <table border cellpadding="3">
     *          <tr>
     *              <td nowrap>YES</td>
     *              <td nowrap>The cycle option of the sequence generator
     *                         is CYCLE.</td>
     *          <tr>
     *              <td nowrap>NO</td>
     *              <td nowrap>The cycle option of the sequence generator is
     *                         NO CYCLE.</td>
     *          </tr>
     *      </table> <p>
     *
     * <li> The value of START_WITH is HSQLDB-specific (not in the SQL 200n
     *      spec).  <p>
     *
     *      It is the character representation of the START WITH value. <p>
     *
     * <li> The value of NEXT_VALUE is HSQLDB-specific (not in the SQL 200n)<p>
     *      This is the character representation of the value that
     *      would be generated by NEXT VALUE FOR when this sequence
     *      is materialized in an SQL statement. <p>
     * </ol>
     *
     * @return Table
     */
final Table SEQUENCES() {
    Table t = sysTables[SEQUENCES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SEQUENCES]);
        addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
        addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
        addColumn(t, "MAXIMUM_VALUE", CHARACTER_DATA);
        addColumn(t, "MINIMUM_VALUE", CHARACTER_DATA);
        addColumn(t, "INCREMENT", CHARACTER_DATA);
        addColumn(t, "CYCLE_OPTION", YES_OR_NO);
        addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
        // HSQLDB-specific
        addColumn(t, "START_WITH", CHARACTER_DATA);
        addColumn(t, "NEXT_VALUE", CHARACTER_DATA);
        // order SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME
        // false PK, as CATALOG may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SEQUENCES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    //
    final int sequence_catalog = 0;
    final int sequence_schema = 1;
    final int sequence_name = 2;
    final int data_type = 3;
    final int numeric_precision = 4;
    final int numeric_precision_radix = 5;
    final int numeric_scale = 6;
    final int maximum_value = 7;
    final int minimum_value = 8;
    final int increment = 9;
    final int cycle_option = 10;
    final int declared_data_type = 11;
    final int declared_numeric_precision = 12;
    final int declared_numeric_scale = 13;
    final int start_with = 14;
    final int next_value = 15;
    //
    Iterator it;
    Object[] row;
    NumberSequence sequence;
    it = database.schemaManager.databaseObjectIterator(SchemaObject.SEQUENCE);
    while (it.hasNext()) {
        sequence = (NumberSequence) it.next();
        if (!session.getGrantee().isAccessible(sequence)) {
            continue;
        }
        row = t.getEmptyRowData();
        NumberType type = (NumberType) sequence.getDataType();
        int radix = (type.typeCode == Types.SQL_NUMERIC || type.typeCode == Types.SQL_DECIMAL) ? 10 : 2;
        row[sequence_catalog] = database.getCatalogName().name;
        row[sequence_schema] = sequence.getSchemaName().name;
        row[sequence_name] = sequence.getName().name;
        row[data_type] = sequence.getDataType().getFullNameString();
        row[numeric_precision] = ValuePool.getInt((int) type.getPrecision());
        row[numeric_precision_radix] = ValuePool.getInt(radix);
        row[numeric_scale] = ValuePool.INTEGER_0;
        row[maximum_value] = String.valueOf(sequence.getMaxValue());
        row[minimum_value] = String.valueOf(sequence.getMinValue());
        row[increment] = String.valueOf(sequence.getIncrement());
        row[cycle_option] = sequence.isCycle() ? "YES" : "NO";
        row[declared_data_type] = row[data_type];
        row[declared_numeric_precision] = row[numeric_precision];
        row[declared_numeric_scale] = row[declared_numeric_scale];
        row[start_with] = String.valueOf(sequence.getStartValue());
        row[next_value] = String.valueOf(sequence.peek());
        t.insertSys(store, row);
    }
    return t;
}
Also used : NumberType(org.hsqldb_voltpatches.types.NumberType) Table(org.hsqldb_voltpatches.Table) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) NumberSequence(org.hsqldb_voltpatches.NumberSequence) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Aggregations

Iterator (org.hsqldb_voltpatches.lib.Iterator)102 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)74 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)64 SchemaObject (org.hsqldb_voltpatches.SchemaObject)57 Table (org.hsqldb_voltpatches.Table)55 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)51 Constraint (org.hsqldb_voltpatches.Constraint)50 TextTable (org.hsqldb_voltpatches.TextTable)39 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)28 HsqlException (org.hsqldb_voltpatches.HsqlException)18 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)14 NumberType (org.hsqldb_voltpatches.types.NumberType)10 HashSet (org.hsqldb_voltpatches.lib.HashSet)9 Type (org.hsqldb_voltpatches.types.Type)9 Grantee (org.hsqldb_voltpatches.rights.Grantee)8 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6 IntervalType (org.hsqldb_voltpatches.types.IntervalType)6