Well, since no-one seems to have gotten back to you, I will offer up
our solution to a (very loosely) similar situation. At the least it may
point you in the right direction, or help others who search this forum
(as I did) before coming up with it. However, our scenario was using OCM
with custom, and sometimes versioned, Objects. We needed an import
process that would import the version history, but we only needed to
deal with any one of the following scenarios at one time:
* Update existing Object (which would take the incoming import and
create new versions, in addition to the existing versions there)
* Overwrite existing Object (delete the existing, and use only the
imported version(s))
* Do nothing (exactly that, go to the next Object).
We didn't need to take note of Objects disappearing. We used the
following (quasi-)code to manage importing, where the user was able to
pick how to deal with import from the above 3 bullets. (This is probably
over complicated for your purposes).
<code>
public enum ImportMode {
UPDATE,
OVERWRITE,
DO_NOTHING,
DEFAULT; //this is for use by our system only, and not something users
can specify
}
public synchronized void importRepository (String importFile, ImportMode
importMode ) {
/*
* We used JAXB to marshal on export, and unmarshal on import
* our OCM Objects with their version histories from an XML file.
*/
OurRepository importedRepo; //custom class to manage our Objects with
their histories.
Unmarshaller um = JAXBContext.newInstance
(OurRepository.class).createUnmarshaller();
importedRepo = (OurRepository)um.unmarshal(new FileReader(importFile));
ImportMode modeForLooping;
//for each node/object in import file, in our case on a name basis
for ( String objName : importedRepo.getObjectList().keySet() ) {
if (node/object DOES NOT exist in this Jackrabbit repo)
modeForLooping = ImportMode.DEFAULT;//system deals with
these
else (node/object DOES exist in this Jackrabbit repo )
modeForLooping = importMode; //if it exists, do what
the user specified.
/* Retrieve this Objects history however you exported.
* We used a custom class (ObjectHistory) to manage
* exporting/importing the histories.
*/
ObjectHistory objHistory =
importedRepo.getObjectList().get(objName);
//OurObject is what we store in OCM
Iterator<OurObject> sortedObjIter =
objHistory.getAllVersions().values().iterator();
OurObject thisObj;
switch ( modeForLooping ) {
case DO_NOTHING:
continue;// go for next OurObject! well, you
may want to log the event.
case OVERWRITE:
ocm.remove (objName);
ocm.save;
//deliberately fall through, so after we
removed old one, we can add the new one.
case DEFAULT: //also used if OurObject with objName did
not exist already
thisObj = sortedObjIter.next();
/*
* remember we had to deal with histories:
* historical versions have different paths,
* which we want to reset to force updates.
*/
thisObj.setPath (
OurUtilityClass.convertNameToPath (objName));
/*
* if path was /north/south/east/west, make sure
* /north/south/east is in the OCM already.
*/
insertFillers (thisObj.getPath()); //custom
method
ocm.insert (thisObj)
ocm.save();
ocm.checkin (thisObj.getPath());
//again deliberately fall through to deal with
the version history of this Object
case UPDATE:
while (sortedObjIter.hasNext()) {
thisObj = sortedObjIter.next();
thisObj.setPath(
OurUtilityClass.convertNameToPath(objName));
ocm.checkout ( thisObj.getPath());
ocm.update ( thisObj);
ocm.save();
ocm.checkin (thisObj.getPath());
}
break;
}
}
}
</code>
Good luck!
H. Wilson
On 08/11/2010 01:51 PM, ChadDavis wrote:
Hello. My application loads some meta/config data at bootstrap. I
import the data from an xml file. Currently, I just remove the
existing tree and replace it with the incoming xml data. I would like
to enhance this algorithm to be an intelligent update process. I
would like to be able to take note of nodes that are going to
disappear, nodes that are new, as well as modifications to nodes.
I'm working on my algorithm and researching the JCR API's that might
help me out.
If you have any suggestions on how to go about such a task, please let me know.