Search in sources :

Example 1 with MultiValueHashMap

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

Aggregations

HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)1 NumberSequence (org.hsqldb_voltpatches.NumberSequence)1 SchemaObject (org.hsqldb_voltpatches.SchemaObject)1 Table (org.hsqldb_voltpatches.Table)1 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 MultiValueHashMap (org.hsqldb_voltpatches.lib.MultiValueHashMap)1 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)1 Type (org.hsqldb_voltpatches.types.Type)1