Search in sources :

Example 41 with HsqlException

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

the class DatabaseInformationFull method VIEW_TABLE_USAGE.

/**
     * The VIEW_TABLE_USAGE table has one row for each table identified
     * by a <table name> simply contained in a <table reference>
     * that is contained in the &lt;query expression&gt; of a view. <p>
     *
     * <b>Definition</b><p>
     *
     * <pre class="SqlCodeExample">
     * CREATE TABLE SYSTEM_VIEW_TABLE_USAGE (
     *      VIEW_CATALOG    VARCHAR NULL,
     *      VIEW_SCHEMA     VARCHAR NULL,
     *      VIEW_NAME       VARCHAR NULL,
     *      TABLE_CATALOG   VARCHAR NULL,
     *      TABLE_SCHEMA    VARCHAR NULL,
     *      TABLE_NAME      VARCHAR NULL,
     *      UNIQUE( VIEW_CATALOG, VIEW_SCHEMA, VIEW_NAME,
     *              TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME )
     * )
     * </pre>
     *
     * <b>Description:</b><p>
     *
     * <ol>
     * <li> The values of VIEW_CATALOG, VIEW_SCHEMA, and VIEW_NAME are the
     *      catalog name, unqualified schema name, and qualified identifier,
     *      respectively, of the view being described. <p>
     *
     * <li> The values of TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAME are the
     *      catalog name, unqualified schema name, and qualified identifier,
     *      respectively, of a table identified by a &lt;table name&gt;
     *      simply contained in a &lt;table reference&gt; that is contained in
     *      the &lt;query expression&gt; of the view being described.
     * </ol>
     *
     * @return Table
     */
Table VIEW_TABLE_USAGE() {
    Table t = sysTables[VIEW_TABLE_USAGE];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[VIEW_TABLE_USAGE]);
        addColumn(t, "VIEW_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "VIEW_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "VIEW_NAME", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // false PK, as VIEW_CATALOG, VIEW_SCHEMA, TABLE_CATALOG, and/or
        // TABLE_SCHEMA may be NULL
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[VIEW_TABLE_USAGE].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
        return t;
    }
    // Column number mappings
    final int view_catalog = 0;
    final int view_schema = 1;
    final int view_name = 2;
    final int table_catalog = 3;
    final int table_schema = 4;
    final int table_name = 5;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Iterator tables;
    Table table;
    Object[] row;
    // Initialization
    tables = database.schemaManager.databaseObjectIterator(SchemaObject.TABLE);
    // Do it.
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (table.isView() && session.getGrantee().isFullyAccessibleByRole(table)) {
        // $FALL-THROUGH$
        } else {
            continue;
        }
        OrderedHashSet references = table.getReferences();
        for (int i = 0; i < references.size(); i++) {
            HsqlName refName = (HsqlName) references.get(i);
            if (!session.getGrantee().isFullyAccessibleByRole(refName)) {
                continue;
            }
            if (refName.type != SchemaObject.TABLE) {
                continue;
            }
            row = t.getEmptyRowData();
            row[view_catalog] = database.getCatalogName().name;
            row[view_schema] = table.getSchemaName().name;
            row[view_name] = table.getName().name;
            row[table_catalog] = database.getCatalogName().name;
            row[table_schema] = refName.schema.name;
            row[table_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) Constraint(org.hsqldb_voltpatches.Constraint) HsqlException(org.hsqldb_voltpatches.HsqlException)

Example 42 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 43 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 44 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 45 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)

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