Search in sources :

Example 46 with Iterator

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

the class TransactionManager method getTransactionIDList.

/**
     * Return a lookup of all row ids for cached tables in transactions.
     * For auto-defrag, as currently there will be no RowAction entries
     * at the time of defrag.
     */
public DoubleIntIndex getTransactionIDList() {
    writeLock.lock();
    try {
        DoubleIntIndex lookup = new DoubleIntIndex(10, false);
        lookup.setKeysSearchTarget();
        Iterator it = this.rowActionMap.keySet().iterator();
        for (; it.hasNext(); ) {
            lookup.addUnique(it.nextInt(), 0);
        }
        return lookup;
    } finally {
        writeLock.unlock();
    }
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator) DoubleIntIndex(org.hsqldb_voltpatches.lib.DoubleIntIndex)

Example 47 with Iterator

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

the class TransactionManager method convertTransactionIDs.

/**
     * Convert row ID's for cached table rows in transactions
     */
public void convertTransactionIDs(DoubleIntIndex lookup) {
    writeLock.lock();
    try {
        RowAction[] list = new RowAction[rowActionMap.size()];
        Iterator it = this.rowActionMap.values().iterator();
        for (int i = 0; it.hasNext(); i++) {
            list[i] = (RowAction) it.next();
        }
        rowActionMap.clear();
        for (int i = 0; i < list.length; i++) {
            int pos = lookup.lookupFirstEqual(list[i].getPos());
            list[i].setPos(pos);
            rowActionMap.put(pos, list[i]);
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : Iterator(org.hsqldb_voltpatches.lib.Iterator)

Example 48 with Iterator

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

the class QuerySpecification method resolveExpressionTypes.

/**
     * Sets the types of all the expressions used in this SELECT list.
     */
public void resolveExpressionTypes(Session session) {
    for (int i = 0; i < indexStartAggregates; i++) {
        Expression e = exprColumns[i];
        e.resolveTypes(session, null);
        if (e.getType() == OpTypes.ROW) {
            throw Error.error(ErrorCode.X_42564);
        }
    }
    for (int i = 0, len = rangeVariables.length; i < len; i++) {
        Expression e = rangeVariables[i].nonIndexJoinCondition;
        if (e != null) {
            e.resolveTypes(session, null);
            if (e.getDataType() != Type.SQL_BOOLEAN) {
                throw Error.error(ErrorCode.X_42568);
            }
        }
    }
    if (queryCondition != null) {
        queryCondition.resolveTypes(session, null);
        if (queryCondition.getDataType() != Type.SQL_BOOLEAN) {
            throw Error.error(ErrorCode.X_42568);
        }
        if (queryCondition.opType == OpTypes.VALUE) {
            if (!((boolean) queryCondition.valueData)) {
                // WHERE false => LIMIT 0
                SortAndSlice sortAndSlice = new SortAndSlice();
                ExpressionValue limit0 = new ExpressionValue(ValuePool.INTEGER_0, Type.SQL_INTEGER);
                ExpressionValue offset = new ExpressionValue(ValuePool.INTEGER_0, Type.SQL_INTEGER);
                sortAndSlice.addLimitCondition(new ExpressionOp(OpTypes.LIMIT, offset, limit0));
                addSortAndSlice(sortAndSlice);
            }
            // Leave out the original WHERE condition no matter it is WHERE true or WHERE false.
            queryCondition = null;
        } else {
            // A VoltDB extension to guard against abuse of aggregates in subqueries.
            // Make sure no aggregates in WHERE clause
            tempSet.clear();
            Expression.collectAllExpressions(tempSet, queryCondition, Expression.aggregateFunctionSet, Expression.subqueryExpressionSet);
            if (!tempSet.isEmpty()) {
                // two error messages for two different unsupported cases.
                if (!isTopLevel) {
                    HsqlList columnSet = new OrderedHashSet();
                    Iterator aggIt = tempSet.iterator();
                    while (aggIt.hasNext()) {
                        Expression nextAggr = (Expression) aggIt.next();
                        Expression.collectAllExpressions(columnSet, nextAggr, Expression.columnExpressionSet, Expression.emptyExpressionSet);
                    }
                    Iterator columnIt = columnSet.iterator();
                    while (columnIt.hasNext()) {
                        Expression nextColumn = (Expression) columnIt.next();
                        assert (nextColumn instanceof ExpressionColumn);
                        ExpressionColumn nextColumnEx = (ExpressionColumn) nextColumn;
                        String tableName = nextColumnEx.rangeVariable.rangeTable.tableName.name;
                        String tableAlias = (nextColumnEx.rangeVariable.tableAlias != null) ? nextColumnEx.rangeVariable.tableAlias.name : null;
                        boolean resolved = false;
                        for (RangeVariable rv : rangeVariables) {
                            if (rv.rangeTable.tableName.name.equals(tableName)) {
                                if (rv.tableAlias == null && tableAlias == null) {
                                    resolved = true;
                                } else if (rv.tableAlias != null && tableAlias != null) {
                                    resolved = tableAlias.equals(rv.tableAlias.name);
                                }
                            }
                        }
                        if (!resolved) {
                            throw Error.error(ErrorCode.X_47001);
                        }
                    }
                }
                // with local columns
                throw Error.error(ErrorCode.X_47000);
            }
        // End of VoltDB extension
        }
    }
    if (havingCondition != null) {
        havingCondition.resolveTypes(session, null);
        if (havingCondition.getDataType() != Type.SQL_BOOLEAN) {
            throw Error.error(ErrorCode.X_42568);
        }
    }
}
Also used : RangeIterator(org.hsqldb_voltpatches.navigator.RangeIterator) Iterator(org.hsqldb_voltpatches.lib.Iterator) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlList(org.hsqldb_voltpatches.lib.HsqlList)

Example 49 with Iterator

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

the class DatabaseInformationMain method SYSTEM_TABLES.

/**
     * Retrieves a <code>Table</code> object describing the accessible
     * tables defined within this database. <p>
     *
     * Each row is a table description with the following columns: <p>
     *
     * <pre class="SqlCodeExample">
     * TABLE_CAT                 VARCHAR   table catalog
     * TABLE_SCHEM               VARCHAR   table schema
     * TABLE_NAME                VARCHAR   table name
     * TABLE_TYPE                VARCHAR   {"TABLE" | "VIEW" |
     *                                      "SYSTEM TABLE" | "GLOBAL TEMPORARY"}
     * REMARKS                   VARCHAR   comment on the table.
     * TYPE_CAT                  VARCHAR   table type catalog (not implemented).
     * TYPE_SCHEM                VARCHAR   table type schema (not implemented).
     * TYPE_NAME                 VARCHAR   table type name (not implemented).
     * SELF_REFERENCING_COL_NAME VARCHAR   designated "identifier" column of
     *                                     typed table (not implemented).
     * REF_GENERATION            VARCHAR   {"SYSTEM" | "USER" |
     *                                      "DERIVED" | NULL } (not implemented)
     * HSQLDB_TYPE               VARCHAR   HSQLDB-specific type:
     *                                     {"MEMORY" | "CACHED" | "TEXT" | ...}
     * READ_ONLY                 BOOLEAN   TRUE if table is read-only,
     *                                     else FALSE.
     * COMMIT_ACTION             VARCHAR   "PRESERVE" or "DELETE" for temp tables,
     *                                     else NULL
     * </pre> <p>
     *
     * @return a <code>Table</code> object describing the accessible
     *      tables defined within this database
     */
final Table SYSTEM_TABLES() {
    Table t = sysTables[SYSTEM_TABLES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_TABLES]);
        // -------------------------------------------------------------
        // required
        // -------------------------------------------------------------
        addColumn(t, "TABLE_CAT", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEM", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_TYPE", CHARACTER_DATA);
        addColumn(t, "REMARKS", CHARACTER_DATA);
        // -------------------------------------------------------------
        // JDBC 3.0
        // -------------------------------------------------------------
        addColumn(t, "TYPE_CAT", SQL_IDENTIFIER);
        addColumn(t, "TYPE_SCHEM", SQL_IDENTIFIER);
        addColumn(t, "TYPE_NAME", SQL_IDENTIFIER);
        addColumn(t, "SELF_REFERENCING_COL_NAME", SQL_IDENTIFIER);
        addColumn(t, "REF_GENERATION", CHARACTER_DATA);
        // -------------------------------------------------------------
        // extended
        // ------------------------------------------------------------
        addColumn(t, "HSQLDB_TYPE", SQL_IDENTIFIER);
        // not null
        addColumn(t, "READ_ONLY", Type.SQL_BOOLEAN);
        // not null
        addColumn(t, "COMMIT_ACTION", CHARACTER_DATA);
        // ------------------------------------------------------------
        // order TABLE_TYPE, TABLE_SCHEM and TABLE_NAME
        // added for unique: TABLE_CAT
        // false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_TABLES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 3, 1, 2, 0 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // intermediate holders
    Iterator tables;
    Table table;
    Object[] row;
    HsqlName accessKey;
    DITableInfo ti;
    // column number mappings
    // JDBC 1
    final int itable_cat = 0;
    final int itable_schem = 1;
    final int itable_name = 2;
    final int itable_type = 3;
    final int iremark = 4;
    // JDBC 3.0
    final int itype_cat = 5;
    final int itype_schem = 6;
    final int itype_name = 7;
    final int isref_cname = 8;
    final int iref_gen = 9;
    // hsqldb ext
    final int ihsqldb_type = 10;
    final int iread_only = 11;
    final int icommit_action = 12;
    // Initialization
    tables = allTables();
    ti = new DITableInfo();
    // Do it.
    while (tables.hasNext()) {
        table = (Table) tables.next();
        if (!isAccessibleTable(table)) {
            continue;
        }
        ti.setTable(table);
        row = t.getEmptyRowData();
        row[itable_cat] = database.getCatalogName().name;
        row[itable_schem] = table.getSchemaName().name;
        row[itable_name] = ti.getName();
        row[itable_type] = ti.getJDBCStandardType();
        row[iremark] = ti.getRemark();
        row[ihsqldb_type] = ti.getHsqlType();
        row[iread_only] = ti.isReadOnly();
        row[icommit_action] = table.isTemp() ? (table.onCommitPreserve() ? "PRESERVE" : "DELETE") : null;
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Example 50 with Iterator

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

the class DatabaseInformationMain method SYSTEM_SEQUENCES.

final Table SYSTEM_SEQUENCES() {
    Table t = sysTables[SYSTEM_SEQUENCES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_SEQUENCES]);
        addColumn(t, "SEQUENCE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "SEQUENCE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "SEQUENCE_NAME", SQL_IDENTIFIER);
        addColumn(t, "DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
        addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
        addColumn(t, "MAXIMUM_VALUE", CHARACTER_DATA);
        addColumn(t, "MINIMUM_VALUE", CHARACTER_DATA);
        addColumn(t, "INCREMENT", CHARACTER_DATA);
        addColumn(t, "CYCLE_OPTION", YES_OR_NO);
        addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
        addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
        addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
        // HSQLDB-specific
        addColumn(t, "START_WITH", CHARACTER_DATA);
        addColumn(t, "NEXT_VALUE", CHARACTER_DATA);
        // order SEQUENCE_CATALOG, SEQUENCE_SCHEMA, SEQUENCE_NAME
        // false PK, as CATALOG may be null
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_SEQUENCES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    //
    final int sequence_catalog = 0;
    final int sequence_schema = 1;
    final int sequence_name = 2;
    final int data_type = 3;
    final int numeric_precision = 4;
    final int numeric_precision_radix = 5;
    final int numeric_scale = 6;
    final int maximum_value = 7;
    final int minimum_value = 8;
    final int increment = 9;
    final int cycle_option = 10;
    final int declared_data_type = 11;
    final int declared_numeric_precision = 12;
    final int declared_numeric_scale = 13;
    final int start_with = 14;
    final int next_value = 15;
    //
    Iterator it;
    Object[] row;
    NumberSequence sequence;
    it = database.schemaManager.databaseObjectIterator(SchemaObject.SEQUENCE);
    while (it.hasNext()) {
        sequence = (NumberSequence) it.next();
        if (!session.getGrantee().isAccessible(sequence)) {
            continue;
        }
        row = t.getEmptyRowData();
        NumberType type = (NumberType) sequence.getDataType();
        int radix = (type.typeCode == Types.SQL_NUMERIC || type.typeCode == Types.SQL_DECIMAL) ? 10 : 2;
        row[sequence_catalog] = database.getCatalogName().name;
        row[sequence_schema] = sequence.getSchemaName().name;
        row[sequence_name] = sequence.getName().name;
        row[data_type] = sequence.getDataType().getFullNameString();
        row[numeric_precision] = ValuePool.getInt((int) type.getPrecision());
        row[numeric_precision_radix] = ValuePool.getInt(radix);
        row[numeric_scale] = ValuePool.INTEGER_0;
        row[maximum_value] = String.valueOf(sequence.getMaxValue());
        row[minimum_value] = String.valueOf(sequence.getMinValue());
        row[increment] = String.valueOf(sequence.getIncrement());
        row[cycle_option] = sequence.isCycle() ? "YES" : "NO";
        row[declared_data_type] = row[data_type];
        row[declared_numeric_precision] = row[numeric_precision];
        row[declared_numeric_scale] = row[declared_numeric_scale];
        row[start_with] = String.valueOf(sequence.getStartValue());
        row[next_value] = String.valueOf(sequence.peek());
        t.insertSys(store, row);
    }
    return t;
}
Also used : NumberType(org.hsqldb_voltpatches.types.NumberType) Table(org.hsqldb_voltpatches.Table) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) NumberSequence(org.hsqldb_voltpatches.NumberSequence) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Aggregations

Iterator (org.hsqldb_voltpatches.lib.Iterator)102 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)74 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)64 SchemaObject (org.hsqldb_voltpatches.SchemaObject)57 Table (org.hsqldb_voltpatches.Table)55 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)51 Constraint (org.hsqldb_voltpatches.Constraint)50 TextTable (org.hsqldb_voltpatches.TextTable)39 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)28 HsqlException (org.hsqldb_voltpatches.HsqlException)18 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)14 NumberType (org.hsqldb_voltpatches.types.NumberType)10 HashSet (org.hsqldb_voltpatches.lib.HashSet)9 Type (org.hsqldb_voltpatches.types.Type)9 Grantee (org.hsqldb_voltpatches.rights.Grantee)8 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6 IntervalType (org.hsqldb_voltpatches.types.IntervalType)6