Search in sources :

Example 46 with HsqlArrayList

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

the class ParserDDL method processAlterTableAddColumn.

void processAlterTableAddColumn(Table table) {
    int colIndex = table.getColumnCount();
    HsqlArrayList list = new HsqlArrayList();
    Constraint constraint = new Constraint(null, true, null, Constraint.TEMP);
    list.add(constraint);
    checkIsSchemaObjectName();
    HsqlName hsqlName = database.nameManager.newColumnHsqlName(table.getName(), token.tokenString, isDelimitedIdentifier());
    read();
    ColumnSchema column = readColumnDefinitionOrNull(table, hsqlName, list);
    if (column == null) {
        throw Error.error(ErrorCode.X_42000);
    }
    if (token.tokenType == Tokens.BEFORE) {
        read();
        colIndex = table.getColumnIndex(token.tokenString);
        read();
    }
    TableWorks tableWorks = new TableWorks(session, table);
    session.commit(false);
    tableWorks.addColumn(column, colIndex, list);
    return;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 47 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList 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 48 with HsqlArrayList

use of org.hsqldb_voltpatches.lib.HsqlArrayList 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 49 with HsqlArrayList

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

Example 50 with HsqlArrayList

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

the class DatabaseInformationMain method SYSTEM_USERS.

/**
     * Retrieves a <code>Table</code> object describing the
     * visible <code>Users</code> defined within this database.
     * @return table containing information about the users defined within
     *      this database
     */
Table SYSTEM_USERS() {
    Table t = sysTables[SYSTEM_USERS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_USERS]);
        addColumn(t, "USER_NAME", SQL_IDENTIFIER);
        addColumn(t, "ADMIN", Type.SQL_BOOLEAN);
        addColumn(t, "INITIAL_SCHEMA", SQL_IDENTIFIER);
        // order: USER
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_USERS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // Intermediate holders
    HsqlArrayList users;
    User user;
    Object[] row;
    HsqlName initialSchema;
    // Initialization
    users = database.getUserManager().listVisibleUsers(session);
    // Do it.
    for (int i = 0; i < users.size(); i++) {
        row = t.getEmptyRowData();
        user = (User) users.get(i);
        initialSchema = user.getInitialSchema();
        row[0] = user.getNameString();
        row[1] = ValuePool.getBoolean(user.isAdmin());
        row[2] = ((initialSchema == null) ? null : initialSchema.name);
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) User(org.hsqldb_voltpatches.rights.User) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Aggregations

HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)69 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)21 Iterator (org.hsqldb_voltpatches.lib.Iterator)14 HsqlList (org.hsqldb_voltpatches.lib.HsqlList)11 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)10 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)10 Table (org.hsqldb_voltpatches.Table)7 Type (org.hsqldb_voltpatches.types.Type)6 SchemaObject (org.hsqldb_voltpatches.SchemaObject)5 Method (java.lang.reflect.Method)4 Constraint (org.hsqldb_voltpatches.Constraint)3 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)3 Grantee (org.hsqldb_voltpatches.rights.Grantee)3 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)2 Result (org.hsqldb_voltpatches.result.Result)2 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HSQLParseException (org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)1 NumberSequence (org.hsqldb_voltpatches.NumberSequence)1