Search in sources :

Example 46 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class ParserDDL method compileAlterColumnDataType.

private Statement compileAlterColumnDataType(Table table, ColumnSchema column) {
    HsqlName writeName = null;
    Type typeObject = readTypeDefinition(false);
    String sql = getLastPart();
    Object[] args = new Object[] { table, column, typeObject };
    if (!table.isTemp()) {
        writeName = table.getName();
    }
    return new StatementSchema(sql, StatementTypes.ALTER_TABLE, null, null, writeName);
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 47 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class ParserDDL method readSequenceOptions.

private void readSequenceOptions(NumberSequence sequence, boolean withType, boolean isAlter) {
    OrderedIntHashSet set = new OrderedIntHashSet();
    while (true) {
        boolean end = false;
        if (set.contains(token.tokenType)) {
            throw unexpectedToken();
        }
        switch(token.tokenType) {
            case Tokens.AS:
                {
                    if (withType) {
                        read();
                        Type type = readTypeDefinition(true);
                        sequence.setDefaults(sequence.name, type);
                        break;
                    }
                    throw unexpectedToken();
                }
            case Tokens.START:
                {
                    set.add(token.tokenType);
                    read();
                    readThis(Tokens.WITH);
                    long value = readBigint();
                    sequence.setStartValueNoCheck(value);
                    break;
                }
            case Tokens.RESTART:
                {
                    if (!isAlter) {
                        end = true;
                        break;
                    }
                    set.add(token.tokenType);
                    read();
                    if (readIfThis(Tokens.WITH)) {
                        long value = readBigint();
                        sequence.setCurrentValueNoCheck(value);
                    } else {
                        sequence.setStartValueDefault();
                    }
                    break;
                }
            case Tokens.INCREMENT:
                {
                    set.add(token.tokenType);
                    read();
                    readThis(Tokens.BY);
                    long value = readBigint();
                    sequence.setIncrement(value);
                    break;
                }
            case Tokens.NO:
                read();
                if (token.tokenType == Tokens.MAXVALUE) {
                    sequence.setDefaultMaxValue();
                } else if (token.tokenType == Tokens.MINVALUE) {
                    sequence.setDefaultMinValue();
                } else if (token.tokenType == Tokens.CYCLE) {
                    sequence.setCycle(false);
                } else {
                    throw unexpectedToken();
                }
                set.add(token.tokenType);
                read();
                break;
            case Tokens.MAXVALUE:
                {
                    set.add(token.tokenType);
                    read();
                    long value = readBigint();
                    sequence.setMaxValueNoCheck(value);
                    break;
                }
            case Tokens.MINVALUE:
                {
                    set.add(token.tokenType);
                    read();
                    long value = readBigint();
                    sequence.setMinValueNoCheck(value);
                    break;
                }
            case Tokens.CYCLE:
                set.add(token.tokenType);
                read();
                sequence.setCycle(true);
                break;
            default:
                end = true;
                break;
        }
        if (end) {
            break;
        }
    }
    sequence.checkValues();
}
Also used : Type(org.hsqldb_voltpatches.types.Type) OrderedIntHashSet(org.hsqldb_voltpatches.lib.OrderedIntHashSet)

Example 48 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class ParserDDL method processAlterColumnType.

/**
     * Allows changes to type of column or addition of an IDENTITY generator.
     * IDENTITY is not removed if it does not appear in new column definition
     * Constraint definitions are not allowed
     */
private void processAlterColumnType(Table table, ColumnSchema oldCol, boolean fullDefinition) {
    ColumnSchema newCol;
    if (oldCol.isGenerated()) {
        throw Error.error(ErrorCode.X_42561);
    }
    if (fullDefinition) {
        HsqlArrayList list = new HsqlArrayList();
        Constraint c = table.getPrimaryConstraint();
        if (c == null) {
            c = new Constraint(null, true, null, Constraint.TEMP);
        }
        list.add(c);
        newCol = readColumnDefinitionOrNull(table, oldCol.getName(), list);
        if (newCol == null) {
            throw Error.error(ErrorCode.X_42000);
        }
        if (oldCol.isIdentity() && newCol.isIdentity()) {
            throw Error.error(ErrorCode.X_42525);
        }
        if (list.size() > 1) {
            // attribute of an altered column.
            if (voltDBacceptNotNullConstraint(list)) {
                newCol.setNullable(false);
            } else
                // End of VoltDB extension
                throw Error.error(ErrorCode.X_42524);
        }
    } else {
        Type type = readTypeDefinition(true);
        if (oldCol.isIdentity()) {
            if (!type.isIntegralType()) {
                throw Error.error(ErrorCode.X_42561);
            }
        }
        newCol = oldCol.duplicate();
        newCol.setType(type);
    }
    TableWorks tw = new TableWorks(session, table);
    tw.retypeColumn(oldCol, newCol);
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList)

Example 49 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class ParserDDL method processAlterDomain.

void processAlterDomain() {
    HsqlName schema = session.getSchemaHsqlName(token.namePrefix);
    checkSchemaUpdateAuthorisation(schema);
    Type domain = database.schemaManager.getDomain(token.tokenString, schema.name, true);
    read();
    switch(token.tokenType) {
        case Tokens.RENAME:
            {
                read();
                readThis(Tokens.TO);
                HsqlName newName = readNewSchemaObjectName(SchemaObject.DOMAIN);
                newName.setSchemaIfNull(schema);
                if (domain.getSchemaName() != newName.schema) {
                    throw Error.error(ErrorCode.X_42505, newName.schema.name);
                }
                checkSchemaUpdateAuthorisation(schema);
                database.schemaManager.renameSchemaObject(domain.getName(), newName);
                return;
            }
        case Tokens.DROP:
            {
                read();
                if (token.tokenType == Tokens.DEFAULT) {
                    read();
                    domain.userTypeModifier.removeDefaultClause();
                    return;
                } else if (token.tokenType == Tokens.CONSTRAINT) {
                    read();
                    checkIsSchemaObjectName();
                    HsqlName name = database.schemaManager.getSchemaObjectName(domain.getSchemaName(), token.tokenString, SchemaObject.CONSTRAINT, true);
                    read();
                    //                    domain.removeConstraint(tokenString);
                    database.schemaManager.removeSchemaObject(name);
                    return;
                } else {
                    throw unexpectedToken();
                }
            }
        case Tokens.SET:
            {
                read();
                readThis(Tokens.DEFAULT);
                Expression e = readDefaultClause(domain);
                domain.userTypeModifier.setDefaultClause(e);
                return;
            }
        case Tokens.ADD:
            {
                read();
                if (token.tokenType == Tokens.CONSTRAINT || token.tokenType == Tokens.CHECK) {
                    HsqlArrayList tempConstraints = new HsqlArrayList();
                    readConstraint(domain, tempConstraints);
                    Constraint c = (Constraint) tempConstraints.get(0);
                    domain.userTypeModifier.addConstraint(c);
                    database.schemaManager.addSchemaObject(c);
                    return;
                }
            }
    }
    throw unexpectedToken();
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 50 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class ParserDDL method compileCreateDomain.

StatementSchema compileCreateDomain() {
    UserTypeModifier userTypeModifier = null;
    HsqlName name;
    read();
    name = readNewSchemaObjectNameNoCheck(SchemaObject.DOMAIN);
    readIfThis(Tokens.AS);
    Type type = readTypeDefinition(false).duplicate();
    Expression defaultClause = null;
    if (readIfThis(Tokens.DEFAULT)) {
        defaultClause = readDefaultClause(type);
    }
    userTypeModifier = new UserTypeModifier(name, SchemaObject.DOMAIN, type);
    userTypeModifier.setDefaultClause(defaultClause);
    type.userTypeModifier = userTypeModifier;
    HsqlArrayList tempConstraints = new HsqlArrayList();
    compileContext.currentDomain = type;
    while (true) {
        boolean end = false;
        switch(token.tokenType) {
            case Tokens.CONSTRAINT:
            case Tokens.CHECK:
                readConstraint(type, tempConstraints);
                break;
            default:
                end = true;
                break;
        }
        if (end) {
            break;
        }
    }
    compileContext.currentDomain = null;
    for (int i = 0; i < tempConstraints.size(); i++) {
        Constraint c = (Constraint) tempConstraints.get(i);
        c.prepareCheckConstraint(session, null, false);
        userTypeModifier.addConstraint(c);
    }
    String sql = getLastPart();
    Object[] args = new Object[] { type };
    return new StatementSchema(sql, StatementTypes.CREATE_DOMAIN, args, null, null);
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) UserTypeModifier(org.hsqldb_voltpatches.types.UserTypeModifier)

Aggregations

Type (org.hsqldb_voltpatches.types.Type)72 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)20 CharacterType (org.hsqldb_voltpatches.types.CharacterType)20 NumberType (org.hsqldb_voltpatches.types.NumberType)14 SchemaObject (org.hsqldb_voltpatches.SchemaObject)11 Table (org.hsqldb_voltpatches.Table)9 Iterator (org.hsqldb_voltpatches.lib.Iterator)9 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)9 IntervalType (org.hsqldb_voltpatches.types.IntervalType)9 Constraint (org.hsqldb_voltpatches.Constraint)8 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)8 HsqlException (org.hsqldb_voltpatches.HsqlException)7 TextTable (org.hsqldb_voltpatches.TextTable)6 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)6 DTIType (org.hsqldb_voltpatches.types.DTIType)6 ColumnSchema (org.hsqldb_voltpatches.ColumnSchema)4 DateTimeType (org.hsqldb_voltpatches.types.DateTimeType)4 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2