openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1055128 - in /openjpa/branches/2.1.x: openjpa-kernel/src/main/java/org/apache/openjpa/enhance/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kernel/src/test/java/org/a...
Date Tue, 04 Jan 2011 18:19:39 GMT
Author: curtisr7
Date: Tue Jan  4 18:19:38 2011
New Revision: 1055128

URL: http://svn.apache.org/viewvc?rev=1055128&view=rev
Log:
OPENJPA-1896: Merging changes from trunk.

Added:
    openjpa/branches/2.1.x/openjpa-kernel/src/test/java/org/apache/openjpa/meta/TestJavaTypes.java
      - copied unchanged from r1052025, openjpa/trunk/openjpa-kernel/src/test/java/org/apache/openjpa/meta/TestJavaTypes.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntegerVersionEntity.java
      - copied unchanged from r1052025, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntegerVersionEntity.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestMergeNoStateManager.java
      - copied unchanged from r1052025, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/TestMergeNoStateManager.java
Modified:
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/JavaTypes.java
    openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java?rev=1055128&r1=1055127&r2=1055128&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java
Tue Jan  4 18:19:38 2011
@@ -3261,15 +3261,14 @@ public class PCEnhancer { 
                 ifins.setTarget(code.nop());
                 // if (pcVersionInit != false)
                 // return true
-                // else return false;
+                // else return null; //  (returning null because we don't know the correct
answer)
                 loadManagedInstance(code, false);
                 getfield(code, null, VERSION_INIT_STR);
                 ifins = code.ifeq();
                 code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
                 code.areturn();
                 ifins.setTarget(code.nop());
-                code.getstatic().setField(Boolean.class, "FALSE", Boolean.class);
-                
+                code.constant().setNull();                
             }
             code.areturn();
             return false;

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java?rev=1055128&r1=1055127&r2=1055128&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/VersionAttachStrategy.java
Tue Jan  4 18:19:38 2011
@@ -18,12 +18,15 @@
  */
 package org.apache.openjpa.kernel;
 
+import java.lang.reflect.Field;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.enhance.Reflection;
 import org.apache.openjpa.enhance.StateManager;
+import org.apache.openjpa.event.LifecycleEvent;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
@@ -31,10 +34,9 @@ import org.apache.openjpa.meta.JavaTypes
 import org.apache.openjpa.meta.ValueMetaData;
 import org.apache.openjpa.meta.ValueStrategies;
 import org.apache.openjpa.util.ApplicationIds;
+import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.ObjectNotFoundException;
 import org.apache.openjpa.util.OptimisticException;
-import org.apache.openjpa.util.ImplHelper;
-import org.apache.openjpa.event.LifecycleEvent;
 
 /**
  * Handles attaching instances using version and primary key fields.
@@ -175,9 +177,29 @@ class VersionAttachStrategy
      */
     private void compareVersion(StateManagerImpl sm, PersistenceCapable pc) {
         Object version = pc.pcGetVersion();
-        if (version == null)
+        // In the event that the version field is a primitive and it is the types default
value, we can't differentiate
+        // between a value that was set to be the default, and one that defaulted to that
value.
+        if (version != null 
+                && JavaTypes.isPrimitiveDefault(version, sm.getMetaData().getVersionField().getTypeCode()))
{
+            Field pcVersionInitField = null;
+            try {
+                pcVersionInitField = pc.getClass().getDeclaredField("pcVersionInit");
+                Object pcField = Reflection.get(pc, pcVersionInitField);
+                if (pcField != null) {
+                    boolean bool = (Boolean) pcField;
+                    if (bool == false) {
+                        // If this field if false, that means that the pcGetVersion returned
a default value rather than
+                        // and actual value.
+                        version = null;
+                    }
+                }
+            } catch (Exception e) {
+                // Perhaps this is an Entity that was enhanced before the pcVersionInit field
was added. 
+            }
+        }
+        if (version == null) {
             return;
-
+        }
         // don't need to load unloaded fields since its implicitly
         // a single field value
         StoreManager store = sm.getBroker().getStoreManager();

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/JavaTypes.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/JavaTypes.java?rev=1055128&r1=1055127&r2=1055128&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/JavaTypes.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/JavaTypes.java
Tue Jan  4 18:19:38 2011
@@ -435,4 +435,31 @@ public class JavaTypes {
             Array.set(array, idx, itr.next ());
 		return array;
 	}
+    
+    /**
+     * Determine whether or not the provided Object value is the default for the provided
typeCode.
+     * 
+     * For example: If o = Integer(0) and typeCode = JavaTypes.INT, this method will return
true.
+     */
+    public static boolean isPrimitiveDefault(Object o, int typeCode) {
+        switch (typeCode) {
+            case BOOLEAN:
+                return ((Boolean) o).equals(Boolean.FALSE) ? true : false;
+            case BYTE:
+                return ((Byte) o) == 0 ? true : false;
+            case SHORT:
+                return ((Short) o) == 0 ? true : false;
+            case INT:
+                return ((Integer) o) == 0 ? true : false;
+            case LONG:
+                return ((Long) o) == 0L ? true : false;
+            case FLOAT:
+                return ((Float) o) == 0.0F ? true : false;
+            case CHAR:
+                return ((Character) o) == '\u0000' ? true : false;
+            case DOUBLE:
+                return ((Double) o) == 0.0d ? true : false;
+        }
+        return false;
+    }
 }

Modified: openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java?rev=1055128&r1=1055127&r2=1055128&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/detach/IntVersionEntity.java
Tue Jan  4 18:19:38 2011
@@ -18,6 +18,8 @@
  */
 package org.apache.openjpa.persistence.detach;
 
+import java.io.Serializable;
+
 import javax.persistence.CascadeType;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
@@ -26,7 +28,7 @@ import javax.persistence.OneToOne;
 import javax.persistence.Version;
 
 @Entity
-public class IntVersionEntity {
+public class IntVersionEntity implements Serializable {
     
     @Id
     private int id;



Mime
View raw message