Search in sources :

Example 1 with HashMappedList

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

the class StatementDML method delete.

/**
     *  Highest level multiple row delete method. Corresponds to an SQL
     *  DELETE.
     */
int delete(Session session, Table table, RowSetNavigator oldRows) {
    if (table.fkMainConstraints.length == 0) {
        deleteRows(session, table, oldRows);
        oldRows.beforeFirst();
        if (table.hasTrigger(Trigger.DELETE_AFTER)) {
            table.fireAfterTriggers(session, Trigger.DELETE_AFTER, oldRows);
        }
        return oldRows.getSize();
    }
    HashSet path = session.sessionContext.getConstraintPath();
    HashMappedList tableUpdateList = session.sessionContext.getTableUpdateList();
    if (session.database.isReferentialIntegrity()) {
        oldRows.beforeFirst();
        while (oldRows.hasNext()) {
            oldRows.next();
            Row row = oldRows.getCurrentRow();
            path.clear();
            checkCascadeDelete(session, table, tableUpdateList, row, false, path);
        }
    }
    if (session.database.isReferentialIntegrity()) {
        oldRows.beforeFirst();
        while (oldRows.hasNext()) {
            oldRows.next();
            Row row = oldRows.getCurrentRow();
            path.clear();
            checkCascadeDelete(session, table, tableUpdateList, row, true, path);
        }
    }
    oldRows.beforeFirst();
    while (oldRows.hasNext()) {
        oldRows.next();
        Row row = oldRows.getCurrentRow();
        if (!row.isDeleted(session)) {
            table.deleteNoRefCheck(session, row);
        }
    }
    for (int i = 0; i < tableUpdateList.size(); i++) {
        Table targetTable = (Table) tableUpdateList.getKey(i);
        HashMappedList updateList = (HashMappedList) tableUpdateList.get(i);
        if (updateList.size() > 0) {
            targetTable.updateRowSet(session, updateList, null, true);
            updateList.clear();
        }
    }
    oldRows.beforeFirst();
    if (table.hasTrigger(Trigger.DELETE_AFTER)) {
        table.fireAfterTriggers(session, Trigger.DELETE_AFTER, oldRows);
    }
    path.clear();
    return oldRows.getSize();
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) HashSet(org.hsqldb_voltpatches.lib.HashSet) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 2 with HashMappedList

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

the class StatementDML method executeUpdateStatement.

/**
     * Executes an UPDATE statement.  It is assumed that the argument
     * is of the correct type.
     *
     * @return the result of executing the statement
     */
Result executeUpdateStatement(Session session) {
    int count = 0;
    Expression[] colExpressions = updateExpressions;
    HashMappedList rowset = new HashMappedList();
    Type[] colTypes = baseTable.getColumnTypes();
    RangeIteratorBase it = RangeVariable.getIterator(session, targetRangeVariables);
    Expression checkCondition = null;
    if (targetTable != baseTable) {
        checkCondition = ((TableDerived) targetTable).getQueryExpression().getMainSelect().checkQueryCondition;
    }
    while (it.next()) {
        session.sessionData.startRowProcessing();
        Row row = it.getCurrentRow();
        Object[] data = row.getData();
        Object[] newData = getUpdatedData(session, baseTable, updateColumnMap, colExpressions, colTypes, data);
        if (checkCondition != null) {
            it.currentData = newData;
            boolean check = checkCondition.testCondition(session);
            if (!check) {
                throw Error.error(ErrorCode.X_44000);
            }
        }
        rowset.add(row, newData);
    }
    /* debug 190
        if (rowset.size() == 0) {
            System.out.println(targetTable.getName().name + " zero update: session "
                               + session.getId());
        } else if (rowset.size() >1) {
           System.out.println("multiple update: session "
                              + session.getId() + ", " + rowset.size());
       }

//* debug 190 */
    count = update(session, baseTable, rowset);
    return Result.getUpdateCountResult(count);
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) Type(org.hsqldb_voltpatches.types.Type) RangeIteratorBase(org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)

Example 3 with HashMappedList

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

the class StatementDML method update.

/**
     * Highest level multiple row update method. Corresponds to an SQL UPDATE.
     * To deal with unique constraints we need to perform all deletes at once
     * before the inserts. If there is a UNIQUE constraint violation limited
     * only to the duration of updating multiple rows, we don't want to abort
     * the operation. Example: UPDATE MYTABLE SET UNIQUECOL = UNIQUECOL + 1
     * After performing each cascade update, delete the main row. After all
     * cascade ops and deletes have been performed, insert new rows.<p>
     *
     * Following clauses from SQL Standard section 11.8 are enforced 9) Let ISS
     * be the innermost SQL-statement being executed. 10) If evaluation of these
     * General Rules during the execution of ISS would cause an update of some
     * site to a value that is distinct from the value to which that site was
     * previously updated during the execution of ISS, then an exception
     * condition is raised: triggered data change violation. 11) If evaluation
     * of these General Rules during the execution of ISS would cause deletion
     * of a row containing a site that is identified for replacement in that
     * row, then an exception condition is raised: triggered data change
     * violation. (fredt)
     *
     * @param session Session
     * @param table Table
     * @param updateList HashMappedList
     * @return int
     */
int update(Session session, Table table, HashMappedList updateList) {
    HashSet path = session.sessionContext.getConstraintPath();
    HashMappedList tableUpdateList = session.sessionContext.getTableUpdateList();
    // set identity column where null and check columns
    for (int i = 0; i < updateList.size(); i++) {
        Row row = (Row) updateList.getKey(i);
        Object[] data = (Object[]) updateList.get(i);
        /**
             * @todo 1.9.0 - make optional using database property - this means the identity column can be set to null to force
             * creation of a new identity value
             */
        table.setIdentityColumn(session, data);
        if (table.triggerLists[Trigger.UPDATE_BEFORE].length != 0) {
            table.fireBeforeTriggers(session, Trigger.UPDATE_BEFORE, row.getData(), data, updateColumnMap);
        }
        table.enforceRowConstraints(session, data);
    }
    if (table.isView) {
        return updateList.size();
    }
    // perform check/cascade operations
    if (session.database.isReferentialIntegrity()) {
        for (int i = 0; i < updateList.size(); i++) {
            Object[] data = (Object[]) updateList.get(i);
            Row row = (Row) updateList.getKey(i);
            checkCascadeUpdate(session, table, tableUpdateList, row, data, updateColumnMap, null, path);
        }
    }
    // merge any triggered change to this table with the update list
    HashMappedList triggeredList = (HashMappedList) tableUpdateList.get(table);
    if (triggeredList != null) {
        for (int i = 0; i < triggeredList.size(); i++) {
            Row row = (Row) triggeredList.getKey(i);
            Object[] data = (Object[]) triggeredList.get(i);
            mergeKeepUpdate(session, updateList, updateColumnMap, table.colTypes, row, data);
        }
        triggeredList.clear();
    }
    // update lists - main list last
    for (int i = 0; i < tableUpdateList.size(); i++) {
        Table targetTable = (Table) tableUpdateList.getKey(i);
        HashMappedList updateListT = (HashMappedList) tableUpdateList.get(i);
        targetTable.updateRowSet(session, updateListT, null, true);
        updateListT.clear();
    }
    table.updateRowSet(session, updateList, updateColumnMap, false);
    path.clear();
    return updateList.size();
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) HashSet(org.hsqldb_voltpatches.lib.HashSet) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet)

Example 4 with HashMappedList

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

the class StatementResultUpdate method getResult.

Result getResult(Session session) {
    checkAccessRights(session);
    Object[] args = session.sessionContext.dynamicArguments;
    switch(actionType) {
        case ResultConstants.UPDATE_CURSOR:
            {
                Long id = (Long) args[args.length - 1];
                PersistentStore store = session.sessionData.getRowStore(baseTable);
                Row row = (Row) store.get((int) id.longValue(), false);
                HashMappedList list = new HashMappedList();
                Object[] data = (Object[]) ArrayUtil.duplicateArray(row.getData());
                for (int i = 0; i < baseColumnMap.length; i++) {
                    if (types[i] == Type.SQL_ALL_TYPES) {
                        continue;
                    }
                    data[baseColumnMap[i]] = args[i];
                }
                list.add(row, data);
                update(session, baseTable, list);
                break;
            }
        case ResultConstants.DELETE_CURSOR:
            {
                Long id = (Long) args[args.length - 1];
                PersistentStore store = session.sessionData.getRowStore(baseTable);
                Row row = (Row) store.get((int) id.longValue(), false);
                RowSetNavigator navigator = new RowSetNavigatorLinkedList();
                navigator.add(row);
                delete(session, baseTable, navigator);
                break;
            }
        case ResultConstants.INSERT_CURSOR:
            {
                Object[] data = baseTable.getNewRowData(session);
                for (int i = 0; i < data.length; i++) {
                    data[baseColumnMap[i]] = args[i];
                }
                PersistentStore store = session.sessionData.getRowStore(baseTable);
                baseTable.insertRow(session, store, data);
            }
    }
    return Result.updateOneResult;
}
Also used : RowSetNavigatorLinkedList(org.hsqldb_voltpatches.navigator.RowSetNavigatorLinkedList) HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator)

Example 5 with HashMappedList

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

the class StatementCompound method setVariables.

//
private void setVariables() {
    if (variables.length == 0) {
        if (parent == null) {
            rangeVariables = root.getParameterRangeVariables();
        } else {
            rangeVariables = parent.rangeVariables;
        }
        return;
    }
    HashMappedList list = new HashMappedList();
    if (parent != null) {
        for (int i = 0; i < parent.scopeVariables.size(); i++) {
            list.add(parent.scopeVariables.getKey(i), parent.scopeVariables.get(i));
        }
    }
    for (int i = 0; i < variables.length; i++) {
        String name = variables[i].getName().name;
        boolean added = list.add(name, variables[i]);
        if (!added) {
            throw Error.error(ErrorCode.X_42606, name);
        }
        if (root.getParameterIndex(name) != -1) {
            throw Error.error(ErrorCode.X_42606, name);
        }
    }
    RangeVariable range = new RangeVariable(list, true);
    rangeVariables = new RangeVariable[] { root.getParameterRangeVariables()[0], range };
    root.variableCount = list.size();
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList)

Aggregations

HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)23 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)4 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)4 HashSet (org.hsqldb_voltpatches.lib.HashSet)3 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)3 Index (org.hsqldb_voltpatches.index.Index)2 Iterator (org.hsqldb_voltpatches.lib.Iterator)2 RowIterator (org.hsqldb_voltpatches.navigator.RowIterator)2 RowSetNavigator (org.hsqldb_voltpatches.navigator.RowSetNavigator)2 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)2 Result (org.hsqldb_voltpatches.result.Result)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 HashSet (java.util.HashSet)1 HsqlException (org.hsqldb_voltpatches.HsqlException)1 SimpleName (org.hsqldb_voltpatches.HsqlNameManager.SimpleName)1 RangeIteratorBase (org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)1