/**
* 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.
.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 {
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);
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++) {
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) {
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();
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();