Search in sources :

Example 51 with HsqlName

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

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

the class RoutineSchema method addSpecificRoutine.

public void addSpecificRoutine(Database database, Routine routine) {
    int signature = routine.getParameterSignature();
    Type[] types = routine.getParameterTypes();
    for (int i = 0; i < this.routines.length; i++) {
        if (routines[i].parameterTypes.length == types.length) {
            if (routineType == SchemaObject.PROCEDURE) {
                throw Error.error(ErrorCode.X_42605);
            }
            boolean match = true;
            for (int j = 0; j < types.length; j++) {
                if (!routines[i].parameterTypes[j].equals(types[j])) {
                    match = false;
                    break;
                }
            }
            if (match) {
                throw Error.error(ErrorCode.X_42605);
            }
        }
    }
    if (routine.getSpecificName() == null) {
        HsqlName specificName = database.nameManager.newAutoName("", name.name, name.schema, name, name.type);
        routine.setSpecificName(specificName);
    }
    routines = (Routine[]) ArrayUtil.resizeArray(routines, routines.length + 1);
    routines[routines.length - 1] = routine;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 53 with HsqlName

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

the class SchemaManager method getCascadingSchemaReferences.

//
private void getCascadingSchemaReferences(HsqlName schema, OrderedHashSet set) {
    Iterator mainIterator = referenceMap.keySet().iterator();
    while (mainIterator.hasNext()) {
        HsqlName name = (HsqlName) mainIterator.next();
        if (name.schema != schema) {
            continue;
        }
        getCascadingReferences(name, set);
    }
    for (int i = 0; i < set.size(); i++) {
        HsqlName name = (HsqlName) set.get(i);
        if (name.schema == schema) {
            set.remove(i);
            i--;
        }
    }
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 54 with HsqlName

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

Example 55 with HsqlName

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

the class SchemaManager method findSchemaObject.

public SchemaObject findSchemaObject(String name, String schemaName, int type) {
    Schema schema = (Schema) schemaMap.get(schemaName);
    if (schema == null) {
        return null;
    }
    SchemaObjectSet set = null;
    HsqlName objectName;
    Table table;
    switch(type) {
        case SchemaObject.SEQUENCE:
            return schema.sequenceLookup.getObject(name);
        case SchemaObject.TABLE:
        case SchemaObject.VIEW:
            return schema.sequenceLookup.getObject(name);
        case SchemaObject.CHARSET:
            if (name.equals("SQL_IDENTIFIER")) {
                return SqlInvariants.SQL_IDENTIFIER_CHARSET;
            }
            if (name.equals("SQL_TEXT")) {
                return SqlInvariants.SQL_TEXT;
            }
            if (name.equals("LATIN1")) {
                return SqlInvariants.LATIN1;
            }
            if (name.equals("ASCII_GRAPHIC")) {
                return SqlInvariants.ASCII_GRAPHIC;
            }
            return schema.charsetLookup.getObject(name);
        case SchemaObject.COLLATION:
            return schema.collationLookup.getObject(name);
        case SchemaObject.PROCEDURE:
            return schema.procedureLookup.getObject(name);
        case SchemaObject.FUNCTION:
            return schema.functionLookup.getObject(name);
        case SchemaObject.DOMAIN:
        case SchemaObject.TYPE:
            return schema.typeLookup.getObject(name);
        case SchemaObject.INDEX:
            set = schema.indexLookup;
            objectName = set.getName(name);
            if (objectName == null) {
                return null;
            }
            table = (Table) schema.tableList.get(objectName.parent.name);
            return table.getIndex(name);
        case SchemaObject.CONSTRAINT:
            set = schema.constraintLookup;
            objectName = set.getName(name);
            if (objectName == null) {
                return null;
            }
            table = (Table) schema.tableList.get(objectName.parent.name);
            if (table == null) {
                return null;
            }
            return table.getConstraint(name);
        case SchemaObject.TRIGGER:
            set = schema.indexLookup;
            objectName = set.getName(name);
            if (objectName == null) {
                return null;
            }
            table = (Table) schema.tableList.get(objectName.parent.name);
            return table.getTrigger(name);
        default:
            throw Error.runtimeError(ErrorCode.U_S0500, "SchemaManager");
    }
}
Also used : 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