Package org.apache.openjpa.jdbc.sql

Examples of org.apache.openjpa.jdbc.sql.Row


        throws SQLException {
        OpenJPAStateManager em = store.getContext().getStateManager
            (sm.fetchObject(field.getIndex()));
        boolean newVal = em == null || em.getPCState() == PCState.ECOPY;

        Row row = null;
        if (newVal && field.getJoinForeignKey() != null
            && field.isJoinOuter()) {
            // if our record is in an outer-joined related table and we're not
            // updating an existing value, delete the old one
            Row del = rm.getRow(field.getTable(), Row.ACTION_DELETE, sm, true);
            del.whereForeignKey(field.getJoinForeignKey(), sm);
            delete(sm, null, store, rm, del);

            // insert the new value
            row = rm.getRow(field.getTable(), Row.ACTION_INSERT, sm,
                em != null);
View Full Code Here


        throws SQLException {
        OpenJPAStateManager em = null;
        if (sm.getLoaded().get(field.getIndex()))
            em = store.getContext().getStateManager(sm.fetchObject
                (field.getIndex()));
        Row row = field.getRow(sm, store, rm, Row.ACTION_DELETE);
        delete(sm, em, store, rm, row);
    }
View Full Code Here

        OpenJPAStateManager rel = RelationStrategies.getStateManager
            (sm.fetchObjectField(field.getIndex()), store.getContext());
        if (field.getJoinDirection() == field.JOIN_INVERSE)
            updateInverse(sm, rel, store, rm);
        else {
            Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
            if (row != null)
                field.setForeignKey(row, rel);
        }
    }
View Full Code Here

        if (field.getJoinDirection() == field.JOIN_INVERSE) {
            nullInverse(sm, rm);
            updateInverse(sm, rel, store, rm);
        } else {
            Row row = field.getRow(sm, store, rm, Row.ACTION_UPDATE);
            if (row != null)
                field.setForeignKey(row, rel);
        }
    }
View Full Code Here

            if (rel != null) {
                ForeignKey fk = field.getForeignKey((ClassMapping)
                    rel.getMetaData());
                if (fk.getDeleteAction() == ForeignKey.ACTION_RESTRICT ||
                    fk.getDeleteAction() == ForeignKey.ACTION_CASCADE) {
                    Row row = field.getRow(sm, store, rm, Row.ACTION_DELETE);
                    row.setForeignKey(fk, null, rel);
                }
            }
        }
    }
View Full Code Here

            return;

        // null inverse if not already enforced by fk
        if (field.getIndependentTypeMappings().length != 1)
            throw RelationStrategies.uninversable(field);
        Row row = rm.getAllRows(fk.getTable(), Row.ACTION_UPDATE);
        row.setForeignKey(fk, io, null);
        row.whereForeignKey(fk, sm);
        rm.flushAllRows(row);
    }
View Full Code Here

        if (field.getIndependentTypeMappings().length != 1)
            throw RelationStrategies.uninversable(field);

        // get the row for the inverse object; the row might be in a secondary
        // table if there is a field controlling the foreign key
        Row row = null;
        FieldMapping[] invs = field.getInverseMappings();
        for (int i = 0; i < invs.length; i++) {
            if (invs[i].getMappedByMetaData() == field
                && invs[i].getTypeCode() == JavaTypes.PC) {
                row = invs[i].getRow(rel, store, rm, action);
                break;
            }
        }
        ClassMapping relMapping = field.getTypeMapping();
        if (row == null)
            row = rm.getRow(relMapping.getTable(), action, rel, true);

        // if this is an update, this might be the only mod to the row, so
        // make sure the where condition is set
        if (action == Row.ACTION_UPDATE
            && row.getTable() == relMapping.getTable())
            row.wherePrimaryKey(rel);

        // update the inverse pointer with our oid value
        row.setForeignKey(fk, io, sm);
    }
View Full Code Here

        // loop through fields and update changing values for the next state
        // image, plus add WHERE conditions on updates to make sure that
        // db values match our previous image
        FieldMapping[] fields = (FieldMapping[]) sm.getMetaData().getFields();
        Row row;
        if (sm.isVersionCheckRequired()) {
            for (int i = 0, max = loaded.length(); i < max; i++) {
                if (!loaded.get(i))
                    continue;

                // update our next state image with the new field value
                if (sm.getDirty().get(i) && !sm.getFlushed().get(i))
                    nextState[i] = sm.fetch(fields[i].getIndex());

                // fetch the row for this field; if no row exists, then we can't
                // add one because we have no updates to perform; that means we
                // won't detect OL exceptions when another transaction changes
                // fields that aren't in any of the same tables as fields that
                // this transaction changed
                row = rm.getRow(fields[i].getTable(), Row.ACTION_UPDATE,
                    sm, false);
                if (row == null)
                    continue;

                // set WHERE criteria matching the previous state image so the
                // update will fail for any changes made by another transaction
                fields[i].where(sm, store, rm, state[i]);
                row.setFailedObject(sm.getManagedInstance());
            }
        }
        sm.setNextVersion(nextState);
    }
View Full Code Here

        throws SQLException {
        Collection coll = toCollection(vals);
        if (coll == null || coll.isEmpty())
            return;

        Row row = rm.getSecondaryRow(field.getTable(), Row.ACTION_INSERT);
        row.setForeignKey(field.getJoinForeignKey(), field.getJoinColumnIO(),
            sm);

        ValueMapping elem = field.getElementMapping();
        StoreContext ctx = sm.getContext();
        Column order = field.getOrderColumn();
        boolean setOrder = field.getOrderColumnIO().isInsertable(order, false);
        int idx = 0;
        OpenJPAStateManager esm;
        for (Iterator itr = coll.iterator(); itr.hasNext(); idx++) {
            esm = RelationStrategies.getStateManager(itr.next(), ctx);
            elem.setForeignKey(row, esm);
            if (setOrder)
                row.setInt(order, idx);
            rm.flushSecondaryRow(row);
        }
    }
View Full Code Here

        OpenJPAStateManager esm;

        // delete the removes
        Collection rem = ct.getRemoved();
        if (!rem.isEmpty()) {
            Row delRow = rm.getSecondaryRow(field.getTable(),
                Row.ACTION_DELETE);
            delRow.whereForeignKey(field.getJoinForeignKey(), sm);

            for (Iterator itr = rem.iterator(); itr.hasNext();) {
                esm = RelationStrategies.getStateManager(itr.next(), ctx);
                elem.whereForeignKey(delRow, esm);
                rm.flushSecondaryRow(delRow);
            }
        }

        // insert the adds
        Collection add = ct.getAdded();
        if (!add.isEmpty()) {
            Row addRow = rm.getSecondaryRow(field.getTable(),
                Row.ACTION_INSERT);
            addRow.setForeignKey(field.getJoinForeignKey(),
                field.getJoinColumnIO(), sm);

            int seq = ct.getNextSequence();
            Column order = field.getOrderColumn();
            boolean setOrder = field.getOrderColumnIO().isInsertable(order,
                false);
            for (Iterator itr = add.iterator(); itr.hasNext(); seq++) {
                esm = RelationStrategies.getStateManager(itr.next(), ctx);
                elem.setForeignKey(addRow, esm);
                if (setOrder)
                    addRow.setInt(order, seq);
                rm.flushSecondaryRow(addRow);
            }
            if (order != null)
                ct.setNextSequence(seq);
        }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.sql.Row

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.