From 0dd127ebfc98d49c18d3b1d8157d0d85e77b572a Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 30 Apr 2010 22:09:20 +0000 Subject: [PATCH] --- .../wamblee/persistence/JpaMergeSupport.java | 53 +++++++++---------- .../wamblee/reflection/ReflectionUtils.java | 2 +- 2 files changed, 25 insertions(+), 30 deletions(-) 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 df1ce81d..6230656f 100644 --- a/support/general/src/main/java/org/wamblee/persistence/JpaMergeSupport.java +++ b/support/general/src/main/java/org/wamblee/persistence/JpaMergeSupport.java @@ -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 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 void processMap(Map aMerged, Map aPersistent, List 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> entries = aMerged.entrySet(); @@ -283,7 +277,8 @@ public class JpaMergeSupport { for (Entry 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(); diff --git a/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java b/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java index 0f33c1c2..4c706b15 100644 --- a/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java +++ b/support/general/src/main/java/org/wamblee/reflection/ReflectionUtils.java @@ -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 found = new ArrayList(); getAllFields(aClass, found, Arrays.asList(aExcludedClasses)); -- 2.31.1