Authors: Rob van Maris (Finalist IT Group)
Last revision: Januari 18th, 2002

Introduction

The most important new concept introduced by XML Importer is merging objects. The XML Importer code will handle most of the details for you, and in order to put this to work, all you will have to do is provide implementations for these interfaces: . The XML Importer provides basic implementations for both of these, but some additional work will be necessary to meet your needs.

In this document we'll have a look at some of the issues involved, and give some guidelines.

SimilarObjectFinder

When we have populated a transaction with (access and input) objects, we can merge all objects of a given type. In order to do so, the XML Importer performs these actions:
  1. Walk through the list of objects in the transaction - in the order they were added to the transaction - of the given type.
  2. For each such object, look for a similar object.
  3. If a similar object is found, merge both objects to a single object.
  4. If more than one similar object is found, the transaction cannot proceed, unless the user can choose the object to merge with.
The SimilarObjectFinder is needed to implement step 2. One fairly general way to do this is implemented by BasicFinder, which makes a distinction between exact matches (i.e. indistinguishable) and non-exact matches (e.g. different, but considered to be the same, based on some specified criteria - i.e. fuzzy comparison):
  1. Walk through the list of objects in the transaction, that were added before this one, compare these with this object, and keep the results as a list of exact matches and a list of non-exact matches.
  2. Look for exact matches in the persistent cloud
  3. If exact matches were found in step 1 or 2, these are returned as the result of the search.
  4. Otherwise, look for objects in the persistent cloud that are close enough to warrant further inspection, and compare these with this object.
  5. If non-exact matches were found in step 1 or 4, these are returned as the result of the search.
This strategy has these characteristics: For examples of implementation based on BasicFinder, see MoviesFinder and PersonsFinder in the XML Importer examples code.

ObjectMerger

The ObjectMerger is needed to implement merging two objects to a single object. In order to do so, the XML Importer performs these actions:
  1. If one of the objects represents a persistent object, this object is made the merge target, e.g. the object that will hold the merge result.
  2. The fields of both objects are merged - the resulting fields are set on the merge target.
  3. The relations of both objects are merged - the resulting relations are set to the merge target.
  4. If step 3 results in duplicate relations, the duplicating relations are deleted.
  5. Of the two objects, only the merge target is retained - the object that is not the merge target is deleted.
  6. If there was no similar object to merge with, this object will only be kept in the transaction if the ObjectMerger specifies so (see method isAllowedToAdd() in ObjectMerger).
A fairly general implementation is provided by BasicMerger, which has these characteristics:

Tips

Performance issues

Merging objects can put a heavy stress on the MMBase server and database, so it is important to be aware of the following perfomance issues.

Documentation

For a full unterstanding of the XML Importer, it is recommended to read the following documents, available on the MMBase website:
  1. TCP 1.0 documentation (see Temporary Cloud Project).
  2. XML Importer overview (see XML Importer Project).
  3. The javadoc documentation of the org.mmbase.applications.xmlimporter package.