Examples of RowImpl


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

     * 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

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

     * @param insertUpdates Collection of update statements that are executed
     * after the insert/update operations are flushed
     */
    private void addInsertUpdate(PrimaryRow row, Edge edge,
        Collection insertUpdates) throws SQLException {
        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 {
            // Row.ACTION_UPDATE
            row.copyInto(update, true);
        }
        if (edge.getUserObject() instanceof ForeignKey) {
            fk = (ForeignKey) edge.getUserObject();
            update.setForeignKey(fk, row.getForeignKeyIO(fk),
                row.getForeignKeySet(fk));
            row.clearForeignKey(fk);
        } else {
            col = (Column) edge.getUserObject();
            update.setRelationId(col, row.getRelationIdSet(col),
                row.getRelationIdCallback(col));
            row.clearRelationId(col);
        }

        insertUpdates.add(update);
View Full Code Here

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

     */
    protected void flush(Collection rows, PreparedStatementManager psMgr) {
        if (rows.size() == 0)
            return;

        RowImpl row;
        for (Iterator itr = rows.iterator(); itr.hasNext(); ) {
            row = (RowImpl) itr.next();
            if (row.isValid() && !row.isDependent())
                psMgr.flush(row);
        }
    }
View Full Code Here

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

     * 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

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

     * @param insertUpdates Collection of update statements that are executed
     * after the insert/update operations are flushed
     */
    private void addInsertUpdate(PrimaryRow row, Edge edge,
        Collection insertUpdates) throws SQLException {
        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 {
            // Row.ACTION_UPDATE
            row.copyInto(update, true);
        }
        if (edge.getUserObject() instanceof ForeignKey) {
            fk = (ForeignKey) edge.getUserObject();
            update.setForeignKey(fk, row.getForeignKeyIO(fk),
                row.getForeignKeySet(fk));
            row.clearForeignKey(fk);
        } else {
            col = (Column) edge.getUserObject();
            update.setRelationId(col, row.getRelationIdSet(col),
                row.getRelationIdCallback(col));
            row.clearRelationId(col);
        }

        insertUpdates.add(update);
View Full Code Here

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

     */
    protected void flush(Collection rows, PreparedStatementManager psMgr) {
        if (rows.size() == 0)
            return;

        RowImpl row;
        for (Iterator itr = rows.iterator(); itr.hasNext(); ) {
            row = (RowImpl) itr.next();
            if (row.isValid() && !row.isDependent())
                psMgr.flush(row);
        }
    }
View Full Code Here

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

     */
    protected void flushBatch() {
        if (_batchedSql != null && _batchedRows.size() > 0) {
            PreparedStatement ps = null;
            try {
                RowImpl onerow = null;
                ps = _conn.prepareStatement(_batchedSql);
                if (_batchedRows.size() == 1) {
                    // execute a single row.
                    onerow = (RowImpl) _batchedRows.get(0);
                    flushSingleRow(onerow, ps);
                } else {
                    // cache has more than one rows, execute as batch.
                    int count = 0;
                    int batchedRowsBaseIndex = 0;
                    Iterator itr = _batchedRows.iterator();
                    while (itr.hasNext()) {
                        onerow = (RowImpl) itr.next();
                        if (_batchLimit == 1) {
                            flushSingleRow(onerow, ps);
                        } else {
                            if (count < _batchLimit || _batchLimit == -1) {
                                onerow.flush(ps, _dict, _store);
                                ps.addBatch();
                                count++;
                            } else {
                                // reach the batchLimit, execute the batch
                                int[] rtn = ps.executeBatch();
                                checkUpdateCount(rtn, batchedRowsBaseIndex);

                                batchedRowsBaseIndex += _batchLimit;

                                onerow.flush(ps, _dict, _store);
                                ps.addBatch();
                                // reset the count to 1 for new batch
                                count = 1;
                            }
                        }
View Full Code Here

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

        throws SQLException {
        int cnt = 0;
        Object failed = null;
        for (int i = 0; i < count.length; i++) {
            cnt = count[i];
            RowImpl row = (RowImpl) _batchedRows.get(batchedRowsBaseIndex + i);
            switch (cnt) {
            case Statement.EXECUTE_FAILED: // -3
                failed = row.getFailedObject();
                if (failed != null || row.getAction() == Row.ACTION_UPDATE)
                    _exceptions.add(new OptimisticException(failed));
                else if (row.getAction() == Row.ACTION_INSERT)
                    throw new SQLException(_loc.get(
                        "update-failed-no-failed-obj",
                        String.valueOf(count[i]), _batchedSql).getMessage());
                break;
            case Statement.SUCCESS_NO_INFO: // -2
                if (_log.isTraceEnabled())
                    _log.trace(_loc.get("batch_update_info",
                        String.valueOf(cnt), _batchedSql).getMessage());
                break;
            case 0: // no row is inserted, treats it as failed
                // case
                failed = row.getFailedObject();
                if ((failed != null || row.getAction() == Row.ACTION_INSERT))
                    throw new SQLException(_loc.get(
                        "update-failed-no-failed-obj",
                        String.valueOf(count[i]), _batchedSql).getMessage());
            }
        }
View Full Code Here

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

            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);
        }
        return updates;
View Full Code Here

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

     */
    protected void flush(Collection rows, PreparedStatementManager psMgr) {
        if (rows.isEmpty())
            return;

        RowImpl row;
        for (Iterator itr = rows.iterator(); itr.hasNext();) {
            row = (RowImpl) itr.next();
            if (row.isValid())
                psMgr.flush(row);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.