Package org.apache.openjpa.jdbc.sql

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


        }

        // first construct the graph for deletes; this may expand to include
        // inserts and updates as well if there are any inserts that rely on
        // deletes (delete-then-insert-same-pk cases)
        PrimaryRow row;
        Row row2;
        ForeignKey[] fks;
        OpenJPAStateManager fkVal;
        boolean ignoreUpdates = true;
        for (Iterator itr = deletes.iterator(); itr.hasNext();) {
            row = (PrimaryRow) itr.next();
            if (!row.isValid())
                continue;

            row2 = getInsertRow(insertMap, rowMgr, row);
            if (row2 != null) {
                ignoreUpdates = false;
                graphs[1] = addEdge(graphs[1], (PrimaryRow) row2, row, null);
            }

            // now check this row's fks against other deletes
            fks = row.getTable().getForeignKeys();
            for (int j = 0; j < fks.length; j++) {
                // when deleting ref fks they'll just set a where value, so
                // check both for fk updates (relation fks) and wheres (ref fks)
                fkVal = row.getForeignKeySet(fks[j]);
                if (fkVal == null)
                    fkVal = row.getForeignKeyWhere(fks[j]);
                if (fkVal == null)
                    continue;

                row2 = rowMgr.getRow(fks[j].getPrimaryKeyTable(),
                    Row.ACTION_DELETE, fkVal, false);
View Full Code Here


     * Analyze the given rows against the inserts, placing dependencies
     * in the given graph.
     */
    private Graph analyzeAgainstInserts(Collection rows, RowManagerImpl rowMgr,
        Graph graph) {
        PrimaryRow row;
        Row row2;
        ForeignKey[] fks;
        Column[] cols;
        for (Iterator itr = rows.iterator(); itr.hasNext();) {
            row = (PrimaryRow) itr.next();
            if (!row.isValid())
                continue;

            // check this row's fks against inserts; a logical fk to an auto-inc
            // column is treated just as actual database fk because the result
            // is the same: the pk row has to be inserted before the fk row
            fks = row.getTable().getForeignKeys();
            for (int j = 0; j < fks.length; j++) {
                if (row.getForeignKeySet(fks[j]) == null)
                    continue;

                // see if this row is dependent on another.  if it's only
                // depenent on itself, see if the fk is logical or deferred, in
                // which case it must be an auto-inc because otherwise we
                // wouldn't have recorded it
                row2 = rowMgr.getRow(fks[j].getPrimaryKeyTable(),
                    Row.ACTION_INSERT, row.getForeignKeySet(fks[j]), false);
                if (row2 != null && row2.isValid() && (row2 != row
                    || fks[j].isDeferred() || fks[j].isLogical()))
                    graph = addEdge(graph, row, (PrimaryRow) row2, fks[j]);
            }

            // see if there are any relation id columns dependent on
            // auto-inc objects
            cols = row.getTable().getRelationIdColumns();
            for (int j = 0; j < cols.length; j++) {
                OpenJPAStateManager sm = row.getRelationIdSet(cols[j]);
                if (sm == null)
                    continue;

                row2 = rowMgr.getRow(getBaseTable(sm), Row.ACTION_INSERT,
                    sm, false);
View Full Code Here

     * @param deleteUpdates Collection of update statements that are executed
     * before the delete operations are flushed
     */
    private void addDeleteUpdate(Edge edge, Collection deleteUpdates)
        throws SQLException {
        PrimaryRow row;
        RowImpl update;
        ForeignKey fk;

        // copy where conditions into new update that nulls the fk
        row = (PrimaryRow) edge.getTo();
        update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null);
        row.copyInto(update, true);
        if (edge.getUserObject() instanceof ForeignKey) {
            fk = (ForeignKey) edge.getUserObject();
            update.setForeignKey(fk, row.getForeignKeyIO(fk), null);
        } else
            update.setNull((Column) edge.getUserObject());

        deleteUpdates.add(update);
    }
View Full Code Here

        if (!row.isValid())
            return updates;

        ForeignKey[] fks = row.getTable().getForeignKeys();
        OpenJPAStateManager sm;
        PrimaryRow rel;
        RowImpl update;
        for (int i = 0; i < fks.length; i++) {
            // when deleting ref fks we set the where value instead
            sm = row.getForeignKeySet(fks[i]);
            if (sm == null)
                sm = row.getForeignKeyWhere(fks[i]);
            if (sm == null)
                continue;

            // only need an update if we have an fk to a row that's being
            // deleted before we are
            rel = (PrimaryRow) rowMgr.getRow(fks[i].getPrimaryKeyTable(),
                Row.ACTION_DELETE, sm, false);
            if (rel == null || !rel.isValid()
                || rel.getIndex() >= row.getIndex())
                continue;

            // create an update to null the offending fk before deleting.  use
            // a primary row to be sure to copy delayed-flush pks/fks
            update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null);
            row.copyInto(update, true);
            update.setForeignKey(fks[i], row.getForeignKeyIO(fks[i]), null);
            if (updates == null)
                updates = new ArrayList();
            updates.add(update);
View Full Code Here

            return updates;
        }

        ForeignKey[] fks = row.getTable().getForeignKeys();
        OpenJPAStateManager sm;
        PrimaryRow rel;
        PrimaryRow update;
        for (int i = 0; i < fks.length; i++) {
            sm = row.getForeignKeySet(fks[i]);
            if (sm == null)
                continue;

            // only need an update if we have an fk to a row that's being
            // inserted after we are; if row is dependent on itself and no
            // fk, must be an auto-inc because otherwise we wouldn't have
            // recorded it
            rel = (PrimaryRow) rowMgr.getRow(fks[i].getPrimaryKeyTable(),
                Row.ACTION_INSERT, sm, false);
            if (rel == null || !rel.isValid()
                || rel.getIndex() < row.getIndex()
                || (rel == row && !fks[i].isDeferred() && !fks[i].isLogical()))
                continue;

            // don't insert or update with the given fk; create a deferred
            // update for after the rel row has been inserted; use a primary row
            // to prevent setting values until after flush to get auto-inc
            update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null);
            if (row.getAction() == Row.ACTION_INSERT)
                update.wherePrimaryKey(row.getPrimaryKey());
            else
                row.copyInto(update, true);
            update.setForeignKey(fks[i], row.getForeignKeyIO(fks[i]), sm);
            row.clearForeignKey(fks[i]);

            if (updates == null)
                updates = new ArrayList();
            updates.add(update);
View Full Code Here

        RowImpl update;
        ForeignKey fk;
        Column col;

        // copy where conditions into new update that sets the fk
        update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null);
        if (row.getAction() == Row.ACTION_INSERT) {
            if (row.getPrimaryKey() == null)
                throw new InternalException(_loc.get("ref-cycle"));
            update.wherePrimaryKey(row.getPrimaryKey());
        } else {
View Full Code Here

                if (!breakableLink.isRemovedFromGraph()) {

                    // use a primary row update to prevent setting pk and fk
                    // values until after flush, to get latest auto-increment
                    // values
                    PrimaryRow row = (PrimaryRow) breakableLink.getFrom();
                    if (row.getAction() == Row.ACTION_DELETE) {
                        addDeleteUpdate(breakableLink, deleteUpdates);
                    } else {
                        addInsertUpdate(row, breakableLink, insertUpdates);
                    }
                    graph.removeEdge(breakableLink);
View Full Code Here

        }

        // first construct the graph for deletes; this may expand to include
        // inserts and updates as well if there are any inserts that rely on
        // deletes (delete-then-insert-same-pk cases)
        PrimaryRow row;
        Row row2;
        ForeignKey[] fks;
        OpenJPAStateManager fkVal;
        boolean ignoreUpdates = true;
        for (Iterator itr = deletes.iterator(); itr.hasNext();) {
            row = (PrimaryRow) itr.next();
            if (!row.isValid())
                continue;

            row2 = getInsertRow(insertMap, rowMgr, row);
            if (row2 != null) {
                ignoreUpdates = false;
                graphs[1] = addEdge(graphs[1], (PrimaryRow) row2, row, null);
            }

            // now check this row's fks against other deletes
            fks = row.getTable().getForeignKeys();
            for (int j = 0; j < fks.length; j++) {
                // when deleting ref fks they'll just set a where value, so
                // check both for fk updates (relation fks) and wheres (ref fks)
                fkVal = row.getForeignKeySet(fks[j]);
                if (fkVal == null)
                    fkVal = row.getForeignKeyWhere(fks[j]);
                if (fkVal == null)
                    continue;

                row2 = rowMgr.getRow(fks[j].getPrimaryKeyTable(),
                    Row.ACTION_DELETE, fkVal, false);
View Full Code Here

     * Analyze the given rows against the inserts, placing dependencies
     * in the given graph.
     */
    private Graph analyzeAgainstInserts(Collection rows, RowManagerImpl rowMgr,
        Graph graph) {
        PrimaryRow row;
        Row row2;
        ForeignKey[] fks;
        Column[] cols;
        for (Iterator itr = rows.iterator(); itr.hasNext();) {
            row = (PrimaryRow) itr.next();
            if (!row.isValid())
                continue;

            // check this row's fks against inserts; a logical fk to an auto-inc
            // column is treated just as actual database fk because the result
            // is the same: the pk row has to be inserted before the fk row
            fks = row.getTable().getForeignKeys();
            for (int j = 0; j < fks.length; j++) {
                if (row.getForeignKeySet(fks[j]) == null)
                    continue;

                // see if this row is dependent on another.  if it's only
                // depenent on itself, see if the fk is logical or deferred, in
                // which case it must be an auto-inc because otherwise we
                // wouldn't have recorded it
                row2 = rowMgr.getRow(fks[j].getPrimaryKeyTable(),
                    Row.ACTION_INSERT, row.getForeignKeySet(fks[j]), false);
                if (row2 != null && row2.isValid() && (row2 != row
                    || fks[j].isDeferred() || fks[j].isLogical()))
                    graph = addEdge(graph, row, (PrimaryRow) row2, fks[j]);
            }

            // see if there are any relation id columns dependent on
            // auto-inc objects
            cols = row.getTable().getRelationIdColumns();
            for (int j = 0; j < cols.length; j++) {
                OpenJPAStateManager sm = row.getRelationIdSet(cols[j]);
                if (sm == null)
                    continue;

                row2 = rowMgr.getRow(getBaseTable(sm), Row.ACTION_INSERT,
                    sm, false);
View Full Code Here

     * @param deleteUpdates Collection of update statements that are executed
     * before the delete operations are flushed
     */
    private void addDeleteUpdate(Edge edge, Collection deleteUpdates)
        throws SQLException {
        PrimaryRow row;
        RowImpl update;
        ForeignKey fk;

        // copy where conditions into new update that nulls the fk
        row = (PrimaryRow) edge.getTo();
        update = new PrimaryRow(row.getTable(), Row.ACTION_UPDATE, null);
        row.copyInto(update, true);
        if (edge.getUserObject() instanceof ForeignKey) {
            fk = (ForeignKey) edge.getUserObject();
            update.setForeignKey(fk, row.getForeignKeyIO(fk), null);
        } else
            update.setNull((Column) edge.getUserObject());

        deleteUpdates.add(update);
    }
View Full Code Here

TOP

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

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.