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);
}
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);
}
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();
}
}
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;
}
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);
}
Aggregations