openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r450916 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/
Date Thu, 28 Sep 2006 16:34:08 GMT
Author: skim
Date: Thu Sep 28 09:34:05 2006
New Revision: 450916

URL: http://svn.apache.org/viewvc?view=rev&rev=450916
Log:
PNewProvisional again.  I think I covered the object graph reflush issue

Added:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
  (with props)
Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/OpenJPAStateManager.java
    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/SingleFieldManager.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbedFieldStrategy.java
Thu Sep 28 09:34:05 2006
@@ -627,6 +627,10 @@
             return isFlushed();
         }
 
+        public boolean isProvisional() {
+            return _owner.isProvisional();
+        }
+
         public BitSet getLoaded() {
             // consider everything loaded
             if (_full == null) {

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
Thu Sep 28 09:34:05 2006
@@ -94,7 +94,7 @@
 
         CallbackException excep = null;
         try {
-            return attach(pc, null, null, null);
+            return attach(pc, null, null, null, true);
         } catch (CallbackException ce) {
             excep = ce;
             return null; // won't be reached as the exceps will be rethrown
@@ -122,7 +122,7 @@
             int i = 0;
             for (Iterator itr = instances.iterator(); itr.hasNext(); i++) {
                 try {
-                    attached[i] = attach(itr.next(), null, null, null);
+                    attached[i] = attach(itr.next(), null, null, null, true);
                 } catch (OpenJPAException ke) {
                     // track exceptions and optimistic failed objects
                     if (opt && !(ke instanceof OptimisticException))
@@ -212,9 +212,10 @@
      * @param into the instance we're attaching into
      * @param owner state manager for <code>into</code>
      * @param ownerMeta the field we traversed to find <code>toAttach</code>
+     * @param explicit whether to make new instances explicitly persistent
      */
     Object attach(Object toAttach, PersistenceCapable into,
-        OpenJPAStateManager owner, ValueMetaData ownerMeta) {
+        OpenJPAStateManager owner, ValueMetaData ownerMeta, boolean explicit) {
         if (toAttach == null)
             return null;
 
@@ -233,7 +234,7 @@
             getMetaDataRepositoryInstance().getMetaData(toAttach.getClass(),
             _broker.getClassLoader(), true);
         return getStrategy(toAttach).attach(this, toAttach, meta, into,
-            owner, ownerMeta);
+            owner, ownerMeta, explicit);
     }
 
     /**

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachStrategy.java
Thu Sep 28 09:34:05 2006
@@ -55,10 +55,11 @@
      * @param into instance we're attaching into
      * @param owner state manager for <code>into</code>
      * @param ownerMeta field we traversed to find <code>toAttach</code>
+     * @param explicit whether to make new instances explicitly persistent
      */
     public abstract Object attach(AttachManager manager,
         Object toAttach, ClassMetaData meta, PersistenceCapable into,
-        OpenJPAStateManager owner, ValueMetaData ownerMeta);
+        OpenJPAStateManager owner, ValueMetaData ownerMeta, boolean explicit);
 
     /**
      * Return the identity of the given detached instance.
@@ -73,10 +74,12 @@
         int field);
 
     /**
-     * Return a PNew managed object for the given detached instance.
+     * Return a PNew/PNewProvisional managed object for the given detached 
+     * instance.
      */
     protected StateManagerImpl persist(AttachManager manager,
-        PersistenceCapable pc, ClassMetaData meta, Object appId) {
+        PersistenceCapable pc, ClassMetaData meta, Object appId, 
+        boolean explicit) {
         PersistenceCapable newInstance;
         if (!manager.getCopyNew())
             newInstance = pc;
@@ -86,7 +89,7 @@
             newInstance = pc.pcNewInstance(null, appId, false);
 
         return (StateManagerImpl) manager.getBroker().persist
-            (newInstance, appId, manager.getBehavior());
+            (newInstance, appId, explicit, manager.getBehavior());
     }
 
     /**
@@ -191,7 +194,7 @@
                             manager.getDetachedObjectId(frmpc))) {
                             intopc = null;
                         }
-                        frmpc = manager.attach(frmpc, intopc, sm, fmd);
+                        frmpc = manager.attach(frmpc, intopc, sm, fmd, false);
                     }
                     if (frmpc != topc)
                         sm.settingObjectField(into, i, topc, frmpc, set);
@@ -199,6 +202,8 @@
                 break;
             case JavaTypes.COLLECTION:
                 Collection frmc = (Collection) fetchObjectField(i);
+                System.out.println("Fetch:" + fmd + ":" + frmc
+                    + ":" + nullLoaded);
                 if (frmc == null && !nullLoaded)
                     return false;
                 Collection toc = (Collection) sm.fetchObjectField(i);
@@ -320,7 +325,7 @@
             if (vmd.getCascadeAttach() == ValueMetaData.CASCADE_NONE)
                 elem = getReference(manager, itr.next(), sm, vmd);
             else
-                elem = manager.attach(itr.next(), null, sm, vmd);
+                elem = manager.attach(itr.next(), null, sm, vmd, false);
             coll.add(elem);
         }
         return coll;
@@ -432,13 +437,13 @@
                 if (keymd.getCascadeAttach() == ValueMetaData.CASCADE_NONE)
                     key = getReference(manager, key, sm, keymd);
                 else
-                    key = manager.attach(key, null, sm, keymd);
+                    key = manager.attach(key, null, sm, keymd, false);
                 val = entry.getValue();
                 if (valmd.isDeclaredTypePC()) {
                     if (valmd.getCascadeAttach() == ValueMetaData.CASCADE_NONE)
                         val = getReference(manager, val, sm, valmd);
                     else
-                        val = manager.attach(val, null, sm, valmd);
+                        val = manager.attach(val, null, sm, valmd, false);
                 }
                 map.put(key, val);
             }
@@ -449,7 +454,8 @@
                 if (valmd.getCascadeAttach() == ValueMetaData.CASCADE_NONE)
                     val = getReference(manager, entry.getValue(), sm, valmd);
                 else
-                    val = manager.attach(entry.getValue(), null, sm, valmd);
+                    val = manager.attach(entry.getValue(), null, sm, valmd, 
+                        false);
                 entry.setValue(val);
             }
         }
@@ -479,7 +485,7 @@
                 if (vmd.getCascadeAttach() == ValueMetaData.CASCADE_NONE)
                     elem = getReference(manager, elem, sm, vmd);
                 else
-                    elem = manager.attach(elem, null, sm, vmd);
+                    elem = manager.attach(elem, null, sm, vmd, false);
             }
             diff = diff || !equals(elem, Array.get(toa, i), pc);
             Array.set(newa, i, elem);

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
Thu Sep 28 09:34:05 2006
@@ -2152,7 +2152,25 @@
     // Object lifecycle
     ////////////////////
 
+    public void persist(Object obj, OpCallbacks call) {
+        persist(obj, null, true, call);
+    }
+
+    public OpenJPAStateManager persist(Object obj, Object id,
+        OpCallbacks call) {
+        return persist(obj, id, true, call);
+    }
+
     public void persistAll(Collection objs, OpCallbacks call) {
+        persistAll(objs, true, call);
+    }
+
+    /**
+     * Persist the given objects.  Indicate whether this was an explicit persist
+     * (PNEW) or a provisonal persist (PNEWPROVISIONAL).
+     */
+    public void persistAll(Collection objs, boolean explicit, 
+        OpCallbacks call) {
         if (objs.isEmpty())
             return;
 
@@ -2163,7 +2181,7 @@
 
             for (Iterator itr = objs.iterator(); itr.hasNext();) {
                 try {
-                    persist(itr.next(), call);
+                    persist(itr.next(), explicit, call);
                 } catch (UserException ue) {
                     exceps = add(exceps, ue);
                 }
@@ -2212,11 +2230,20 @@
         throw err.setNestedThrowables(t).setFatal(fatal);
     }
 
-    public void persist(Object obj, OpCallbacks call) {
-        persist(obj, null, call);
+    /**
+     * Persist the given object.  Indicate whether this was an explicit persist
+     * (PNEW) or a provisonal persist (PNEWPROVISIONAL)
+     */
+    public void persist(Object obj, boolean explicit, OpCallbacks call) {
+        persist(obj, null, explicit, call);
     }
 
-    public OpenJPAStateManager persist(Object obj, Object id,
+    /**
+     * Persist the given object.  Indicate whether this was an explicit persist
+     * (PNEW) or a provisonal persist (PNEWPROVISIONAL).
+     * See {@link Broker} for details on this method.
+     */
+    public OpenJPAStateManager persist(Object obj, Object id, boolean explicit,
         OpCallbacks call) {
         if (obj == null)
             return null;
@@ -2299,9 +2326,12 @@
 
             // create new sm
             sm = new StateManagerImpl(id, meta, this);
-            if ((_flags & FLAG_ACTIVE) != 0)
-                sm.initialize(pc, PCState.PNEW);
-            else
+            if ((_flags & FLAG_ACTIVE) != 0) {
+                if (explicit)
+                    sm.initialize(pc, PCState.PNEW);
+                else
+                    sm.initialize(pc, PCState.PNEWPROVISIONAL);
+            } else
                 sm.initialize(pc, PCState.PNONTRANSNEW);
             if ((action & OpCallbacks.ACT_CASCADE) != 0)
                 sm.cascadePersist(call);

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateAttachStrategy.java
Thu Sep 28 09:34:05 2006
@@ -70,7 +70,7 @@
 
     public Object attach(AttachManager manager, Object toAttach,
         ClassMetaData meta, PersistenceCapable into, OpenJPAStateManager owner,
-        ValueMetaData ownerMeta) {
+        ValueMetaData ownerMeta, boolean explicit) {
         BrokerImpl broker = manager.getBroker();
         PersistenceCapable pc = (PersistenceCapable) toAttach;
 
@@ -94,7 +94,8 @@
             sm = (StateManagerImpl) broker.embed(into, null, owner, ownerMeta);
             into = sm.getPersistenceCapable();
         } else if (state == null) {
-            sm = persist(manager, pc, meta, ApplicationIds.create(pc, meta));
+            sm = persist(manager, pc, meta, ApplicationIds.create(pc, meta),
+                explicit);
             into = sm.getPersistenceCapable();
         } else if (!embedded && into == null) {
             Object id = getDetachedObjectId(manager, pc);
@@ -117,7 +118,7 @@
                 // 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);
+                sm = persist(manager, pc, meta, id, explicit);
                 into = sm.getPersistenceCapable();
 
                 // nullify the state, since the new instance won't have one

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedStateManager.java
Thu Sep 28 09:34:05 2006
@@ -87,7 +87,7 @@
 
     public Object attach(AttachManager manager, Object toAttach,
         ClassMetaData meta, PersistenceCapable into, OpenJPAStateManager owner,
-        ValueMetaData ownerMeta) {
+        ValueMetaData ownerMeta, boolean explicit) {
         BrokerImpl broker = manager.getBroker();
         StateManagerImpl sm = null;
         if (_embedded) {
@@ -225,7 +225,8 @@
                         PersistenceCapable toPC = null;
                         if (objval != null && fields[i].isEmbeddedPC())
                             toPC = (PersistenceCapable) objval;
-                        objval = manager.attach(objval, toPC, sm, fields[i]);
+                        objval = manager.attach(objval, toPC, sm, fields[i],
+                            false);
                     }
                     if (_dirty.get(i))
                         sm.settingObjectField(pc, i, (!loaded.get(i)) ? null
@@ -685,6 +686,10 @@
     }
 
     public boolean isFlushedDirty() {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isProvisional() {
         throw new UnsupportedOperationException();
     }
 

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DetachedValueStateManager.java
Thu Sep 28 09:34:05 2006
@@ -101,6 +101,10 @@
         return false;
     }
 
+    public boolean isProvisional() {
+        return false;
+    }
+
     public BitSet getLoaded() {
         throw new UnsupportedOperationException();
     }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ObjectIdStateManager.java
Thu Sep 28 09:34:05 2006
@@ -317,6 +317,10 @@
         return false;
     }
 
+    public boolean isProvisional() {
+        return false;
+    }
+
     public BitSet getLoaded() {
         throw new UnsupportedOperationException();
     }

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/OpenJPAStateManager.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/OpenJPAStateManager.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/OpenJPAStateManager.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/OpenJPAStateManager.java
Thu Sep 28 09:34:05 2006
@@ -121,6 +121,11 @@
     public boolean isFlushedDirty();
 
     /**
+     * Return whether this object is provisionally persistent.
+     */
+    public boolean isProvisional();
+
+    /**
      * Return a read-only mask of the indexes of all loaded fields.
      */
     public BitSet getLoaded();

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=450916&r1=450915&r2=450916
==============================================================================
--- 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
Thu Sep 28 09:34:05 2006
@@ -63,6 +63,11 @@
     public static final PCState PNEWDELETED = new PNewDeletedState();
 
     /**
+     * Persistent-New-Provisional
+     */
+    public static final PCState PNEWPROVISIONAL = new PNewProvisionalState();
+
+    /**
      * Persistent-Nontransactinoal
      */
     public static final PCState PNONTRANS = new PNonTransState();
@@ -229,6 +234,15 @@
     }
 
     /**
+     * Return the state to transition to after making no longer provisional. 
+     * The context is not given because no actions should be taken.
+     */
+    PCState nonprovisional(StateManagerImpl context, boolean flush, 
+        boolean logical, OpCallbacks call) {
+        return this;
+    }
+
+    /**
      * Perform any actions necesssary and return the proper lifecycle state
      * on a call to {@link StoreContext#nontransactional} with the given
      * instance. Returns the <code>this</code> pointer by default.
@@ -403,6 +417,15 @@
     }
 
     /**
+     * Return whether this is a state that will become transient
+     * at the end of the next transaction.
+     * Returns <code>false</code> by default.
+     */
+    boolean isProvisional() {
+        return false;
+    }
+
+    /**
      * Whether this state requires a version check when being flushed, 
      * assuming the system is configured for version checks.
      */
@@ -430,6 +453,8 @@
             return PDELETED;
         if (this instanceof PNewDeletedState)
             return PNEWDELETED;
+        if (this instanceof PNewProvisionalState)
+            return PNEWPROVISIONAL;
         if (this instanceof PNonTransState)
             return PNONTRANS;
         if (this instanceof PNonTransDirtyState)

Added: 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=auto&rev=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
(added)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
Thu Sep 28 09:34:05 2006
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.kernel;
+
+/**
+ * Lifecycle state.
+ * Represents an instance that was made persistent via reachability within the
+ * current	transaction.
+ *
+ * @author Steve Kim
+ * @author: Abe White
+ */
+class PNewProvisionalState
+    extends PNewState {
+
+    PCState persist(StateManagerImpl context) {
+        return PNEW;
+    }
+
+    PCState nonprovisional(StateManagerImpl context, boolean flush, 
+        boolean logical, OpCallbacks call) {
+        if (flush)
+            beforeFlush(context, logical, call);
+
+        return PNEW;
+    }
+
+    PCState commit(StateManagerImpl context) {
+        return TRANSIENT;
+    }
+
+    PCState commitRetain(StateManagerImpl context) {
+        return TRANSIENT;
+    }
+
+    boolean isProvisional() {
+        return true;
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/PNewProvisionalState.java
------------------------------------------------------------------------------
    svn:executable = *

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=450916&r1=450915&r2=450916
==============================================================================
--- 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
Thu Sep 28 09:34:05 2006
@@ -250,21 +250,22 @@
             case JavaTypes.PC_UNTYPED:
                 if (!_broker.isDetachedNew() && _broker.isDetached(objval))
                     return; // allow but ignore
-                _broker.persist(objval, call);
+                _broker.persist(objval, false, call);
                 break;
             case JavaTypes.ARRAY:
-                _broker.persistAll(Arrays.asList((Object[]) objval), call);
+                _broker.persistAll(Arrays.asList((Object[]) objval), false, 
+                    call);
                 break;
             case JavaTypes.COLLECTION:
-                _broker.persistAll((Collection) objval, call);
+                _broker.persistAll((Collection) objval, false, call);
                 break;
             case JavaTypes.MAP:
                 if (fmd.getKey().getCascadePersist()
                     == ValueMetaData.CASCADE_IMMEDIATE)
-                    _broker.persistAll(((Map) objval).keySet(), call);
+                    _broker.persistAll(((Map) objval).keySet(), false, call);
                 if (fmd.getElement().getCascadePersist()
                     == ValueMetaData.CASCADE_IMMEDIATE)
-                    _broker.persistAll(((Map) objval).values(), call);
+                    _broker.persistAll(((Map) objval).values(), false, call);
                 break;
         }
     }
@@ -460,14 +461,14 @@
      * pc fields. Return true if the field needs to be replaced with the
      * new value.
      */
-    public boolean preFlush(OpCallbacks call) {
+    public boolean preFlush(boolean logical, OpCallbacks call) {
         // only care about object fields
         FieldMetaData fmd = _sm.getMetaData().getField(field);
         if (fmd.getDeclaredTypeCode() < JavaTypes.OBJECT)
             return false;
 
         // perform pers-by-reach and dependent refs
-        boolean ret = preFlush(fmd, call);
+        boolean ret = preFlush(fmd, logical, call);
 
         // manage inverses
         InverseManager manager = _broker.getInverseManager();
@@ -523,7 +524,8 @@
     /**
      * Helper method to perform pre flush actions on the current object.
      */
-    private boolean preFlush(FieldMetaData fmd, OpCallbacks call) {
+    private boolean preFlush(FieldMetaData fmd, boolean logical, 
+        OpCallbacks call) {
         // check for illegal nulls
         if (objval == null) {
             if (fmd.getNullValue() == FieldMetaData.NULL_EXCEPTION
@@ -552,13 +554,13 @@
         // check for pcs in field value
         if (preFlush(fmd, fmd.getDeclaredTypeCode(),
             fmd.getKey().getDeclaredTypeCode(),
-            fmd.getElement().getDeclaredTypeCode(), false, call))
+            fmd.getElement().getDeclaredTypeCode(), false, logical, call))
             return true;
 
         // also check for pcs in externalized values
         if (fmd.isExternalized())
             preFlush(fmd, fmd.getTypeCode(), fmd.getKey().getTypeCode(),
-                fmd.getElement().getTypeCode(), true, call);
+                fmd.getElement().getTypeCode(), true, logical, call);
         return false;
     }
 
@@ -567,7 +569,7 @@
      * dependent objects won't be deleted.
      */
     private boolean preFlush(FieldMetaData fmd, int type, int keyType,
-        int elemType, boolean external, OpCallbacks call) {
+        int elemType, boolean external, boolean logical, OpCallbacks call) {
         Object val = objval;
         if (val == null)
             return false;
@@ -582,14 +584,14 @@
                     if (external)
                         val = fmd.getExternalValue(val, _broker);
                     if (val != null)
-                        preFlushPC(fmd, val, call);
+                        preFlushPC(fmd, val, logical, call);
                 }
                 break;
             case JavaTypes.PC_UNTYPED:
                 if (external)
                     val = fmd.getExternalValue(val, _broker);
                 if (val != null)
-                    preFlushPC(fmd, val, call);
+                    preFlushPC(fmd, val, logical, call);
                 break;
             case JavaTypes.ARRAY:
                 if (fmd.getElement().isEmbeddedPC())
@@ -599,7 +601,8 @@
                     if (external)
                         val = fmd.getExternalValue(val, _broker);
                     if (val != null)
-                        preFlushPCs(fmd.getElement(), (Object[]) val, call);
+                        preFlushPCs(fmd.getElement(), (Object[]) val, logical, 
+                            call);
                 }
                 break;
             case JavaTypes.COLLECTION:
@@ -616,14 +619,16 @@
                         // lrs fields
                         ChangeTracker ct = ((Proxy) val).getChangeTracker();
                         if (ct != null && ct.isTracking()) {
-                            preFlushPCs(fmd.getElement(), ct.getAdded(), call);
+                            preFlushPCs(fmd.getElement(), ct.getAdded(), 
+                                logical, call);
                             preFlushPCs(fmd.getElement(), ct.getChanged(),
-                                call);
+                                logical, call);
                             flushed = true;
                         }
                     }
                     if (!flushed && val != null)
-                        preFlushPCs(fmd.getElement(), (Collection) val, call);
+                        preFlushPCs(fmd.getElement(), (Collection) val, logical,
+                            call);
                 }
                 break;
             case JavaTypes.MAP:
@@ -647,13 +652,16 @@
                             getChangeTracker();
                         if (ct != null && ct.isTracking() && ct.getTrackKeys())
                         {
-                            preFlushPCs(fmd.getKey(), ct.getAdded(), call);
-                            preFlushPCs(fmd.getKey(), ct.getChanged(), call);
+                            preFlushPCs(fmd.getKey(), ct.getAdded(), logical,
+                                call);
+                            preFlushPCs(fmd.getKey(), ct.getChanged(), logical,
+                                call);
                             flushed = true;
                         }
                     }
                     if (!flushed && val != null)
-                        preFlushPCs(fmd.getKey(), ((Map) val).keySet(), call);
+                        preFlushPCs(fmd.getKey(), ((Map) val).keySet(), logical,
+                            call);
                 }
 
                 if (!valEmbed && (elemType == JavaTypes.PC
@@ -669,21 +677,21 @@
                         if (ct != null && ct.isTracking()) {
                             if (ct.getTrackKeys()) {
                                 preFlushPCs(fmd.getElement(), ct.getAdded(),
-                                    (Map) val, call);
+                                    (Map) val, logical, call);
                                 preFlushPCs(fmd.getElement(), ct.getChanged(),
-                                    (Map) val, call);
+                                    (Map) val, logical, call);
                             } else {
                                 preFlushPCs(fmd.getElement(), ct.getAdded(),
-                                    call);
+                                    logical, call);
                                 preFlushPCs(fmd.getElement(), ct.getChanged(),
-                                    call);
+                                    logical, call);
                             }
                             flushed = true;
                         }
                     }
                     if (!flushed && val != null)
                         preFlushPCs(fmd.getElement(), ((Map) val).values(),
-                            call);
+                            logical, call);
                 }
                 break;
         }
@@ -695,9 +703,9 @@
      * the given keys.
      */
     private void preFlushPCs(ValueMetaData vmd, Collection keys, Map map,
-        OpCallbacks call) {
+        boolean logical, OpCallbacks call) {
         for (Iterator itr = keys.iterator(); itr.hasNext();)
-            preFlushPC(vmd, map.get(itr.next()), call);
+            preFlushPC(vmd, map.get(itr.next()), logical, call);
     }
 
     /**
@@ -705,9 +713,9 @@
      * the given array.
      */
     private void preFlushPCs(ValueMetaData vmd, Object[] objs,
-        OpCallbacks call) {
+        boolean logical, OpCallbacks call) {
         for (int i = 0; i < objs.length; i++)
-            preFlushPC(vmd, objs[i], call);
+            preFlushPC(vmd, objs[i], logical, call);
     }
 
     /**
@@ -715,15 +723,16 @@
      * the given collection.
      */
     private void preFlushPCs(ValueMetaData vmd, Collection objs,
-        OpCallbacks call) {
+        boolean logical, OpCallbacks call) {
         for (Iterator itr = objs.iterator(); itr.hasNext();)
-            preFlushPC(vmd, itr.next(), call);
+            preFlushPC(vmd, itr.next(), logical, call);
     }
 
     /**
      * Perform pre flush operations on the given object.
      */
-    private void preFlushPC(ValueMetaData vmd, Object obj, OpCallbacks call) {
+    private void preFlushPC(ValueMetaData vmd, Object obj, boolean logical,
+        OpCallbacks call) {
         if (obj == null)
             return;
 
@@ -740,7 +749,7 @@
                         Exceptions.toString(_sm.getManagedInstance()))).
                     setFailedObject(obj);
         } else
-            sm = _broker.persist(obj, null, call);
+            sm = _broker.persist(obj, null, true, call);
 
         if (sm != null) {
             // if deleted and not managed inverse, die
@@ -750,6 +759,7 @@
                     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=450916&r1=450915&r2=450916
==============================================================================
--- 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
Thu Sep 28 09:34:05 2006
@@ -369,6 +369,10 @@
         return (_flags & FLAG_FLUSHED_DIRTY) > 0;
     }
 
+    public boolean wasPreFlushed() {
+        return (_flags & FLAG_PRE_FLUSHED) > 0;
+    }
+
     public BitSet getLoaded() {
         return _loaded;
     }
@@ -996,6 +1000,16 @@
     /**
      * 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));
+    }
+
+    /**
+     * Delegates to the current state.
+     *
      * @see PCState#release
      * @see Broker#release
      */
@@ -1252,6 +1266,10 @@
         return _state.isPendingTransactional();
     }
 
+    public boolean isProvisional() {
+        return _state.isProvisional();
+    }
+
     public boolean isPersistent() {
         return _state.isPersistent();
     }
@@ -2619,6 +2637,9 @@
      * for all strategies that don't require flushing.
      */
     void preFlush(boolean logical, OpCallbacks call) {
+        if ((_flags & FLAG_PRE_FLUSHED) != 0)
+            return;
+
         if (isPersistent()) {
             fireLifecycleEvent(LifecycleEvent.BEFORE_STORE);
             _flags |= FLAG_PRE_FLUSHED;
@@ -2632,7 +2653,7 @@
                 if ((logical || !assignField(i, true)) && !_flush.get(i)
                     && _dirty.get(i)) {
                     provideField(_pc, _single, i);
-                    if (_single.preFlush(call))
+                    if (_single.preFlush(logical, call))
                         replaceField(_pc, _single, i);
                     else
                         _single.clear();

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java?view=diff&rev=450916&r1=450915&r2=450916
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
Thu Sep 28 09:34:05 2006
@@ -59,7 +59,7 @@
 
     public Object attach(AttachManager manager, Object toAttach,
         ClassMetaData meta, PersistenceCapable into, OpenJPAStateManager owner,
-        ValueMetaData ownerMeta) {
+        ValueMetaData ownerMeta, boolean explicit) {
         BrokerImpl broker = manager.getBroker();
         PersistenceCapable pc = (PersistenceCapable) toAttach;
 
@@ -82,7 +82,8 @@
             sm = (StateManagerImpl) broker.embed(into, null, owner, ownerMeta);
             into = sm.getPersistenceCapable();
         } else if (isNew) {
-            sm = persist(manager, pc, meta, ApplicationIds.create(pc, meta));
+            sm = persist(manager, pc, meta, ApplicationIds.create(pc, meta),
+                explicit);
             into = sm.getPersistenceCapable();
         } else if (!embedded && into == null) {
             Object id = getDetachedObjectId(manager, toAttach);
@@ -235,8 +236,8 @@
         PersistenceCapable intoPC = (into == null) ? null
             : into.getPersistenceCapable();
         if (vmd.isEmbedded())
-            return manager.attach(pc, intoPC, sm, vmd);
-        return manager.attach(pc, intoPC, null, null);
+            return manager.attach(pc, intoPC, sm, vmd, false);
+        return manager.attach(pc, intoPC, null, null, false);
     }
 
     /**



Mime
View raw message