Search in sources :

Example 56 with OrderedHashSet

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

the class ParserDDL method processAlterTableAddForeignKeyConstraint.

void processAlterTableAddForeignKeyConstraint(Table table, HsqlName name) {
    if (name == null) {
        name = database.nameManager.newAutoName("FK", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
    }
    OrderedHashSet set = readColumnNames(false);
    Constraint c = readFKReferences(table, name, set);
    HsqlName mainTableName = c.getMainTableName();
    c.core.mainTable = database.schemaManager.getTable(session, mainTableName.name, mainTableName.schema.name);
    c.setColumnsIndexes(table);
    session.commit(false);
    TableWorks tableWorks = new TableWorks(session, table);
    tableWorks.addForeignKey(c);
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 57 with OrderedHashSet

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

the class ParserDDL method compileRoleGrantOrRevoke.

private StatementSchema compileRoleGrantOrRevoke(boolean grant) {
    Grantee grantor = session.getGrantee();
    OrderedHashSet roleList = new OrderedHashSet();
    OrderedHashSet granteeList = new OrderedHashSet();
    boolean cascade = false;
    if (!grant && token.tokenType == Tokens.ADMIN) {
        throw unsupportedFeature();
    /*
            read();
            readThis(Token.OPTION);
            readThis(Token.FOR);
*/
    }
    while (true) {
        checkIsSimpleName();
        roleList.add(token.tokenString);
        read();
        if (token.tokenType == Tokens.COMMA) {
            read();
            continue;
        }
        break;
    }
    if (grant) {
        readThis(Tokens.TO);
    } else {
        readThis(Tokens.FROM);
    }
    while (true) {
        checkIsSimpleName();
        granteeList.add(token.tokenString);
        read();
        if (token.tokenType == Tokens.COMMA) {
            read();
        } else {
            break;
        }
    }
    if (grant) {
        if (token.tokenType == Tokens.WITH) {
            throw unsupportedFeature();
        /*
                read();
                readThis(Token.ADMIN);
                readThis(Token.OPTION);
*/
        }
    }
    if (token.tokenType == Tokens.GRANTED) {
        read();
        readThis(Tokens.BY);
        if (token.tokenType == Tokens.CURRENT_USER) {
            read();
        } else {
            readThis(Tokens.CURRENT_ROLE);
        }
    }
    if (!grant) {
        if (token.tokenType == Tokens.CASCADE) {
            cascade = true;
            read();
        } else {
            readThis(Tokens.RESTRICT);
        }
    }
    int type = grant ? StatementTypes.GRANT_ROLE : StatementTypes.REVOKE_ROLE;
    Object[] args = new Object[] { granteeList, roleList, grantor, Boolean.valueOf(cascade) };
    String sql = getLastPart();
    StatementSchema cs = new StatementSchema(sql, type, args, null, null);
    return cs;
}
Also used : Grantee(org.hsqldb_voltpatches.rights.Grantee) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 58 with OrderedHashSet

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

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

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

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