Search in sources :

Example 16 with OrderedHashSet

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

the class ParserDDL method compileAlterTableAddForeignKeyConstraint.

Statement compileAlterTableAddForeignKeyConstraint(Table table, HsqlName name) {
    if (name == null) {
        name = database.nameManager.newAutoName("FK", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
    }
    OrderedHashSet set = readColumnNames(false);
    Constraint c = readFKReferences(table, name, set);
    HsqlName mainTableName = c.getMainTableName();
    c.core.mainTable = database.schemaManager.getTable(session, mainTableName.name, mainTableName.schema.name);
    c.setColumnsIndexes(table);
    String sql = getLastPart();
    Object[] args = new Object[] { c };
    return new StatementSchema(sql, StatementTypes.ALTER_TABLE, args, c.core.mainTableName, table.getName());
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 17 with OrderedHashSet

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

the class ParserDDL method getBaseColumnNames.

/// Collect the names of the unique columns underlying a list of indexed expressions.
private OrderedHashSet getBaseColumnNames(java.util.List<Expression> indexExprs) {
    OrderedHashSet set = new OrderedHashSet();
    HsqlList col_list = new HsqlArrayList();
    for (Expression expression : indexExprs) {
        expression.collectAllColumnExpressions(col_list);
    }
    for (int i = 0; i < col_list.size(); i++) {
        String colName = ((ExpressionColumn) col_list.get(i)).columnName;
        set.add(colName);
    }
    return set;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Example 18 with OrderedHashSet

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

the class SchemaManager method getSQLArray.

public String[] getSQLArray() {
    OrderedHashSet resolved = new OrderedHashSet();
    OrderedHashSet unresolved = new OrderedHashSet();
    HsqlArrayList list = new HsqlArrayList();
    Iterator schemas = schemaMap.values().iterator();
    while (schemas.hasNext()) {
        Schema schema = (Schema) schemas.next();
        if (isSystemSchema(schema.name.name)) {
            continue;
        }
        if (isLobsSchema(schema.name.name)) {
            continue;
        }
        list.addAll(schema.getSQLArray(resolved, unresolved));
    }
    while (true) {
        Iterator it = unresolved.iterator();
        if (!it.hasNext()) {
            break;
        }
        while (it.hasNext()) {
            SchemaObject object = (SchemaObject) it.next();
            OrderedHashSet references = object.getReferences();
            boolean isResolved = true;
            for (int j = 0; j < references.size(); j++) {
                HsqlName name = (HsqlName) references.get(j);
                if (name.type == SchemaObject.COLUMN || name.type == SchemaObject.CONSTRAINT) {
                    name = name.parent;
                }
                if (!resolved.contains(name)) {
                    isResolved = false;
                    break;
                }
            }
            if (isResolved) {
                if (object.getType() == SchemaObject.TABLE) {
                    list.addAll(((Table) object).getSQL(resolved, unresolved));
                } else {
                    list.add(object.getSQL());
                    resolved.add(object.getName());
                }
                it.remove();
            }
        }
    }
    schemas = schemaMap.values().iterator();
    while (schemas.hasNext()) {
        Schema schema = (Schema) schemas.next();
        if (database.schemaManager.isSystemSchema(schema.name.name)) {
            continue;
        }
        if (database.schemaManager.isLobsSchema(schema.name.name)) {
        //                continue;
        }
        list.addAll(schema.getTriggerSQL());
        list.addAll(schema.getSequenceRestartSQL());
    }
    if (defaultSchemaHsqlName != null) {
        StringBuffer sb = new StringBuffer();
        sb.append(Tokens.T_SET).append(' ').append(Tokens.T_DATABASE);
        sb.append(' ').append(Tokens.T_DEFAULT).append(' ');
        sb.append(Tokens.T_INITIAL).append(' ').append(Tokens.T_SCHEMA);
        sb.append(' ').append(defaultSchemaHsqlName.statementName);
        list.add(sb.toString());
    }
    String[] array = new String[list.size()];
    list.toArray(array);
    return array;
}
Also used : HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) 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 19 with OrderedHashSet

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

the class RoutineSchema method getComponents.

public OrderedHashSet getComponents() {
    OrderedHashSet set = new OrderedHashSet();
    set.addAll(routines);
    return set;
}
Also used : OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 20 with OrderedHashSet

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

the class SchemaManager method checkObjectIsReferenced.

void checkObjectIsReferenced(HsqlName name) {
    OrderedHashSet set = getReferencingObjects(name);
    HsqlName refName = null;
    for (int i = 0; i < set.size(); i++) {
        refName = (HsqlName) set.get(i);
        if (refName.parent != name) {
            break;
        }
        refName = null;
    }
    if (refName == null) {
        return;
    }
    throw Error.error(ErrorCode.X_42502, refName.getSchemaQualifiedStatementName());
}
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