openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r615313 - in /openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel: AttachManager.java VersionAttachStrategy.java
Date Fri, 25 Jan 2008 19:32:22 GMT
Author: pcl
Date: Fri Jan 25 11:32:22 2008
New Revision: 615313

URL: http://svn.apache.org/viewvc?rev=615313&view=rev
Log:
OPENJPA-245

Modified:
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java?rev=615313&r1=615312&r2=615313&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AttachManager.java
Fri Jan 25 11:32:22 2008
@@ -98,11 +98,7 @@
 
         CallbackException excep = null;
         try {
-            PersistenceCapable into = findFromDatabase(pc);
-            OpenJPAStateManager owner = (into == null) ? null
-                    : (OpenJPAStateManager) into.pcGetStateManager();
-            return attach(pc, into, owner, null, true);
-
+            return attach(pc, null, null, null, true);
         } catch (CallbackException ce) {
             excep = ce;
             return null; // won't be reached as the exceps will be rethrown
@@ -339,30 +335,4 @@
                 Exceptions.toString(obj))).setFailedObject (obj);
 		return sm;
 	}
-
-    /**
-     * Find a PersistenceCapable instance of an Object if it exists in the 
-     * database. If the object is null or can't be found in the database.  
-     *  
-     * @param pc An object which will be attached into the current context. The 
-     * object may or may not correspond to a row in the database. 
-     * 
-     * @return If the object is null or can't be found in the database this 
-     * method returns null. Otherwise a PersistenceCapable representation of the
-     * object is returned.
-     */
-    protected PersistenceCapable findFromDatabase(Object pc) {
-        PersistenceCapable rval = null;
-
-        if (pc != null) {
-            Object oid = _broker.newObjectId(pc.getClass(),
-                    getDetachedObjectId(pc));
-
-            if (oid != null) {
-                rval = ImplHelper.toPersistenceCapable(_broker.find(oid, true,
-                        null), getBroker().getConfiguration());
-            }
-        }
-        return rval;
-    }
 }

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java?rev=615313&r1=615312&r2=615313&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
Fri Jan 25 11:32:22 2008
@@ -68,6 +68,13 @@
     public Object attach(AttachManager manager, Object toAttach,
         ClassMetaData meta, PersistenceCapable into, OpenJPAStateManager owner,
         ValueMetaData ownerMeta, boolean explicit) {
+
+        // VersionAttachStrategy is invoked in the case where no more
+        // intelligent strategy could be found; let's be more lenient
+        // about new vs. detached record determination.
+        if (into == null)
+            into = findFromDatabase(manager, toAttach);
+
         BrokerImpl broker = manager.getBroker();
         PersistenceCapable pc = ImplHelper.toPersistenceCapable(toAttach,
             meta.getRepository().getConfiguration());
@@ -342,4 +349,29 @@
         }
         return (copy == null) ? map : copy;
 	}
+
+    /**
+     * Find a PersistenceCapable instance of an Object if it exists in the
+     * database. If the object is null or can't be found in the database.
+     *
+     * @param pc An object which will be attached into the current context. The
+     * object may or may not correspond to a row in the database.
+     *
+     * @return If the object is null or can't be found in the database this
+     * method returns null. Otherwise a PersistenceCapable representation of the
+     * object is returned.
+     */
+    protected PersistenceCapable findFromDatabase(AttachManager manager,
+        Object pc) {
+        Object oid = manager.getBroker().newObjectId(pc.getClass(),
+            manager.getDetachedObjectId(pc));
+
+        if (oid != null) {
+            return ImplHelper.toPersistenceCapable(
+                manager.getBroker().find(oid, true, null),
+                manager.getBroker().getConfiguration());
+        } else {
+            return null;
+        }
+    }
 }



Mime
View raw message