From 923eb32d31d08edc9526a6f6ce9c4ca30357e738 Mon Sep 17 00:00:00 2001 From: Stephen Kim Date: Sat, 30 Sep 2006 05:29:10 +0000 Subject: [PATCH] fixed duplicate preFlush and bug wrt persist vs nonprovisional in singlefieldmanager git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@451543 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/kernel/PCState.java | 6 +-- .../openjpa/kernel/PNewProvisionalState.java | 45 ++++++++++++++++--- .../openjpa/kernel/SingleFieldManager.java | 10 +++-- .../openjpa/kernel/StateManagerImpl.java | 15 ++++--- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java index ca888ee70..599c97fac 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java @@ -235,10 +235,10 @@ public class PCState /** * Return the state to transition to after making no longer provisional. - * The context is not given because no actions should be taken. + * Returns the this pointer by default. */ - PCState nonprovisional(StateManagerImpl context, boolean flush, - boolean logical, OpCallbacks call) { + PCState nonprovisional(StateManagerImpl context, boolean logical, + OpCallbacks call) { return this; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java index 2e5aa83ce..2198c3bb1 100755 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java @@ -24,17 +24,21 @@ package org.apache.openjpa.kernel; * @author: Abe White */ class PNewProvisionalState - extends PNewState { + extends PCState { + + void initialize(StateManagerImpl context) { + context.setLoaded(true); + context.setDirty(true); + context.saveFields(false); + } PCState persist(StateManagerImpl context) { return PNEW; } - PCState nonprovisional(StateManagerImpl context, boolean flush, - boolean logical, OpCallbacks call) { - if (flush) - beforeFlush(context, logical, call); - + PCState nonprovisional(StateManagerImpl context, boolean logical, + OpCallbacks call) { + context.preFlush(logical, call); return PNEW; } @@ -46,6 +50,35 @@ class PNewProvisionalState return TRANSIENT; } + PCState rollback(StateManagerImpl context) { + return TRANSIENT; + } + + PCState rollbackRestore(StateManagerImpl context) { + context.restoreFields(); + return TRANSIENT; + } + + PCState release(StateManagerImpl context) { + return TRANSIENT; + } + + boolean isTransactional() { + return true; + } + + boolean isPersistent() { + return true; + } + + boolean isNew() { + return true; + } + + boolean isDirty() { + return true; + } + boolean isProvisional() { return true; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java index 0f790e344..1d88acae2 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java @@ -748,8 +748,13 @@ class SingleFieldManager Exceptions.toString(obj), vmd, Exceptions.toString(_sm.getManagedInstance()))). setFailedObject(obj); - } else - sm = _broker.persist(obj, null, true, call); + } else { + sm = _broker.getStateManager(obj); + if (sm != null && sm.isProvisional()) + ((StateManagerImpl) sm).nonprovisional(logical, call); + else + sm = _broker.persist(obj, null, true, call); + } if (sm != null) { // if deleted and not managed inverse, die @@ -759,7 +764,6 @@ class SingleFieldManager Exceptions.toString(obj), vmd, Exceptions.toString(_sm.getManagedInstance()))). setFailedObject(obj); - ((StateManagerImpl) sm).nonprovisional(true, logical, call); ((StateManagerImpl) sm).setDereferencedDependent(false, true); } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java index 907c2216a..3550af077 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java @@ -486,7 +486,8 @@ public class StateManagerImpl * @param recache whether to recache ourself on the new oid */ private void assertObjectIdAssigned(boolean recache) { - if (!isNew() || isDeleted() || (_flags & FLAG_OID_ASSIGNED) > 0) + if (!isNew() || isDeleted() || isProvisional() || + (_flags & FLAG_OID_ASSIGNED) > 0) return; if (_oid == null) { if (_meta.getIdentityType() == ClassMetaData.ID_DATASTORE) @@ -905,7 +906,7 @@ public class StateManagerImpl Object orig = _id; assertObjectIdAssigned(false); - boolean wasNew = isNew() && !isDeleted(); + boolean wasNew = isNew() && !isDeleted() && !isProvisional(); if (_broker.getRetainState()) setPCState(_state.commitRetain(this)); else @@ -997,10 +998,9 @@ public class StateManagerImpl * Delegates to the current state. * * @see PCState#nonprovisional - * @see Broker#nonprovisional */ - void nonprovisional(boolean flush, boolean logical, OpCallbacks call) { - setPCState(_state.nonprovisional(this, flush, logical, call)); + void nonprovisional(boolean logical, OpCallbacks call) { + setPCState(_state.nonprovisional(this, logical, call)); } /** @@ -2633,9 +2633,10 @@ public class StateManagerImpl * for all strategies that don't require flushing. */ void preFlush(boolean logical, OpCallbacks call) { - boolean second = (_flags & FLAG_PRE_FLUSHED) != 0; + if ((_flags & FLAG_PRE_FLUSHED) != 0) + return; - if (isPersistent() && !second) { + if (isPersistent()) { fireLifecycleEvent(LifecycleEvent.BEFORE_STORE); _flags |= FLAG_PRE_FLUSHED; }