From: erik Date: Fri, 30 Apr 2010 14:02:00 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.2.2^2~23 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=03a7ad865b594ca2e46862d15b53fb559a96c7d0;p=utils --- diff --git a/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java b/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java index 1a9be6f2..6d6cde0f 100644 --- a/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java +++ b/security/impl/src/main/java/org/wamblee/usermgt/jpa/JpaGroupSet.java @@ -7,6 +7,7 @@ import java.util.TreeSet; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; +import org.wamblee.persistence.JpaMergeSupport; import org.wamblee.usermgt.Group; import org.wamblee.usermgt.GroupSet; @@ -52,7 +53,8 @@ public class JpaGroupSet implements GroupSet { @Override public void groupModified(Group aGroup) { assert aGroup.getPrimaryKey() != null; - em.merge(aGroup); + Group merged = em.merge(aGroup); + JpaMergeSupport.merge(merged, aGroup); } @Override diff --git a/support/general/src/main/java/org/wamblee/persistence/JpaMergeSupport.java b/support/general/src/main/java/org/wamblee/persistence/JpaMergeSupport.java index be188e2d..df1ce81d 100644 --- a/support/general/src/main/java/org/wamblee/persistence/JpaMergeSupport.java +++ b/support/general/src/main/java/org/wamblee/persistence/JpaMergeSupport.java @@ -81,7 +81,7 @@ public class JpaMergeSupport { /** * Copies primary keys and version from the result of the merged to the * object that was passed to the merge operation. It does this by traversing - * the properties of the object. It copies the primary key and version for + * the public properties of the object. It copies the primary key and version for * objects that implement {@link Persistent} and applies the same rules to * objects in maps and sets as well (i.e. recursively). * @@ -152,7 +152,11 @@ public class JpaMergeSupport { for (Method getter : methods) { if ((getter.getName().startsWith("get") || getter.getName() .startsWith("is")) && - !Modifier.isStatic(getter.getModifiers())) { + !Modifier.isStatic(getter.getModifiers()) && + Modifier.isPublic(getter.getModifiers()) && + getter.getParameterTypes().length == 0 && + getter.getReturnType() != Void.class + ) { Class returnType = getter.getReturnType(); try { diff --git a/support/general/src/test/java/org/wamblee/persistence/JpaMergeSupportTest.java b/support/general/src/test/java/org/wamblee/persistence/JpaMergeSupportTest.java index 3e92799b..c906fb19 100644 --- a/support/general/src/test/java/org/wamblee/persistence/JpaMergeSupportTest.java +++ b/support/general/src/test/java/org/wamblee/persistence/JpaMergeSupportTest.java @@ -127,6 +127,28 @@ public class JpaMergeSupportTest { return array; } } + + private static class X6 { + @Id + int id; + + public X1 getNotaGetter(String aMessage) { + return null; + } + + public void getNotaGetter2() { + + } + } + + private static class X7 { + @Id + int id; + + private void getX() { + fail("Private getters should not be used"); + } + } @Test public void testSimple() { @@ -360,4 +382,22 @@ public class JpaMergeSupportTest { JpaMergeSupport.merge(x, y); } + @Test + public void testNotAGetter() { + X6 x = new X6(); + x.id = 100; + X6 y = new X6(); + + JpaMergeSupport.merge(x,y); + assertEquals(x.id, y.id); + } + + @Test + public void testPrivateGetter() { + X7 x = new X7(); + x.id = 100; + X7 y = new X7(); + JpaMergeSupport.merge(x,y); + assertEquals(x.id, y.id); + } }