openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1339509 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Date Thu, 17 May 2012 07:55:42 GMT
Author: struberg
Date: Thu May 17 07:55:41 2012
New Revision: 1339509

URL: http://svn.apache.org/viewvc?rev=1339509&view=rev
Log:
OPENJPA-2197 fix lifecycle method detection

This commit fixes a problem to pick up a JPA lifecycle method
like @PrePersist if there is a method with the same name
(but different parameters) in the class as well.

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java?rev=1339509&r1=1339508&r2=1339509&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/ListenerImpl.java
Thu May 17 07:55:41 2012
@@ -51,6 +51,14 @@ public class ListenerImpl {
         postLoadCount++;
     }
 
+    // dummy methods for testing OPENJPA-2197
+    public void postLoad(int someotherValue, String dummyParameter) {
+        // do nothing. This just breaks the other method ... ;)
+    }
+    public void postLoad(int someotherValue) {
+        // do nothing. This just breaks the other method ... ;)
+    }
+
     @PreUpdate
     public void preUpdate(Object o) {
         preUpdateCount++;

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=1339509&r1=1339508&r2=1339509&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Thu May 17 07:55:41 2012
@@ -2017,14 +2017,33 @@ public class AnnotationPersistenceMetaDa
                 if (c1.isAssignableFrom(c2))
                     return -1;
                 else
-					return 1;
-			}
-			int compare = m1.getName ().compareTo (m2.getName ());
-			if (compare == 0)
-				return m1.hashCode () - m2.hashCode ();
-			return compare;
-		}
-	}
+                    return 1;
+            }
+            int compare = m1.getName().compareTo(m2.getName ());
+            if (compare != 0) {
+                return compare;
+            }
+
+            Class<?>[] params1 = m1.getParameterTypes();
+            Class<?>[] params2 = m2.getParameterTypes();
+            compare = params1.length - params2.length;
+            if (compare != 0) {
+                return compare;
+            }
+
+            // Just using the Method#hashCode() is not enough as it only contains
+            // the hash of the class + the hash of the NAME of the method...
+            // Thus if they have the same number of parameters, we need to compare them all
+            for (int i = 0; i < params1.length; i++) {
+                compare = params1[i].hashCode() - params2[i].hashCode();
+                if (compare != 0) {
+                    return compare;
+                }
+            }
+
+            return 0;
+        }
+    }
     
     /**
      * An internal class used to mimic the FetchGroup annotation.



Mime
View raw message