Search in sources :

Example 76 with OrderedHashSet

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

the class SchemaManager method dropSchema.

void dropSchema(String name, boolean cascade) {
    Schema schema = (Schema) schemaMap.get(name);
    if (schema == null) {
        throw Error.error(ErrorCode.X_42501, name);
    }
    if (cascade) {
        OrderedHashSet externalReferences = new OrderedHashSet();
        getCascadingSchemaReferences(schema.getName(), externalReferences);
        removeSchemaObjects(externalReferences);
    } else {
        if (!schema.isEmpty()) {
            throw Error.error(ErrorCode.X_2B000);
        }
    }
    Iterator tableIterator = schema.schemaObjectIterator(SchemaObject.TABLE);
    while (tableIterator.hasNext()) {
        Table table = ((Table) tableIterator.next());
        database.getGranteeManager().removeDbObject(table.getName());
        table.releaseTriggers();
        database.persistentStoreCollection.releaseStore(table);
    }
    Iterator sequenceIterator = schema.schemaObjectIterator(SchemaObject.SEQUENCE);
    while (sequenceIterator.hasNext()) {
        NumberSequence sequence = ((NumberSequence) sequenceIterator.next());
        database.getGranteeManager().removeDbObject(sequence.getName());
    }
    schema.clearStructures();
    schemaMap.remove(name);
    if (defaultSchemaHsqlName.name.equals(name)) {
        HsqlName hsqlName = database.nameManager.newHsqlName(name, false, SchemaObject.SCHEMA);
        schema = new Schema(hsqlName, database.getGranteeManager().getDBARole());
        defaultSchemaHsqlName = schema.name;
        schemaMap.put(schema.name.name, schema);
    }
    // these are called last and in this particular order
    database.getUserManager().removeSchemaReference(name);
    database.getSessionManager().removeSchemaReference(schema);
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 77 with OrderedHashSet

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

the class SchemaManager method removeSchemaObject.

void removeSchemaObject(HsqlName name, boolean cascade) {
    OrderedHashSet objectSet = new OrderedHashSet();
    switch(name.type) {
        case SchemaObject.SEQUENCE:
        case SchemaObject.TABLE:
        case SchemaObject.VIEW:
        case SchemaObject.TYPE:
        case SchemaObject.CHARSET:
        case SchemaObject.COLLATION:
        case SchemaObject.PROCEDURE:
        case SchemaObject.FUNCTION:
            getCascadingReferences(name, objectSet);
            break;
        case SchemaObject.DOMAIN:
            break;
    }
    if (objectSet.isEmpty()) {
        removeSchemaObject(name);
        return;
    }
    if (!cascade) {
        HsqlName objectName = (HsqlName) objectSet.get(0);
        throw Error.error(ErrorCode.X_42502, objectName.getSchemaQualifiedStatementName());
    }
    objectSet.add(name);
    removeSchemaObjects(objectSet);
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 78 with OrderedHashSet

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

the class SchemaManager method recompileDependentObjects.

/**
     * After addition or removal of columns and indexes all views that
     * reference the table should be recompiled.
     */
void recompileDependentObjects(Table table) {
    OrderedHashSet set = getReferencingObjects(table.getName());
    Session session = database.sessionManager.getSysSession();
    for (int i = 0; i < set.size(); i++) {
        HsqlName name = (HsqlName) set.get(i);
        switch(name.type) {
            case SchemaObject.VIEW:
            case SchemaObject.CONSTRAINT:
            case SchemaObject.ASSERTION:
                SchemaObject object = getSchemaObject(name);
                object.compile(session);
                break;
        }
    }
    HsqlArrayList list = getAllTables();
    for (int i = 0; i < list.size(); i++) {
        Table t = (Table) list.get(i);
        t.updateConstraintPath();
    }
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 79 with OrderedHashSet

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

the class SchemaManager method getReferencingObjects.

OrderedHashSet getReferencingObjects(HsqlName table, HsqlName column) {
    OrderedHashSet set = new OrderedHashSet();
    Iterator it = referenceMap.get(table);
    while (it.hasNext()) {
        HsqlName name = (HsqlName) it.next();
        SchemaObject object = getSchemaObject(name);
        OrderedHashSet references = object.getReferences();
        if (references.contains(column)) {
            set.add(name);
        }
    }
    return set;
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 80 with OrderedHashSet

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

the class SchemaManager method dropTable.

void dropTable(Session session, Table table, boolean cascade) {
    Schema schema = (Schema) schemaMap.get(table.getSchemaName().name);
    int dropIndex = schema.tableList.getIndex(table.getName().name);
    OrderedHashSet externalConstraints = table.getDependentExternalConstraints();
    OrderedHashSet externalReferences = new OrderedHashSet();
    getCascadingReferences(table.getName(), externalReferences);
    if (!cascade) {
        for (int i = 0; i < externalConstraints.size(); i++) {
            Constraint c = (Constraint) externalConstraints.get(i);
            HsqlName tablename = c.getRef().getName();
            HsqlName refname = c.getRefName();
            if (c.getConstraintType() == Constraint.MAIN) {
                throw Error.error(ErrorCode.X_42533, refname.schema.name + '.' + tablename.name + '.' + refname.name);
            }
        }
        if (!externalReferences.isEmpty()) {
            int i = 0;
            for (; i < externalReferences.size(); i++) {
                HsqlName name = (HsqlName) externalReferences.get(i);
                if (name.parent == table.getName()) {
                    continue;
                }
                throw Error.error(ErrorCode.X_42502, name.getSchemaQualifiedStatementName());
            }
        }
    }
    OrderedHashSet tableSet = new OrderedHashSet();
    OrderedHashSet constraintNameSet = new OrderedHashSet();
    OrderedHashSet indexNameSet = new OrderedHashSet();
    for (int i = 0; i < externalConstraints.size(); i++) {
        Constraint c = (Constraint) externalConstraints.get(i);
        Table t = c.getMain();
        if (t != table) {
            tableSet.add(t);
        }
        t = c.getRef();
        if (t != table) {
            tableSet.add(t);
        }
        constraintNameSet.add(c.getMainName());
        constraintNameSet.add(c.getRefName());
        indexNameSet.add(c.getRefIndex().getName());
    }
    TableWorks tw = new TableWorks(session, table);
    tableSet = tw.makeNewTables(tableSet, constraintNameSet, indexNameSet);
    tw.setNewTablesInSchema(tableSet);
    tw.updateConstraints(tableSet, constraintNameSet);
    removeSchemaObjects(externalReferences);
    removeReferencedObject(table.getName());
    schema.tableList.remove(dropIndex);
    database.getGranteeManager().removeDbObject(table.getName());
    schema.triggerLookup.removeParent(table.tableName);
    schema.indexLookup.removeParent(table.tableName);
    schema.constraintLookup.removeParent(table.tableName);
    table.releaseTriggers();
    database.persistentStoreCollection.releaseStore(table);
    recompileDependentObjects(tableSet);
}
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