Package org.apache.openjpa.util

Examples of org.apache.openjpa.util.OptimisticException


                boolean isNew = state.length == 3 + offset;

                // attempting to attach an instance that has been deleted
                // will throw an OVE if it was not PNEW when it was detached
                if (!isNew)
                    throw new OptimisticException(_loc.get("attach-deleted",
                        ImplHelper.getManagedInstance(pc).getClass(), id))
                        .setFailedObject(id);

                // if the instance does not exist, we assume that it was
                // made persistent in a new transaction, detached, and then
                // the transaction was rolled back; the danger is that
                // the instance was made persistent, detached, committed,
                // and then deleted, but this is an uncommon case
                sm = persist(manager, pc, meta, id, explicit);
                into = sm.getPersistenceCapable();

                // nullify the state, since the new instance won't have one
                state = null;
            } else
                sm = manager.assertManaged(into);
        } else
            sm = manager.assertManaged(into);

        // mark that we attached the instance *before* we
        // fill in values to avoid endless recursion
        manager.setAttachedCopy(pc, into);
        meta = sm.getMetaData();
        manager.fireBeforeAttach(pc, meta);
        offset = meta.getIdentityType() == meta.ID_DATASTORE ? 1 : 0;

        // assign the detached pc the same state manager as the object we're
        // copying into during the attach process
        pc.pcReplaceStateManager(sm);
        BitSet fields = state == null ? null : (BitSet) state[1 + offset];
        try {
            FieldMetaData[] fmds = meta.getFields();
            for (int i = 0; i < fmds.length; i++) {
                // only attach fields in the FG of the detached instance; new
                // instances get all their fields attached
                if (fields == null || fields.get(i))
                    attachField(manager, pc, sm, fmds[i], true);
            }
        }
        finally {
            pc.pcReplaceStateManager(null);
        }

        // set the next version for non-new instances that are not embedded
        if (state != null && !embedded) {
            // make sure that all the fields in the original FG are loaded
            // before we try to compare version
            if (fields != null && !fields.equals(sm.getLoaded())) {
                BitSet toLoad = (BitSet) fields.clone();
                toLoad.andNot(sm.getLoaded()); // skip already loaded fields
                if (toLoad.length() > 0)
                    sm.loadFields(toLoad, null, LockLevels.LOCK_NONE, null);
                //### we should calculate lock level above
            }
            Object version = state[offset];

            StoreManager store = broker.getStoreManager();
            switch (store.compareVersion(sm, version, sm.getVersion())) {
                case StoreManager.VERSION_LATER:
                    // we have a later version: set it into the object.
                    // lock validation will occur at commit time
                    sm.setVersion(version);
                    break;
                case StoreManager.VERSION_EARLIER:
                case StoreManager.VERSION_DIFFERENT:
                    sm.setVersion(version);
                    throw new OptimisticException(into);
                case StoreManager.VERSION_SAME:
                    // no action required
                    break;
            }
        }
View Full Code Here


            row.flush(ps, _dict, _store);
        int count = executeUpdate(ps, row.getSQL(_dict), row);
        if (count != 1) {
            Object failed = row.getFailedObject();
            if (failed != null)
                _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), row.getSQL(_dict)).getMessage());
        }
    }
View Full Code Here

            RowImpl row = (RowImpl) batchedRows.get(batchedRowsBaseIndex + i);
            failed = row.getFailedObject();
            switch (cnt) {
            case Statement.EXECUTE_FAILED: // -3
                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]),
                        row.getSQL(_dict)).getMessage());
                break;
            case Statement.SUCCESS_NO_INFO: // -2
                if (_dict.reportsSuccessNoInfoOnBatchUpdates &&                   
                    updateSuccessCnt != count.length) {
                    // Oracle batching specifics:
                    // treat update/delete of SUCCESS_NO_INFO as failed case
                    // because:
                    // 1. transaction should be rolled back.
                    // 2. if DataCache is enabled, objects in
                    //    cache should be removed.
                    if (failed != null)
                        _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]),
                            row.getSQL(_dict)).getMessage());
                }
                if (_log.isTraceEnabled())
                    _log.trace(_loc.get("batch_update_info",
                        String.valueOf(cnt),
                        row.getSQL(_dict)).getMessage());
                break;
            case 0: // no row is inserted, treats it as failed
                // case
                if (failed != null)
                    _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]),
                        row.getSQL(_dict)).getMessage());
View Full Code Here

                updateIndicators(sm, (ClassMapping) sm.getMetaData(), rowMgr,
                    store, customs, true);
            } else if (sm.isVersionCheckRequired()) {
                if (!((ClassMapping) sm.getMetaData()).getVersion().
                    checkVersion(sm, store, false))
                    exceps = addException(exceps, new OptimisticException(sm.
                        getManagedInstance()));
            }
        } catch (SQLException se) {
            exceps = addException(exceps, SQLExceptions.getStore(se, dict));
        } catch (OpenJPAException ke) {
View Full Code Here

        try {
            int count = executeUpdate(stmnt, sql, row);
            if (count != 1) {
                Object failed = row.getFailedObject();
                if (failed != null)
                    _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),
                        sql).getMessage());
            }
View Full Code Here

                updateIndicators(sm, (ClassMapping) sm.getMetaData(), rowMgr,
                    store, customs, true);
            } else if (sm.isVersionCheckRequired()) {
                if (!((ClassMapping) sm.getMetaData()).getVersion().
                    checkVersion(sm, store, false))
                    exceps = addException(exceps, new OptimisticException(sm.
                        getManagedInstance()));
            }
        } catch (SQLException se) {
            exceps = addException(exceps, SQLExceptions.getStore(se, dict));
        } catch (OpenJPAException ke) {
View Full Code Here

                    failed.add(f);
            }
        }
        if (opt && !failed.isEmpty()) {
            if(_suppressBatchOLELogging == true){
                return new OptimisticException(_loc.get("broker-suppressing-exceptions",t.length));
            }else{
                return new OptimisticException(failed, t);
            }
        }
        if (opt)
            return new OptimisticException(t);
       
        Object failedObject = null;
        if (t[0] instanceof OpenJPAException){
          failedObject = ((OpenJPAException)t[0]).getFailedObject();
        }
View Full Code Here

            break;
        case StoreException.OBJECT_NOT_FOUND:
            storeEx = new ObjectNotFoundException(failed);
            break;
        case StoreException.OPTIMISTIC:
            storeEx = new OptimisticException(failed);
            break;
        case StoreException.REFERENTIAL_INTEGRITY:
            storeEx = new ReferentialIntegrityException(msg);
            break;
        case StoreException.QUERY:
View Full Code Here

            if (id != null)
                into =
                    ImplHelper.toPersistenceCapable(broker.find(id, true, null),
                        broker.getConfiguration());
            if (into == null)
                throw new OptimisticException(_loc.get("attach-version-del",
                    ImplHelper.getManagedInstance(pc).getClass(), id, version))
                    .setFailedObject(toAttach);

            sm = manager.assertManaged(into);
            if (meta.getDescribedType()
View Full Code Here

                sm.setVersion(version);
                break;
            case StoreManager.VERSION_EARLIER:
            case StoreManager.VERSION_DIFFERENT:
                sm.setVersion(version);
                throw new OptimisticException(sm.getManagedInstance());
            case StoreManager.VERSION_SAME:
                // no action required
                break;
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.util.OptimisticException

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.