Search in sources :

Example 86 with Iterator

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

the class Grantee method getRightsSQL.

public HsqlArrayList getRightsSQL() {
    HsqlArrayList list = new HsqlArrayList();
    String roleString = getDirectRolesAsString();
    if (roleString.length() != 0) {
        list.add("GRANT " + roleString + " TO " + getStatementName());
    }
    MultiValueHashMap rightsMap = getRights();
    Iterator dbObjects = rightsMap.keySet().iterator();
    while (dbObjects.hasNext()) {
        Object nameObject = dbObjects.next();
        Iterator rights = rightsMap.get(nameObject);
        while (rights.hasNext()) {
            Right right = (Right) rights.next();
            StringBuffer sb = new StringBuffer(128);
            HsqlName hsqlname = (HsqlName) nameObject;
            switch(hsqlname.type) {
                case SchemaObject.TABLE:
                case SchemaObject.VIEW:
                    Table table = granteeManager.database.schemaManager.findUserTable(null, hsqlname.name, hsqlname.schema.name);
                    if (table != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(right.getTableRightsSQL(table));
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("TABLE ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
                case SchemaObject.SEQUENCE:
                    NumberSequence sequence = (NumberSequence) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.SEQUENCE);
                    if (sequence != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(Tokens.T_USAGE);
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("SEQUENCE ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
                case SchemaObject.DOMAIN:
                    Type domain = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
                    if (domain != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(Tokens.T_USAGE);
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("DOMAIN ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
                case SchemaObject.TYPE:
                    Type type = (Type) granteeManager.database.schemaManager.findSchemaObject(hsqlname.name, hsqlname.schema.name, SchemaObject.DOMAIN);
                    if (type != null) {
                        sb.append(Tokens.T_GRANT).append(' ');
                        sb.append(Tokens.T_USAGE);
                        sb.append(' ').append(Tokens.T_ON).append(' ');
                        sb.append("TYPE ").append(hsqlname.getSchemaQualifiedStatementName());
                    }
                    break;
            }
            if (sb.length() == 0) {
                continue;
            }
            sb.append(' ').append(Tokens.T_TO).append(' ');
            sb.append(getStatementName());
            list.add(sb.toString());
        }
    }
    return list;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) Table(org.hsqldb_voltpatches.Table) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) NumberSequence(org.hsqldb_voltpatches.NumberSequence) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) MultiValueHashMap(org.hsqldb_voltpatches.lib.MultiValueHashMap)

Example 87 with Iterator

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

the class ScriptWriterBase method writeExistingData.

protected void writeExistingData() throws IOException {
    // start with blank schema - SET SCHEMA to log
    currentSession.loggedSchema = null;
    Iterator schemas = database.schemaManager.allSchemaNameIterator();
    while (schemas.hasNext()) {
        String schema = (String) schemas.next();
        Iterator tables = database.schemaManager.databaseObjectIterator(schema, SchemaObject.TABLE);
        while (tables.hasNext()) {
            Table t = (Table) tables.next();
            // write all memory table data
            // write cached table data unless index roots have been written
            // write all text table data apart from readonly text tables
            // unless index roots have been written
            boolean script = false;
            switch(t.getTableType()) {
                case TableBase.MEMORY_TABLE:
                    script = true;
                    break;
                case TableBase.CACHED_TABLE:
                    script = includeCachedData;
                    break;
                case TableBase.TEXT_TABLE:
                    script = includeCachedData && !t.isReadOnly();
                    break;
            }
            try {
                if (script) {
                    schemaToLog = t.getName().schema;
                    writeTableInit(t);
                    RowIterator it = t.rowIterator(currentSession);
                    while (it.hasNext()) {
                        writeRow(currentSession, t, it.getNextRow().getData());
                    }
                    writeTableTerm(t);
                }
            } catch (Exception e) {
                throw Error.error(ErrorCode.FILE_IO_ERROR, e.toString());
            }
        }
    }
    writeDataTerm();
}
Also used : Table(org.hsqldb_voltpatches.Table) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) Iterator(org.hsqldb_voltpatches.lib.Iterator) IOException(java.io.IOException)

Example 88 with Iterator

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

the class GranteeManager method removeDbObjects.

public void removeDbObjects(OrderedHashSet nameSet) {
    Iterator it = nameSet.iterator();
    while (it.hasNext()) {
        HsqlName name = (HsqlName) it.next();
        for (int i = 0; i < map.size(); i++) {
            Grantee g = (Grantee) map.get(i);
            g.revokeDbObject(name);
        }
    }
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 89 with Iterator

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

the class GranteeManager method getRightstSQL.

public String[] getRightstSQL() {
    HsqlArrayList list = new HsqlArrayList();
    Iterator grantees = getGrantees().iterator();
    while (grantees.hasNext()) {
        Grantee grantee = (Grantee) grantees.next();
        String name = grantee.getNameString();
        // _SYSTEM user, DBA Role grants not persisted
        if (GranteeManager.isImmutable(name)) {
            continue;
        }
        HsqlArrayList subList = grantee.getRightsSQL();
        list.addAll(subList);
    }
    String[] array = new String[list.size()];
    list.toArray(array);
    return array;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Iterator(org.hsqldb_voltpatches.lib.Iterator)

Example 90 with Iterator

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

the class GranteeManager method getSQL.

public String[] getSQL() {
    HsqlArrayList list = new HsqlArrayList();
    // roles
    Iterator it = getRoles().iterator();
    while (it.hasNext()) {
        Grantee grantee = (Grantee) it.next();
        // ADMIN_ROLE_NAME is not persisted
        if (!GranteeManager.isReserved(grantee.getNameString())) {
            list.add(grantee.getSQL());
        }
    }
    // users
    it = getGrantees().iterator();
    for (; it.hasNext(); ) {
        Grantee grantee = (Grantee) it.next();
        if (grantee instanceof User) {
            list.add(grantee.getSQL());
        }
    }
    String[] array = new String[list.size()];
    list.toArray(array);
    return array;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) Iterator(org.hsqldb_voltpatches.lib.Iterator)

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