Search in sources :

Example 36 with OrderedHashSet

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

the class ParserRoutine method readSelectSingleRowStatement.

private Statement readSelectSingleRowStatement(RangeVariable[] rangeVars) {
    OrderedHashSet variableNames = new OrderedHashSet();
    QuerySpecification select = XreadSelect();
    readThis(Tokens.INTO);
    readColumnNamesForSelectInto(variableNames, rangeVars);
    XreadTableExpression(select);
    select.setAsTopLevel();
    select.resolve(session);
    int[] indexes = new int[variableNames.size()];
    ColumnSchema[] variables = new ColumnSchema[variableNames.size()];
    Statement statement = new StatementSimple(StatementTypes.ASSIGNMENT, variables, null, indexes);
    return statement;
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 37 with OrderedHashSet

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

the class TableWorks method dropColumn.

void dropColumn(int colIndex, boolean cascade) {
    OrderedHashSet constraintNameSet = new OrderedHashSet();
    OrderedHashSet dependentConstraints = table.getDependentConstraints(colIndex);
    OrderedHashSet cascadingConstraints = table.getContainingConstraints(colIndex);
    OrderedHashSet indexNameSet = table.getContainingIndexNames(colIndex);
    HsqlName columnName = table.getColumn(colIndex).getName();
    OrderedHashSet referencingObjects = database.schemaManager.getReferencingObjects(table.getName(), columnName);
    if (table.isText() && !table.isEmpty(session)) {
        throw Error.error(ErrorCode.X_S0521);
    }
    if (!cascade) {
        if (!cascadingConstraints.isEmpty()) {
            Constraint c = (Constraint) cascadingConstraints.get(0);
            HsqlName name = c.getName();
            throw Error.error(ErrorCode.X_42536, name.getSchemaQualifiedStatementName());
        }
        if (!referencingObjects.isEmpty()) {
            for (int i = 0; i < referencingObjects.size(); i++) {
                HsqlName name = (HsqlName) referencingObjects.get(i);
                throw Error.error(ErrorCode.X_42536, name.getSchemaQualifiedStatementName());
            }
        }
    }
    dependentConstraints.addAll(cascadingConstraints);
    cascadingConstraints.clear();
    OrderedHashSet tableSet = new OrderedHashSet();
    for (int i = 0; i < dependentConstraints.size(); i++) {
        Constraint c = (Constraint) dependentConstraints.get(i);
        if (c.constType == Constraint.FOREIGN_KEY) {
            tableSet.add(c.getMain());
            constraintNameSet.add(c.getMainName());
            constraintNameSet.add(c.getRefName());
            indexNameSet.add(c.getRefIndex().getName());
        }
        if (c.constType == Constraint.MAIN) {
            tableSet.add(c.getRef());
            constraintNameSet.add(c.getMainName());
            constraintNameSet.add(c.getRefName());
            indexNameSet.add(c.getRefIndex().getName());
        }
        constraintNameSet.add(c.getName());
    }
    tableSet = makeNewTables(tableSet, constraintNameSet, indexNameSet);
    Table tn = table.moveDefinition(session, table.tableType, null, null, null, colIndex, -1, constraintNameSet, indexNameSet);
    tn.moveData(session, table, colIndex, -1);
    //
    database.schemaManager.removeSchemaObjects(referencingObjects);
    database.schemaManager.removeSchemaObjects(constraintNameSet);
    setNewTableInSchema(tn);
    setNewTablesInSchema(tableSet);
    updateConstraints(tn, emptySet);
    updateConstraints(tableSet, constraintNameSet);
    database.persistentStoreCollection.releaseStore(table);
    database.schemaManager.recompileDependentObjects(tableSet);
    database.schemaManager.recompileDependentObjects(tn);
    table = tn;
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 38 with OrderedHashSet

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

the class Table method updateConstraintPath.

void updateConstraintPath() {
    if (fkMainConstraints.length == 0) {
        return;
    }
    OrderedHashSet list = new OrderedHashSet();
    getConstraintPath(defaultColumnMap, list);
    if (list.size() == 0) {
        return;
    }
    fkPath = new Constraint[list.size()];
    list.toArray(fkPath);
    for (int i = 0; i < fkPath.length; i++) {
        Constraint c = fkPath[i];
        HsqlName tableName = c.getMain().getName();
        if (c.getMain() != database.schemaManager.getUserTable(null, tableName)) {
            throw Error.runtimeError(ErrorCode.U_S0500, "table constraint");
        }
        tableName = c.getRef().getName();
        if (c.getRef() != database.schemaManager.getUserTable(null, tableName)) {
            throw Error.runtimeError(ErrorCode.U_S0500, "table constraint");
        }
    }
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 39 with OrderedHashSet

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

the class Table method getReferences.

@Override
public OrderedHashSet getReferences() {
    OrderedHashSet set = new OrderedHashSet();
    for (int i = 0; i < colTypes.length; i++) {
        if (colTypes[i].isDomainType() || colTypes[i].isDistinctType()) {
            HsqlName name = ((SchemaObject) colTypes[i]).getName();
            set.add(name);
        }
    }
    return set;
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 40 with OrderedHashSet

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

the class TableWorks method addLimitConstraint.

/* addUniqueExprConstraint */
// A VoltDB extension to support LIMIT PARTITION ROWS
void addLimitConstraint(Constraint c) {
    // Find any pre-existing LIMIT constraint on the table and remove it
    for (Constraint cst : table.constraintList) {
        if (cst.getConstraintType() == Constraint.LIMIT) {
            OrderedHashSet constraintNameSet = new OrderedHashSet();
            HsqlName name = cst.getName();
            constraintNameSet.add(name);
            updateConstraints(table, constraintNameSet);
            database.schemaManager.removeSchemaObject(name);
            // Highlander rules for Constraint.LIMIT
            break;
        }
    }
    table.addConstraint(c);
    database.schemaManager.addSchemaObject(c);
}
Also used : 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