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

        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

        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

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.