openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r451543 - in /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel: PCState.java PNewProvisionalState.java SingleFieldManager.java StateManagerImpl.java
Date Sat, 30 Sep 2006 05:29:12 GMT
Author: skim
Date: Fri Sep 29 22:29:10 2006
New Revision: 451543

URL: http://svn.apache.org/viewvc?view=rev&rev=451543
Log:
fixed duplicate preFlush and bug wrt persist vs nonprovisional in 
singlefieldmanager

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java?view=diff&rev=451543&r1=451542&r2=451543
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PCState.java
Fri Sep 29 22:29:10 2006
@@ -235,10 +235,10 @@
 
     /**
      * Return the state to transition to after making no longer provisional. 
-     * The context is not given because no actions should be taken.
+     * Returns the <code>this</code> pointer by default.
      */
-    PCState nonprovisional(StateManagerImpl context, boolean flush, 
-        boolean logical, OpCallbacks call) {
+    PCState nonprovisional(StateManagerImpl context, boolean logical, 
+        OpCallbacks call) {
         return this;
     }
 

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java?view=diff&rev=451543&r1=451542&r2=451543
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
Fri Sep 29 22:29:10 2006
@@ -24,17 +24,21 @@
  * @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;
     }
 
@@ -44,6 +48,35 @@
 
     PCState commitRetain(StateManagerImpl context) {
         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() {

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java?view=diff&rev=451543&r1=451542&r2=451543
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
Fri Sep 29 22:29:10 2006
@@ -748,8 +748,13 @@
                         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 @@
                     Exceptions.toString(obj), vmd,
                     Exceptions.toString(_sm.getManagedInstance()))).
                     setFailedObject(obj);
-            ((StateManagerImpl) sm).nonprovisional(true, logical, call);
             ((StateManagerImpl) sm).setDereferencedDependent(false, true);
         }
     }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?view=diff&rev=451543&r1=451542&r2=451543
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Fri Sep 29 22:29:10 2006
@@ -486,7 +486,8 @@
      * @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 @@
         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 @@
      * 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 @@
      * 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;
         }



Mime
View raw message