Skip to content

Updating Collections

Geoffrey Wiseman edited this page May 21, 2014 · 2 revisions

Moo will do updates on collections and maps, including matching objects, adding and removing.

Matching Objects

In order to update the objects in the destination based on the objects in the source collection, Moo needs to decide which objects correspond to each other. This is of greater import if swapping attribute values might have some consequence, like dirty-checking persistent objects to decide if they should be written to the database.

If you don't intervene, Moo will use iteration order for sets, iteration/index order for lists and keys to match objects across maps. If you'd prefer to intervene, you can identify the matcher to be used by setting the matcher class on the CollectionProperty annotation.

Adding

If an object exists in the source collection but has no match in the destination, moo will translate the source object and add it to to the destination object. Of course, object matching plays a role in deciding whether or not an object can be found in the destination collection.

Because Java collections don't know much about their expected contents due to type erasure of generics, you'll have to specify the item type to which you expect any translations to be performed.

Removing Orphans

If an object exists in the destination collection but is not matched by an object in the source collection, Moo will remove it from the destination during the update. If you want Moo to avoid doing removals, you can configure it to do so by setting removeOrphans=false on CollectionProperty.