Search in sources :

Example 16 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileDrop.

/*
    CompiledStatementInterface compileAlter() {

        CompiledStatementInterface cs = null;
        read();
        String sql = getStatement(getParsePosition(), endStatementTokensAlter);

        cs = new CompiledStatementSchema(sql, StatementCodes.ALTER_TYPE, null);

        return cs;
    }
*/
Statement compileDrop() {
    int objectTokenType;
    int objectType;
    int statementType;
    boolean canCascade = false;
    boolean cascade = false;
    boolean useIfExists = false;
    boolean ifExists = false;
    HsqlName readName = null;
    HsqlName writeName = null;
    read();
    objectTokenType = this.token.tokenType;
    switch(objectTokenType) {
        case Tokens.INDEX:
            {
                read();
                statementType = StatementTypes.DROP_INDEX;
                objectType = SchemaObject.INDEX;
                useIfExists = true;
                break;
            }
        case Tokens.ASSERTION:
            {
                read();
                statementType = StatementTypes.DROP_ASSERTION;
                objectType = SchemaObject.ASSERTION;
                canCascade = true;
                break;
            }
        case Tokens.PROCEDURE:
            {
                read();
                statementType = StatementTypes.DROP_ROUTINE;
                objectType = SchemaObject.PROCEDURE;
                canCascade = true;
                break;
            }
        case Tokens.FUNCTION:
            {
                read();
                statementType = StatementTypes.DROP_ROUTINE;
                objectType = SchemaObject.FUNCTION;
                canCascade = true;
                break;
            }
        case Tokens.SCHEMA:
            {
                read();
                statementType = StatementTypes.DROP_SCHEMA;
                objectType = SchemaObject.SCHEMA;
                useIfExists = true;
                canCascade = true;
                break;
            }
        case Tokens.SEQUENCE:
            {
                read();
                statementType = StatementTypes.DROP_SEQUENCE;
                objectType = SchemaObject.SEQUENCE;
                canCascade = true;
                useIfExists = true;
                break;
            }
        case Tokens.TRIGGER:
            {
                read();
                statementType = StatementTypes.DROP_TRIGGER;
                objectType = SchemaObject.TRIGGER;
                canCascade = false;
                break;
            }
        case Tokens.USER:
            {
                read();
                statementType = StatementTypes.DROP_USER;
                objectType = SchemaObject.GRANTEE;
                canCascade = true;
                break;
            }
        case Tokens.ROLE:
            {
                read();
                statementType = StatementTypes.DROP_ROLE;
                objectType = SchemaObject.GRANTEE;
                canCascade = true;
                break;
            }
        case Tokens.DOMAIN:
            read();
            statementType = StatementTypes.DROP_DOMAIN;
            objectType = SchemaObject.DOMAIN;
            canCascade = true;
            break;
        case Tokens.TYPE:
            read();
            statementType = StatementTypes.DROP_TYPE;
            objectType = SchemaObject.TYPE;
            canCascade = true;
            break;
        case Tokens.CHARACTER:
            read();
            readThis(Tokens.SET);
            statementType = StatementTypes.DROP_CHARACTER_SET;
            objectType = SchemaObject.CHARSET;
            canCascade = false;
            break;
        case Tokens.VIEW:
            read();
            statementType = StatementTypes.DROP_VIEW;
            objectType = SchemaObject.VIEW;
            canCascade = true;
            useIfExists = true;
            break;
        case Tokens.STREAM:
        case Tokens.TABLE:
            read();
            statementType = StatementTypes.DROP_TABLE;
            objectType = SchemaObject.TABLE;
            canCascade = true;
            useIfExists = true;
            break;
        default:
            throw unexpectedToken();
    }
    checkIsIdentifier();
    HsqlName name = null;
    switch(objectTokenType) {
        case Tokens.USER:
            {
                checkIsSimpleName();
                checkDatabaseUpdateAuthorisation();
                Grantee grantee = database.getUserManager().get(token.tokenString);
                name = grantee.getName();
                read();
                break;
            }
        case Tokens.ROLE:
            {
                checkIsSimpleName();
                checkDatabaseUpdateAuthorisation();
                Grantee role = database.getGranteeManager().getRole(token.tokenString);
                name = role.getName();
                read();
                break;
            }
        case Tokens.SCHEMA:
            {
                name = readNewSchemaName();
                writeName = database.getCatalogName();
                break;
            }
        default:
            name = readNewSchemaObjectNameNoCheck(objectType);
            try {
                String schemaName = name.schema == null ? session.getSchemaName(null) : name.schema.name;
                SchemaObject object = /* disable 3 lines ...
                        database.schemaManager.getSchemaObject(name.name,
                            schemaName, objectType);

                    ... disabled 3 lines */
                database.schemaManager.findSchemaObject(name.name, schemaName, objectType);
                if (object == null) {
                    writeName = null;
                } else // End of VoltDB extension
                if (cascade) {
                    writeName = database.getCatalogName();
                } else {
                    writeName = object.getName();
                    if (writeName.parent != null) {
                        writeName = writeName.parent;
                    }
                    if (writeName.type != SchemaObject.TABLE) {
                        writeName = null;
                    }
                }
            } catch (HsqlException e) {
            }
    }
    if (useIfExists && token.tokenType == Tokens.IF) {
        read();
        readThis(Tokens.EXISTS);
        ifExists = true;
    }
    if (canCascade) {
        if (token.tokenType == Tokens.CASCADE) {
            cascade = true;
            read();
        } else if (token.tokenType == Tokens.RESTRICT) {
            read();
        }
    }
    Object[] args = new Object[] { name, new Integer(objectType), Boolean.valueOf(cascade), Boolean.valueOf(ifExists) };
    String sql = getLastPart();
    return new StatementSchema(sql, statementType, args, readName, writeName);
}
Also used : Grantee(org.hsqldb_voltpatches.rights.Grantee) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 17 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method readNewUserIdentifier.

HsqlName readNewUserIdentifier() {
    checkIsSimpleName();
    String tokenS = token.tokenString;
    boolean isQuoted = isDelimitedIdentifier();
    if (tokenS.equalsIgnoreCase("SA")) {
        tokenS = "SA";
        isQuoted = false;
    }
    HsqlName name = database.nameManager.newHsqlName(tokenS, isQuoted, SchemaObject.GRANTEE);
    read();
    return name;
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 18 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileAlterColumnType.

private Statement compileAlterColumnType(Table table, ColumnSchema column) {
    HsqlName writeName = null;
    String sql = super.getStatement(getParsePosition(), endStatementTokens);
    if (!table.isTemp()) {
        writeName = table.getName();
    }
    return new StatementSchema(sql, StatementTypes.ALTER_TABLE, null, writeName);
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 19 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileAlterSequence.

Statement compileAlterSequence() {
    HsqlName schema = session.getSchemaHsqlName(token.namePrefix);
    NumberSequence sequence = database.schemaManager.getSequence(token.tokenString, schema.name, true);
    read();
    if (token.tokenType == Tokens.RENAME) {
        read();
        readThis(Tokens.TO);
        return compileRenameObject(sequence.getName(), SchemaObject.SEQUENCE);
    }
    NumberSequence copy = sequence.duplicate();
    readSequenceOptions(copy, false, true);
    String sql = getLastPart();
    Object[] args = new Object[] { sequence, copy };
    return new StatementSchema(sql, StatementTypes.ALTER_SEQUENCE, args, null, null);
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 20 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName in project voltdb by VoltDB.

the class ParserDDL method compileCreateSequence.

StatementSchema compileCreateSequence() {
    read();
    /*
                CREATE SEQUENCE <name>
                [AS {INTEGER | BIGINT}]
                [START WITH <value>]
                [INCREMENT BY <value>]
        */
    HsqlName name = readNewSchemaObjectNameNoCheck(SchemaObject.SEQUENCE);
    NumberSequence sequence = new NumberSequence(name, Type.SQL_INTEGER);
    readSequenceOptions(sequence, true, false);
    String sql = getLastPart();
    Object[] args = new Object[] { sequence };
    return new StatementSchema(sql, StatementTypes.CREATE_SEQUENCE, args, null, null);
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Aggregations

HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)204 Table (org.hsqldb_voltpatches.Table)86 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)73 TextTable (org.hsqldb_voltpatches.TextTable)65 Iterator (org.hsqldb_voltpatches.lib.Iterator)64 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)61 SchemaObject (org.hsqldb_voltpatches.SchemaObject)60 Constraint (org.hsqldb_voltpatches.Constraint)59 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)48 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)22 HsqlException (org.hsqldb_voltpatches.HsqlException)20 Type (org.hsqldb_voltpatches.types.Type)20 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)15 Grantee (org.hsqldb_voltpatches.rights.Grantee)12 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 Index (org.hsqldb_voltpatches.index.Index)6