Search in sources :

Example 6 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class Constraint method checkReferencedRows.

/**
     * Check used before creating a new foreign key cosntraint, this method
     * checks all rows of a table to ensure they all have a corresponding
     * row in the main table.
     */
void checkReferencedRows(Session session, Table table, int[] rowColArray) {
    Index mainIndex = getMainIndex();
    PersistentStore store = session.sessionData.getRowStore(table);
    RowIterator it = table.rowIterator(session);
    while (true) {
        Row row = it.getNextRow();
        if (row == null) {
            break;
        }
        Object[] rowData = row.getData();
        if (ArrayUtil.hasNull(rowData, rowColArray)) {
            if (core.matchType == OpTypes.MATCH_SIMPLE) {
                continue;
            }
        } else if (mainIndex.exists(session, store, rowData, rowColArray)) {
            continue;
        }
        if (ArrayUtil.hasAllNull(rowData, rowColArray)) {
            continue;
        }
        String colValues = "";
        for (int i = 0; i < rowColArray.length; i++) {
            Object o = rowData[rowColArray[i]];
            colValues += table.getColumnTypes()[i].convertToString(o);
            colValues += ",";
        }
        String[] info = new String[] { getName().name, getMain().getName().name };
        throw Error.error(ErrorCode.X_23502, ErrorCode.CONSTRAINT, info);
    }
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Index(org.hsqldb_voltpatches.index.Index)

Example 7 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class RowStoreAVLMemory method reindex.

/**
     * for result tables
     */
void reindex(Session session, Index index) {
    setAccessor(index, null);
    RowIterator it = table.rowIterator(session);
    while (it.hasNext()) {
        Row row = it.getNextRow();
        // may need to clear the node before insert
        index.insert(session, this, row);
    }
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) Row(org.hsqldb_voltpatches.Row)

Example 8 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator 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 9 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class RowStoreAVLMemory method dropIndexFromRows.

void dropIndexFromRows(Index primaryIndex, Index oldIndex) {
    RowIterator it = primaryIndex.firstRow(this);
    int position = oldIndex.getPosition() - 1;
    while (it.hasNext()) {
        Row row = it.getNextRow();
        int i = position - 1;
        NodeAVL backnode = ((RowAVL) row).getNode(0);
        while (i-- > 0) {
            backnode = backnode.nNext;
        }
        backnode.nNext = backnode.nNext.nNext;
    }
}
Also used : NodeAVL(org.hsqldb_voltpatches.index.NodeAVL) RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) Row(org.hsqldb_voltpatches.Row) RowAVL(org.hsqldb_voltpatches.RowAVL)

Example 10 with RowIterator

use of org.hsqldb_voltpatches.navigator.RowIterator in project voltdb by VoltDB.

the class RowStoreAVLHybrid method changeToDiskTable.

public void changeToDiskTable() {
    cache = session.sessionData.getResultCache();
    if (cache != null) {
        RowIterator iterator = table.rowIterator(this);
        ArrayUtil.fillArray(accessorList, null);
        isCached = true;
        cache.storeCount++;
        while (iterator.hasNext()) {
            Row row = iterator.getNextRow();
            Row newRow = (Row) getNewCachedObject(session, row.getData());
            indexRow(null, newRow);
        }
        rowIdMap.clear();
    }
    maxMemoryRowCount = Integer.MAX_VALUE;
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) Row(org.hsqldb_voltpatches.Row)

Aggregations

RowIterator (org.hsqldb_voltpatches.navigator.RowIterator)14 Row (org.hsqldb_voltpatches.Row)4 Index (org.hsqldb_voltpatches.index.Index)4 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)4 RowAVL (org.hsqldb_voltpatches.RowAVL)2 NodeAVL (org.hsqldb_voltpatches.index.NodeAVL)2 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2 IOException (java.io.IOException)1 HsqlException (org.hsqldb_voltpatches.HsqlException)1 Session (org.hsqldb_voltpatches.Session)1 Table (org.hsqldb_voltpatches.Table)1 DoubleIntIndex (org.hsqldb_voltpatches.lib.DoubleIntIndex)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 CachedObject (org.hsqldb_voltpatches.persist.CachedObject)1 RowOutputBinary (org.hsqldb_voltpatches.rowio.RowOutputBinary)1 RowOutputInterface (org.hsqldb_voltpatches.rowio.RowOutputInterface)1