Search in sources :

Example 51 with OrderedHashSet

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

the class UserTypeModifier method getComponents.

public final OrderedHashSet getComponents() {
    if (constraints == null) {
        return null;
    }
    OrderedHashSet set = new OrderedHashSet();
    set.addAll(constraints);
    return set;
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 52 with OrderedHashSet

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

the class Charset method getReferences.

public OrderedHashSet getReferences() {
    OrderedHashSet set = new OrderedHashSet();
    set.add(base);
    return set;
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 53 with OrderedHashSet

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

the class ParserDDL method compileRightGrantOrRevoke.

private StatementSchema compileRightGrantOrRevoke(boolean grant) {
    OrderedHashSet granteeList = new OrderedHashSet();
    Grantee grantor = null;
    Right right = null;
    //        SchemaObject   schemaObject;
    HsqlName objectName = null;
    boolean isTable = false;
    boolean isUsage = false;
    boolean isExec = false;
    boolean isAll = false;
    boolean isGrantOption = false;
    boolean cascade = false;
    if (!grant) {
        if (token.tokenType == Tokens.GRANT) {
            read();
            readThis(Tokens.OPTION);
            readThis(Tokens.FOR);
            isGrantOption = true;
        // throw not suppoerted
        } else if (token.tokenType == Tokens.HIERARCHY) {
            throw unsupportedFeature();
        /*
                read();
                readThis(Token.OPTION);
                readThis(Token.FOR);
*/
        }
    }
    // ALL means all the rights the grantor can grant
    if (token.tokenType == Tokens.ALL) {
        read();
        if (token.tokenType == Tokens.PRIVILEGES) {
            read();
        }
        right = Right.fullRights;
        isAll = true;
    } else {
        right = new Right();
        boolean loop = true;
        while (loop) {
            checkIsNotQuoted();
            int rightType = GranteeManager.getCheckSingleRight(token.tokenString);
            int grantType = token.tokenType;
            OrderedHashSet columnSet = null;
            read();
            switch(grantType) {
                case Tokens.REFERENCES:
                case Tokens.SELECT:
                case Tokens.INSERT:
                case Tokens.UPDATE:
                    if (token.tokenType == Tokens.OPENBRACKET) {
                        columnSet = readColumnNames(false);
                    }
                // $FALL-THROUGH$
                case Tokens.DELETE:
                case Tokens.TRIGGER:
                    if (right == null) {
                        right = new Right();
                    }
                    right.set(rightType, columnSet);
                    isTable = true;
                    break;
                case Tokens.USAGE:
                    if (isTable) {
                        throw unexpectedToken();
                    }
                    right = Right.fullRights;
                    isUsage = true;
                    loop = false;
                    continue;
                case Tokens.EXECUTE:
                    if (isTable) {
                        throw unexpectedToken();
                    }
                    right = Right.fullRights;
                    isExec = true;
                    loop = false;
                    continue;
            }
            if (token.tokenType == Tokens.COMMA) {
                read();
                continue;
            }
            break;
        }
    }
    readThis(Tokens.ON);
    if (token.tokenString.equals(Tokens.T_CLASS)) {
        if (!isExec && !isAll) {
            throw unexpectedToken();
        }
        read();
        if (!isSimpleName() || !isDelimitedIdentifier()) {
            throw Error.error(ErrorCode.X_42569);
        }
        objectName = readNewSchemaObjectNameNoCheck(SchemaObject.FUNCTION);
    } else if (token.tokenType == Tokens.TYPE || token.tokenType == Tokens.DOMAIN || token.tokenType == Tokens.SEQUENCE || token.tokenType == Tokens.CHARACTER) {
        if (!isUsage && !isAll) {
            throw unexpectedToken();
        }
        int type = 0;
        switch(token.tokenType) {
            case Tokens.TYPE:
                read();
                type = SchemaObject.TYPE;
                break;
            case Tokens.DOMAIN:
                read();
                type = SchemaObject.DOMAIN;
                break;
            case Tokens.SEQUENCE:
                read();
                type = SchemaObject.SEQUENCE;
                break;
            case Tokens.CHARACTER:
                read();
                readThis(Tokens.SET);
                type = SchemaObject.CHARSET;
                break;
        }
        objectName = readNewSchemaObjectNameNoCheck(type);
    } else {
        if (!isTable && !isAll) {
            throw unexpectedToken();
        }
        readIfThis(Tokens.TABLE);
        objectName = readNewSchemaObjectNameNoCheck(SchemaObject.TABLE);
    }
    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) {
            read();
            readThis(Tokens.GRANT);
            readThis(Tokens.OPTION);
            isGrantOption = true;
        }
        /** @todo - implement */
        if (token.tokenType == Tokens.GRANTED) {
            read();
            readThis(Tokens.BY);
            if (token.tokenType == Tokens.CURRENT_USER) {
                read();
            //
            } else {
                readThis(Tokens.CURRENT_ROLE);
            }
        }
    } else {
        if (token.tokenType == Tokens.CASCADE) {
            cascade = true;
            read();
        } else {
            readThis(Tokens.RESTRICT);
        }
    }
    int type = grant ? StatementTypes.GRANT : StatementTypes.REVOKE;
    Object[] args = new Object[] { granteeList, objectName, right, grantor, Boolean.valueOf(cascade), Boolean.valueOf(isGrantOption) };
    String sql = getLastPart();
    StatementSchema cs = new StatementSchema(sql, type, args, null, null);
    return cs;
}
Also used : Grantee(org.hsqldb_voltpatches.rights.Grantee) Right(org.hsqldb_voltpatches.rights.Right) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 54 with OrderedHashSet

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

the class ParserDDL method processAlterTableAddUniqueConstraint.

// A VoltDB extension to support indexed expressions and the assume unique attribute
void processAlterTableAddUniqueConstraint(Table table, HsqlName name, boolean assumeUnique) {
    boolean isAutogeneratedName = false;
    if (name == null) {
        name = database.nameManager.newAutoName("CT", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
        isAutogeneratedName = true;
    }
    // A VoltDB extension to "readColumnList(table, false)" to support indexed expressions.
    java.util.List<Expression> indexExprs = XreadExpressions(null);
    OrderedHashSet set = getSimpleColumnNames(indexExprs);
    int[] cols = getColumnList(set, table);
    /* disable 1 line ...
        int[] cols = this.readColumnList(table, false);
        ... disabled 1 line */
    // End of VoltDB extension
    session.commit(false);
    TableWorks tableWorks = new TableWorks(session, table);
    // A VoltDB extension to support indexed expressions and the assume unique attribute
    if ((indexExprs != null) && (cols == null)) {
        // A VoltDB extension to support indexed expressions.
        // Not just indexing columns.
        // The meaning of cols shifts here to be
        // the set of unique base columns for the indexed expressions.
        set = getBaseColumnNames(indexExprs);
        cols = getColumnList(set, table);
        tableWorks.addUniqueExprConstraint(cols, indexExprs.toArray(new Expression[indexExprs.size()]), name, isAutogeneratedName, assumeUnique);
        return;
    }
    tableWorks.addUniqueConstraint(cols, name, isAutogeneratedName, assumeUnique);
/* disable 1 line ...
        tableWorks.addUniqueConstraint(cols, name);
        ... disabled 1 line */
// End of VoltDB extension
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 55 with OrderedHashSet

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

the class ParserDDL method readColumnDefinitionOrNull.

/**
     * Responsible for handling the creation of table columns during the process
     * of executing CREATE TABLE or ADD COLUMN etc. statements.
     *
     * @param table this table
     * @param hsqlName column name
     * @param constraintList list of constraints
     * @return a Column object with indicated attributes
     */
ColumnSchema readColumnDefinitionOrNull(Table table, HsqlName hsqlName, HsqlArrayList constraintList) {
    boolean isIdentity = false;
    boolean isPKIdentity = false;
    boolean identityAlways = false;
    Expression generateExpr = null;
    boolean isNullable = true;
    Expression defaultExpr = null;
    Type typeObject;
    NumberSequence sequence = null;
    if (token.tokenType == Tokens.IDENTITY) {
        read();
        isIdentity = true;
        isPKIdentity = true;
        typeObject = Type.SQL_INTEGER;
        sequence = new NumberSequence(null, 0, 1, typeObject);
    } else if (token.tokenType == Tokens.COMMA) {
        ;
        return null;
    } else {
        typeObject = readTypeDefinition(true);
    }
    if (isIdentity) {
    } else if (token.tokenType == Tokens.DEFAULT) {
        read();
        defaultExpr = readDefaultClause(typeObject);
    } else if (token.tokenType == Tokens.GENERATED && !isIdentity) {
        read();
        if (token.tokenType == Tokens.BY) {
            read();
            readThis(Tokens.DEFAULT);
        } else {
            readThis(Tokens.ALWAYS);
            identityAlways = true;
        }
        readThis(Tokens.AS);
        if (token.tokenType == Tokens.IDENTITY) {
            read();
            sequence = new NumberSequence(null, typeObject);
            sequence.setAlways(identityAlways);
            if (token.tokenType == Tokens.OPENBRACKET) {
                read();
                readSequenceOptions(sequence, false, false);
                readThis(Tokens.CLOSEBRACKET);
            }
            isIdentity = true;
        } else if (token.tokenType == Tokens.OPENBRACKET) {
            read();
            generateExpr = XreadValueExpression();
            readThis(Tokens.CLOSEBRACKET);
        }
    }
    ColumnSchema column = new ColumnSchema(hsqlName, typeObject, isNullable, false, defaultExpr);
    readColumnConstraints(table, column, constraintList);
    if (token.tokenType == Tokens.IDENTITY && !isIdentity) {
        read();
        isIdentity = true;
        isPKIdentity = true;
        sequence = new NumberSequence(null, 0, 1, typeObject);
    }
    if (isIdentity) {
        column.setIdentity(sequence);
    }
    if (isPKIdentity && !column.isPrimaryKey()) {
        OrderedHashSet set = new OrderedHashSet();
        set.add(column.getName().name);
        HsqlName constName = database.nameManager.newAutoName("PK", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
        Constraint c = new Constraint(constName, true, set, Constraint.PRIMARY_KEY);
        constraintList.set(0, c);
        column.setPrimaryKey(true);
    }
    return column;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

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