Search in sources :

Example 81 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class TableBase method clearAllData.

public void clearAllData(Session session) {
    PersistentStore store = session.sessionData.getRowStore(this);
    store.removeAll();
}
Also used : PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Example 82 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class Table method updateRowSet.

void updateRowSet(Session session, HashMappedList rowSet, int[] cols, boolean isTriggeredSet) {
    boolean hasLob = false;
    PersistentStore store = session.sessionData.getRowStore(this);
    for (int i = 0; i < rowSet.size(); i++) {
        Row row = (Row) rowSet.getKey(i);
        if (row.isDeleted(session)) {
            if (isTriggeredSet) {
                rowSet.remove(i);
                i--;
                continue;
            } else {
                throw Error.error(ErrorCode.X_27000);
            }
        }
    }
    for (int i = 0; i < rowSet.size(); i++) {
        Row row = (Row) rowSet.getKey(i);
        Object[] data = (Object[]) rowSet.get(i);
        // todo - see if check is necessary ??
        checkRowData(session, data, cols);
        deleteNoCheck(session, row);
    }
    for (int i = 0; i < rowSet.size(); i++) {
        Object[] data = (Object[]) rowSet.get(i);
        insertNoCheck(session, store, data);
    }
}
Also used : PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) CachedObject(org.hsqldb_voltpatches.persist.CachedObject)

Example 83 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class Table method insertIntoTable.

/**
     * Multi-row insert method. Used for CREATE TABLE AS ... queries.
     */
void insertIntoTable(Session session, Result result) {
    PersistentStore store = session.sessionData.getRowStore(this);
    RowSetNavigator nav = result.initialiseNavigator();
    while (nav.hasNext()) {
        Object[] data = nav.getNext();
        Object[] newData = (Object[]) ArrayUtil.resizeArrayIfDifferent(data, getColumnCount());
        insertData(store, newData);
    }
}
Also used : PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) CachedObject(org.hsqldb_voltpatches.persist.CachedObject)

Example 84 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class StatementDML method executeMergeStatement.

/**
     * Executes a MERGE statement.  It is assumed that the argument
     * is of the correct type.
     *
     * @return Result object
     */
Result executeMergeStatement(Session session) {
    Result resultOut = null;
    RowSetNavigator generatedNavigator = null;
    PersistentStore store = session.sessionData.getRowStore(baseTable);
    if (generatedIndexes != null) {
        resultOut = Result.newUpdateCountResult(generatedResultMetaData, 0);
        generatedNavigator = resultOut.getChainedResult().getNavigator();
    }
    int count = 0;
    // data generated for non-matching rows
    RowSetNavigatorClient newData = new RowSetNavigatorClient(8);
    // rowset for update operation
    HashMappedList updateRowSet = new HashMappedList();
    RangeVariable[] joinRangeIterators = targetRangeVariables;
    // populate insert and update lists
    RangeIterator[] rangeIterators = new RangeIterator[joinRangeIterators.length];
    for (int i = 0; i < joinRangeIterators.length; i++) {
        rangeIterators[i] = joinRangeIterators[i].getIterator(session);
    }
    for (int currentIndex = 0; 0 <= currentIndex; ) {
        RangeIterator it = rangeIterators[currentIndex];
        boolean beforeFirst = it.isBeforeFirst();
        if (it.next()) {
            if (currentIndex < joinRangeIterators.length - 1) {
                currentIndex++;
                continue;
            }
        } else {
            if (currentIndex == 1 && beforeFirst) {
                Object[] data = getMergeInsertData(session);
                if (data != null) {
                    newData.add(data);
                }
            }
            it.reset();
            currentIndex--;
            continue;
        }
        // row matches!
        if (updateExpressions != null) {
            // this is always the second iterator
            Row row = it.getCurrentRow();
            Object[] data = getUpdatedData(session, baseTable, updateColumnMap, updateExpressions, baseTable.getColumnTypes(), row.getData());
            updateRowSet.add(row, data);
        }
    }
    // update any matched rows
    if (updateRowSet.size() > 0) {
        count = update(session, baseTable, updateRowSet);
    }
    // insert any non-matched rows
    newData.beforeFirst();
    while (newData.hasNext()) {
        Object[] data = newData.getNext();
        baseTable.insertRow(session, store, data);
        if (generatedNavigator != null) {
            Object[] generatedValues = getGeneratedColumns(data);
            generatedNavigator.add(generatedValues);
        }
    }
    baseTable.fireAfterTriggers(session, Trigger.INSERT_AFTER, newData);
    count += newData.getSize();
    if (resultOut == null) {
        return Result.getUpdateCountResult(count);
    } else {
        resultOut.setUpdateCount(count);
        return resultOut;
    }
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) RangeIterator(org.hsqldb_voltpatches.navigator.RangeIterator) RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Result(org.hsqldb_voltpatches.result.Result) RowSetNavigatorClient(org.hsqldb_voltpatches.navigator.RowSetNavigatorClient)

Example 85 with PersistentStore

use of org.hsqldb_voltpatches.persist.PersistentStore in project voltdb by VoltDB.

the class ScriptReaderBinary method readExistingData.

protected void readExistingData(Session session) throws IOException {
    for (; ; ) {
        String s = readTableInit();
        if (s == null) {
            break;
        }
        String schema = session.getSchemaName(currentSchema);
        Table t = db.schemaManager.getUserTable(session, s, schema);
        PersistentStore store = db.persistentStoreCollection.getStore(t);
        int j = 0;
        for (j = 0; ; j++) {
            if (!readRow(store, t)) {
                break;
            }
        }
        int checkCount = readTableTerm();
        if (j != checkCount) {
            throw Error.error(ErrorCode.ERROR_IN_SCRIPT_FILE, ErrorCode.M_ERROR_IN_BINARY_SCRIPT_1, new Object[] { s, new Integer(j), new Integer(checkCount) });
        }
    }
}
Also used : Table(org.hsqldb_voltpatches.Table) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore)

Aggregations

PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)103 Table (org.hsqldb_voltpatches.Table)74 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)73 SchemaObject (org.hsqldb_voltpatches.SchemaObject)59 Constraint (org.hsqldb_voltpatches.Constraint)57 TextTable (org.hsqldb_voltpatches.TextTable)56 Iterator (org.hsqldb_voltpatches.lib.Iterator)51 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)51 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)20 HsqlException (org.hsqldb_voltpatches.HsqlException)19 Session (org.hsqldb_voltpatches.Session)16 Result (org.hsqldb_voltpatches.result.Result)16 NumberType (org.hsqldb_voltpatches.types.NumberType)10 Grantee (org.hsqldb_voltpatches.rights.Grantee)8 Type (org.hsqldb_voltpatches.types.Type)8 Routine (org.hsqldb_voltpatches.Routine)7 RoutineSchema (org.hsqldb_voltpatches.RoutineSchema)7 CachedObject (org.hsqldb_voltpatches.persist.CachedObject)7 TriggerDef (org.hsqldb_voltpatches.TriggerDef)6 CharacterType (org.hsqldb_voltpatches.types.CharacterType)6