Search in sources :

Example 26 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class DatabaseInformationFull method ROUTINE_COLUMN_USAGE.

Table ROUTINE_COLUMN_USAGE() {
    Table t = sysTables[ROUTINE_COLUMN_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[ROUTINE_COLUMN_USAGE]);
        addColumn(t, "SPECIFIC_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "SPECIFIC_NAME", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "ROUTINE_NAME", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[ROUTINE_COLUMN_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 3, 4, 5, 0, 1, 2, 6, 7, 8, 9 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // column number mappings
    final int specific_catalog = 0;
    final int specific_schema = 1;
    final int specific_name = 2;
    final int routine_catalog = 3;
    final int routine_schema = 4;
    final int routine_name = 5;
    final int table_catalog = 6;
    final int table_schema = 7;
    final int table_name = 8;
    final int column_name = 9;
    //
    Iterator it;
    Object[] row;
    it = database.schemaManager.databaseObjectIterator(SchemaObject.ROUTINE);
    while (it.hasNext()) {
        RoutineSchema routine = (RoutineSchema) it.next();
        if (!session.getGrantee().isAccessible(routine)) {
            continue;
        }
        Routine[] specifics = routine.getSpecificRoutines();
        for (int m = 0; m < specifics.length; m++) {
            OrderedHashSet set = specifics[m].getReferences();
            for (int i = 0; i < set.size(); i++) {
                HsqlName refName = (HsqlName) set.get(i);
                if (refName.type != SchemaObject.COLUMN) {
                    continue;
                }
                if (!session.getGrantee().isAccessible(refName)) {
                    continue;
                }
                row = t.getEmptyRowData();
                //
                row[specific_catalog] = database.getCatalogName().name;
                row[specific_schema] = specifics[m].getSchemaName().name;
                row[specific_name] = specifics[m].getName().name;
                row[routine_catalog] = database.getCatalogName().name;
                row[routine_schema] = routine.getSchemaName().name;
                row[routine_name] = routine.getName().name;
                row[table_catalog] = database.getCatalogName().name;
                row[table_schema] = refName.parent.schema.name;
                row[table_name] = refName.parent.name;
                row[column_name] = refName.name;
                try {
                    t.insertSys(store, row);
                } catch (HsqlException e) {
                }
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Routine(org.hsqldb_voltpatches.Routine) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException) RoutineSchema(org.hsqldb_voltpatches.RoutineSchema)

Example 27 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class RowStoreAVLMemory method insertIndexNodes.

boolean insertIndexNodes(Index primaryIndex, Index newIndex) {
    int position = newIndex.getPosition();
    RowIterator it = primaryIndex.firstRow(this);
    int rowCount = 0;
    HsqlException error = null;
    try {
        while (it.hasNext()) {
            Row row = it.getNextRow();
            ((RowAVL) row).insertNode(position);
            // count before inserting
            rowCount++;
            newIndex.insert(null, this, row);
        }
        return true;
    } catch (java.lang.OutOfMemoryError e) {
        error = Error.error(ErrorCode.OUT_OF_MEMORY);
    } catch (HsqlException e) {
        error = e;
    }
    // backtrack on error
    // rowCount rows have been modified
    it = primaryIndex.firstRow(this);
    for (int i = 0; i < rowCount; i++) {
        Row row = it.getNextRow();
        NodeAVL backnode = ((RowAVL) row).getNode(0);
        int j = position;
        while (--j > 0) {
            backnode = backnode.nNext;
        }
        backnode.nNext = backnode.nNext.nNext;
    }
    throw error;
}
Also used : NodeAVL(org.hsqldb_voltpatches.index.NodeAVL) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) Row(org.hsqldb_voltpatches.Row) RowAVL(org.hsqldb_voltpatches.RowAVL) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 28 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class TextCache method writeHeader.

private void writeHeader(String header) {
    try {
        byte[] buf = null;
        String firstLine = header + NL;
        try {
            buf = firstLine.getBytes(stringEncoding);
        } catch (UnsupportedEncodingException e) {
            buf = firstLine.getBytes();
        }
        dataFile.write(buf, 0, buf.length);
        fileFreePosition = buf.length;
    } catch (IOException e) {
        throw new HsqlException(e.getMessage(), "", 0);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 29 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class PersistentStoreCollectionSession method getStore.

public PersistentStore getStore(Object key) {
    try {
        TableBase table = (TableBase) key;
        PersistentStore store;
        switch(table.persistenceScope) {
            case TableBase.SCOPE_STATEMENT:
                store = (PersistentStore) rowStoreMapStatement.get(table.getPersistenceId());
                if (store == null) {
                    store = session.database.logger.newStore(session, this, table, true);
                }
                return store;
            case TableBase.SCOPE_TRANSACTION:
                store = (PersistentStore) rowStoreMapTransaction.get(table.getPersistenceId());
                if (store == null) {
                    store = session.database.logger.newStore(session, this, table, true);
                }
                return store;
            case TableBase.SCOPE_SESSION:
                store = (PersistentStore) rowStoreMapSession.get(table.getPersistenceId());
                if (store == null) {
                    store = session.database.logger.newStore(session, this, table, true);
                }
                return store;
        }
    } catch (HsqlException e) {
    }
    throw Error.runtimeError(ErrorCode.U_S0500, "PSCS");
}
Also used : TableBase(org.hsqldb_voltpatches.TableBase) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 30 with HsqlException

use of org.hsqldb_voltpatches.HsqlException in project voltdb by VoltDB.

the class TestVoltCompiler method checkDDLAgainstGivenSchema.

private Database checkDDLAgainstGivenSchema(String errorRegex, String givenSchema, String... ddl) throws Exception {
    String schemaDDL = givenSchema + StringUtils.join(ddl, " ");
    VoltCompiler compiler = new VoltCompiler(false);
    boolean success;
    String error;
    try {
        success = compileDDL(schemaDDL, compiler);
        error = (success || compiler.m_errors.size() == 0 ? "" : compiler.m_errors.get(compiler.m_errors.size() - 1).message);
    } catch (HsqlException hex) {
        success = false;
        error = hex.getMessage();
    } catch (PlanningErrorException plex) {
        success = false;
        error = plex.getMessage();
    }
    if (errorRegex == null) {
        assertTrue(String.format("Expected success\nDDL: %s\n%s", StringUtils.join(ddl, " "), error), success);
        Catalog cat = compiler.getCatalog();
        return cat.getClusters().get("cluster").getDatabases().get("database");
    } else {
        assertFalse(String.format("Expected error (\"%s\")\nDDL: %s", errorRegex, StringUtils.join(ddl, " ")), success);
        assertFalse("Expected at least one error message.", error.isEmpty());
        Matcher m = Pattern.compile(errorRegex).matcher(error);
        assertTrue(String.format("%s\nEXPECTED: %s", error, errorRegex), m.matches());
        return null;
    }
}
Also used : PlanningErrorException(org.voltdb.planner.PlanningErrorException) Matcher(java.util.regex.Matcher) HsqlException(org.hsqldb_voltpatches.HsqlException) Catalog(org.voltdb.catalog.Catalog)

Aggregations

HsqlException (org.hsqldb_voltpatches.HsqlException)46 SchemaObject (org.hsqldb_voltpatches.SchemaObject)19 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)17 Constraint (org.hsqldb_voltpatches.Constraint)16 Table (org.hsqldb_voltpatches.Table)16 Iterator (org.hsqldb_voltpatches.lib.Iterator)16 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)16 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)16 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)16 TextTable (org.hsqldb_voltpatches.TextTable)14 IOException (java.io.IOException)10 Routine (org.hsqldb_voltpatches.Routine)5 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)5 TriggerDef (org.hsqldb_voltpatches.TriggerDef)4 Grantee (org.hsqldb_voltpatches.rights.Grantee)4 Right (org.hsqldb_voltpatches.rights.Right)4 Type (org.hsqldb_voltpatches.types.Type)4 Row (org.hsqldb_voltpatches.Row)3 Result (org.hsqldb_voltpatches.result.Result)3 BatchUpdateException (java.sql.BatchUpdateException)2