ItemState prevState = null;
for (Iterator<ItemState> iter = changesLog.getAllStates().iterator(); iter.hasNext();)
{
ItemState state = iter.next();
ItemData item = state.getData();
if (LOG.isDebugEnabled())
LOG.debug(name + ", onSaveItems() " + ItemState.nameFromValue(state.getState()) + " "
+ item.getQPath().getAsString() + " " + item.getIdentifier() + " parent:" + item.getParentIdentifier());
try
{
if (state.isAdded())
{
put(item);
}
else if (state.isDeleted())
{
remove(item);
}
else if (state.isRenamed())
{
// MOVE operation (DESTENATION changes, same as ADDED), states for whole subtree!
// RENAME goes before DELETE
put(item);
}
else if (state.isUpdated())
{
// UPDATE occurs on reordered (no subtree!) and merged nodes (for each
// merged-updated)
if (item.isNode())
{
if (prevState != null)
{
// play only for reorder, UPDATE goes after DELETE of same path
// item
// we have to unload node and its parent child nodes to be loaded
// back from the persistence
if (prevState.isDeleted()
&& prevState.getData().getParentIdentifier().equals(item.getParentIdentifier()))
removeSiblings((NodeData)item);
}
}
else if (item.getQPath().getName().equals(Constants.EXO_PERMISSIONS))
{
// TODO EXOJCR-12 place to put workaround for JCR cache exo:permissions updated
// get parent Node
// check if parent is mix:privilegeable
ItemData parent = get(item.getParentIdentifier());
// delete parent
remove(parent);
writeLock.lock();
try
{
// delete parent containing child nodes list
nodesCache.remove(parent.getParentIdentifier());
// traverse itemCache
Iterator<CacheValue> cacheIterator = cache.values().iterator();
while (cacheIterator.hasNext())
{
ItemData cachedItem = cacheIterator.next().getItem();
if (cachedItem.isNode())
{
if (cachedItem.getQPath().isDescendantOf(parent.getQPath()))
{
cacheIterator.remove();
}
}
}