(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Apr 2010 22:09:20 +0000 (22:09 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Apr 2010 22:09:20 +0000 (22:09 +0000)
support/general/src/main/java/org/wamblee/persistence/JpaMergeSupport.java
support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java

index df1ce81d52aab52ee41d135f38220b1ad481f27d..6230656f0f3933a37a879849ded6418c62c83d46 100644 (file)
@@ -81,9 +81,9 @@ 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 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).
+     * 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).
      * 
      * @param aPersistent
      *            Object whose primary key and version are to be set.
@@ -154,9 +154,8 @@ public class JpaMergeSupport {
                 .startsWith("is")) &&
                 !Modifier.isStatic(getter.getModifiers()) &&
                 Modifier.isPublic(getter.getModifiers()) &&
-                getter.getParameterTypes().length == 0 && 
-                getter.getReturnType() != Void.class
-                ) {
+                getter.getParameterTypes().length == 0 &&
+                getter.getReturnType() != Void.class) {
                 Class returnType = getter.getReturnType();
 
                 try {
@@ -173,22 +172,17 @@ public class JpaMergeSupport {
                         Map persistent = (Map) getter.invoke(aPersistent);
                         processMap(merged, persistent, aProcessed);
                     } else if (returnType.isArray()) {
-                        // early detection of whether it is an array of entities
-                        // to avoid performance problems.
-                        EntityAccessor accessor = PersistentFactory
-                            .createEntityAccessor(returnType.getComponentType());
-                        if (accessor != null) {
-                            Object[] merged = (Object[]) getter.invoke(aMerged);
-                            Object[] persistent = (Object[]) getter
-                                .invoke(aPersistent);
-                            if (merged.length != persistent.length) {
-                                throw new IllegalArgumentException("Array sizes differ " + merged.length +
-                                    " " + persistent.length);
-                            }
-                            for (int i = 0; i < persistent.length; i++) {
-                                processPersistent(merged[i], persistent[i],
-                                    aProcessed);
-                            }
+                        Object[] merged = (Object[]) getter.invoke(aMerged);
+                        Object[] persistent = (Object[]) getter
+                            .invoke(aPersistent);
+                        if (merged.length != persistent.length) {
+                            throw new IllegalArgumentException(
+                                "Array sizes differ " + merged.length + " " +
+                                    persistent.length);
+                        }
+                        for (int i = 0; i < persistent.length; i++) {
+                            processPersistent(merged[i], persistent[i],
+                                aProcessed);
                         }
                     } else {
                         Object merged = getter.invoke(aMerged);
@@ -221,8 +215,8 @@ public class JpaMergeSupport {
         Object[] persistent = aPersistent.toArray();
 
         if (merged.length != persistent.length) {
-            throw new IllegalArgumentException("Array sizes differ " + merged.length +
-                " " + persistent.length);
+            throw new IllegalArgumentException("Array sizes differ " +
+                merged.length + " " + persistent.length);
         }
 
         for (int i = 0; i < merged.length; i++) {
@@ -245,8 +239,8 @@ public class JpaMergeSupport {
     public static void processSet(Set aMerged, Set aPersistent,
         List<ObjectElem> aProcessed) {
         if (aMerged.size() != aPersistent.size()) {
-            throw new IllegalArgumentException("Array sizes differ " + aMerged.size() +
-                " " + aPersistent.size());
+            throw new IllegalArgumentException("Array sizes differ " +
+                aMerged.size() + " " + aPersistent.size());
         }
 
         for (Object merged : aMerged) {
@@ -274,8 +268,8 @@ public class JpaMergeSupport {
     public static <Key, Value> void processMap(Map<Key, Value> aMerged,
         Map<Key, Value> aPersistent, List<ObjectElem> aProcessed) {
         if (aMerged.size() != aPersistent.size()) {
-            throw new IllegalArgumentException("Sizes differ " + aMerged.size() + " " +
-                aPersistent.size());
+            throw new IllegalArgumentException("Sizes differ " +
+                aMerged.size() + " " + aPersistent.size());
         }
 
         Set<Entry<Key, Value>> entries = aMerged.entrySet();
@@ -283,7 +277,8 @@ public class JpaMergeSupport {
         for (Entry<Key, Value> entry : entries) {
             Key key = entry.getKey();
             if (!aPersistent.containsKey(key)) {
-                throw new IllegalArgumentException("Key '" + key + "' not found");
+                throw new IllegalArgumentException("Key '" + key +
+                    "' not found");
             }
 
             Value mergedValue = entry.getValue();
index 0f33c1c261dac9fb7992570f4ae9a78aff669d58..4c706b15084ae9fff3edea70ee5af5173476440c 100644 (file)
@@ -114,7 +114,7 @@ public class ReflectionUtils {
         Class... aExcludedClasses) {
         if (aClass.isInterface()) {
             throw new IllegalArgumentException(aClass.getName() +
-                " is not an interface.");
+                " is an interface.");
         }
         List<Field> found = new ArrayList<Field>();
         getAllFields(aClass, found, Arrays.asList(aExcludedClasses));