Search in sources :

Example 91 with HsqlName

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

the class TransactionManager method lockTablesTPL.

void lockTablesTPL(Session session, Statement cs) {
    if (cs == null || session.abortTransaction) {
        return;
    }
    HsqlName[] nameList = cs.getTableNamesForWrite();
    for (int i = 0; i < nameList.length; i++) {
        HsqlName name = nameList[i];
        if (name.schema == SqlInvariants.SYSTEM_SCHEMA_HSQLNAME) {
            continue;
        }
        tableWriteLocks.put(name, session);
    }
    nameList = cs.getTableNamesForRead();
    for (int i = 0; i < nameList.length; i++) {
        HsqlName name = nameList[i];
        if (name.schema == SqlInvariants.SYSTEM_SCHEMA_HSQLNAME) {
            continue;
        }
        tableReadLocks.put(name, session);
    }
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 92 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName 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 93 with HsqlName

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

the class TableWorks method addUniqueExprConstraint.

/**
     * A VoltDB extended variant of addUniqueConstraint that supports indexed generalized non-column expressions.
     * @param cols
     * @param indexExprs
     * @param name HsqlName
     */
public void addUniqueExprConstraint(int[] cols, Expression[] indexExprs, HsqlName name, boolean isAutogeneratedName, boolean assumeUnique) {
    database.schemaManager.checkSchemaObjectNotExists(name);
    if (table.getUniqueConstraintForExprs(indexExprs) != null) {
        throw Error.error(ErrorCode.X_42522);
    }
    // create an autonamed index
    HsqlName indexname = database.nameManager.newAutoName("IDX", name.name, table.getSchemaName(), table.getName(), SchemaObject.INDEX);
    Index exprIndex = table.createIndexStructure(indexname, cols, null, null, true, true, false);
    exprIndex = exprIndex.withExpressions(indexExprs);
    Constraint constraint = new Constraint(name, isAutogeneratedName, table, exprIndex, Constraint.UNIQUE).setAssumeUnique(assumeUnique);
    Table tn = table.moveDefinition(session, table.tableType, null, constraint, exprIndex, -1, 0, emptySet, emptySet);
    tn.moveData(session, table, -1, 0);
    database.persistentStoreCollection.releaseStore(table);
    table = tn;
    database.schemaManager.addSchemaObject(constraint);
    setNewTableInSchema(table);
    updateConstraints(table, emptySet);
    database.schemaManager.recompileDependentObjects(table);
}
Also used : HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) Index(org.hsqldb_voltpatches.index.Index)

Example 94 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName 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 95 with HsqlName

use of org.hsqldb_voltpatches.HsqlNameManager.HsqlName 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)

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