Author: pnedonosko
Date: 2009-12-25 04:13:17 -0500 (Fri, 25 Dec 2009)
New Revision: 1177
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EOXJCR-333 cleanup and members original sort
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-25
09:12:27 UTC (rev 1176)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2009-12-25
09:13:17 UTC (rev 1177)
@@ -134,8 +134,134 @@
protected final Fqn<String> refsRoot;
- protected boolean txStarted = false;
+ /**
+ * Node order comparator for getChildNodes().
+ */
+ class NodesOrderComparator<N extends NodeData> implements
Comparator<NodeData>
+ {
+ /**
+ * {@inheritDoc}
+ */
+ public int compare(NodeData n1, NodeData n2)
+ {
+ return n1.getOrderNumber() - n2.getOrderNumber();
+ }
+ }
+
+ class ChildItemsIterator<T extends ItemData> implements Iterator<T>
+ {
+
+ final Iterator<Object> childs;
+
+ final String parentId;
+
+ final Fqn<String> root;
+
+ T next;
+
+ ChildItemsIterator(Fqn<String> root, String parentId)
+ {
+ this.parentId = parentId;
+ this.root = root;
+
+ Fqn<String> parentFqn = makeChildListFqn(root, parentId);
+ // TODO replace getNode with get attr -> use ITEMS with CHILDS etc
+ Node<Serializable, Object> parent = cache.getNode(parentFqn);
+ if (parent != null)
+ {
+ this.childs = cache.getChildrenNames(parentFqn).iterator();
+ fetchNext();
+ }
+ else
+ {
+ this.childs = null;
+ this.next = null;
+ }
+ }
+
+ protected void fetchNext()
+ {
+ if (childs.hasNext())
+ {
+ // traverse to the first existing or the end of childs
+ T n = null;
+ do
+ {
+ String itemId = (String)cache.get(makeChildListFqn(root, parentId,
(String)childs.next()), ITEM_ID);
+ if (itemId != null)
+ {
+ n = (T)cache.get(makeItemFqn(itemId), ITEM_DATA);
+ }
+ }
+ while (n == null && childs.hasNext());
+ next = n;
+ }
+ else
+ {
+ next = null;
+ }
+ }
+
+ public boolean hasNext()
+ {
+ return next != null;
+ }
+
+ public T next()
+ {
+ if (next == null)
+ {
+ throw new NoSuchElementException();
+ }
+
+ final T current = next;
+ fetchNext();
+ return current;
+ }
+
+ public void remove()
+ {
+ throw new IllegalArgumentException("Not implemented");
+ }
+ }
+
+ class ChildNodesIterator<N extends NodeData> extends
ChildItemsIterator<N>
+ {
+
+ ChildNodesIterator(String parentId)
+ {
+ super(childNodes, parentId);
+ }
+
+ @Override
+ public N next()
+ {
+ return super.next();
+ }
+ }
+
+ class ChildPropertiesIterator<P extends PropertyData> extends
ChildItemsIterator<P>
+ {
+
+ ChildPropertiesIterator(String parentId)
+ {
+ super(childProps, parentId);
+ }
+
+ @Override
+ public P next()
+ {
+ return super.next();
+ }
+ }
+
+ public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig) throws
RepositoryException,
+ RepositoryConfigurationException
+ {
+ this(readJBCConfig(wsConfig));
+ }
+
/**
* JBossCacheWorkspaceStorageCache constructor.
*
@@ -148,19 +274,19 @@
this.cache.create();
this.cache.start();
- //this.cache.addInterceptor(indexInterceptor, CacheStoreInterceptor.class);
+ // TODO this.cache.addInterceptor(indexInterceptor, CacheStoreInterceptor.class);
Node<Serializable, Object> cacheRoot = cache.getRoot();
- // TODO transaction
-
// prepare cache structures
+ // TODO transaction
TransactionManager tm = getTransactionManager();
try
{
tm.begin();
+
this.itemsRoot = Fqn.fromElements(ITEMS);
cacheRoot.addChild(this.itemsRoot).setResident(true);
@@ -201,21 +327,104 @@
throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
}
+ }
+ protected static String readJBCConfig(final WorkspaceEntry wsConfig) throws
RepositoryConfigurationException
+ {
+ if (wsConfig.getCache() != null)
+ {
+ return wsConfig.getCache().getParameterValue(JBOSSCACHE_CONFIG);
+ }
+ else
+ {
+ throw new RepositoryConfigurationException("Cache configuration not
found");
+ }
}
- public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig) throws
RepositoryException,
- RepositoryConfigurationException
+ /**
+ * Return TransactionManager.
+ * @return TransactionManager.
+ */
+ public TransactionManager getTransactionManager()
{
- this(readJBCConfig(wsConfig));
+ return ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
}
/**
* {@inheritDoc}
*/
- public void addChildNodes(NodeData parent, List<NodeData> childs)
+ public void put(ItemData item)
{
+ putItem(item);
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public void remove(ItemData item)
+ {
+ removeItem(item);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onSaveItems(final ItemStateChangesLog itemStates)
+ {
+ for (ItemState state : itemStates.getAllStates())
+ {
+ if (state.isAdded())
+ {
+ if (state.isPersisted())
+ {
+ putItem(state.getData());
+ }
+ }
+ else if (state.isUpdated())
+ {
+ if (state.isPersisted())
+ {
+ ItemData prevItem = putItem(state.getData());
+ if (prevItem != null && state.isNode())
+ {
+ // nodes reordered, if prev is null it's InvalidItemState case
+ update((NodeData)state.getData(), (NodeData)prevItem);
+ }
+ }
+ }
+ else if (state.isDeleted())
+ {
+ removeItem(state.getData());
+ }
+ else if (state.isRenamed())
+ {
+ // TODO cleanup: update subtree paths
+ // if (prevState.isDeleted() && prevState.isNode())
+ // {
+ // renameNode((NodeData)prevState.getData(),
(NodeData)state.getData());
+ // }
+ putItem(state.getData());
+ }
+ else if (state.isMixinChanged())
+ {
+ if (state.isPersisted())
+ {
+ // update subtree ACLs
+ updateMixin((NodeData)state.getData());
+ }
+ }
+ else
+ {
+ // TODO warn it?
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addChildNodes(NodeData parent, List<NodeData> childs)
+ {
// remove previous all (to be sure about consistency)
cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
@@ -232,7 +441,6 @@
// cache fact of empty childs list
cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
}
-
}
/**
@@ -240,7 +448,6 @@
*/
public void addChildProperties(NodeData parent, List<PropertyData> childs)
{
-
// remove previous all (to be sure about consistency)
cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
@@ -256,7 +463,6 @@
{
LOG.warn("Empty properties list cached " + (parent != null ?
parent.getQPath().getAsString() : parent));
}
-
}
/**
@@ -281,14 +487,6 @@
/**
* {@inheritDoc}
*/
- public ItemData get(String id)
- {
- return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
- }
-
- /**
- * {@inheritDoc}
- */
public ItemData get(String parentId, QPathEntry name)
{
@@ -311,6 +509,14 @@
/**
* {@inheritDoc}
*/
+ public ItemData get(String id)
+ {
+ return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public List<NodeData> getChildNodes(final NodeData parent)
{
final List<NodeData> childs = new ArrayList<NodeData>();
@@ -351,120 +557,12 @@
/**
* {@inheritDoc}
*/
- public long getSize()
- {
- // TODO
- return -1;
- }
-
- /**
- * Return TransactionManager.
- * @return TransactionManager.
- */
- public TransactionManager getTransactionManager()
- {
- return ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isEnabled()
- {
- // TODO
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
public List<PropertyData> listChildProperties(NodeData parent)
{
return getChildProps(parent.getIdentifier(), false);
}
/**
- * {@inheritDoc}
- */
- public void onSaveItems(final ItemStateChangesLog itemStates)
- {
-
- ItemState prevState = null;
-
- for (ItemState state : itemStates.getAllStates())
- {
-
- if (state.isAdded())
- {
- if (state.isPersisted())
- {
- putItem(state.getData());
- }
- }
- else if (state.isUpdated())
- {
- if (state.isPersisted())
- {
- ItemData prevItem = putItem(state.getData());
- if (prevItem != null && state.isNode())
- {
- // nodes reordered, if prev is null it's InvalidItemState case
- update((NodeData)state.getData(), (NodeData)prevItem);
- }
- }
- }
- else if (state.isDeleted())
- {
- removeItem(state.getData());
- }
- else if (state.isRenamed())
- {
- // TODO cleanup: update subtree paths
- // if (prevState.isDeleted() && prevState.isNode())
- // {
- // renameNode((NodeData)prevState.getData(),
(NodeData)state.getData());
- // }
- putItem(state.getData());
- }
- else if (state.isMixinChanged())
- {
- if (state.isPersisted())
- {
- // update subtree ACLs
- updateMixin((NodeData)state.getData());
- }
- }
- else
- {
- // TODO warn it?
- }
-
- prevState = state;
- }
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void put(ItemData item)
- {
-
- putItem(item);
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void remove(ItemData item)
- {
-
- removeItem(item);
-
- }
-
- /**
* Internal get child properties.
*
* @param parentId String
@@ -503,28 +601,47 @@
}
/**
- * Make child Item absolute Fqn, i.e. /root/parentId/childName.
+ * {@inheritDoc}
+ */
+ public long getSize()
+ {
+ // TODO
+ return -1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isEnabled()
+ {
+ // TODO
+ return true;
+ }
+
+ // ****************
+
+ /**
+ * Make Item absolute Fqn, i.e. /$ITEMS/itemID.
*
- * @param root Fqn
- * @param parentId String
- * @param childName QPathEntry
+ * @param itemId String
* @return Fqn
*/
- protected Fqn<String> makeChildFqn(Fqn<String> root, String parentId,
QPathEntry childName)
+ protected Fqn<String> makeItemFqn(String itemId)
{
- return Fqn.fromRelativeElements(root, parentId, childName.getAsString(true));
+ return Fqn.fromRelativeElements(itemsRoot, itemId);
}
/**
- * Make child node parent absolute Fqn, i.e. /root/itemId.
+ * Make child Item absolute Fqn, i.e. /root/parentId/childName.
*
* @param root Fqn
* @param parentId String
+ * @param childName QPathEntry
* @return Fqn
*/
- protected Fqn<String> makeChildListFqn(Fqn<String> root, String parentId)
+ protected Fqn<String> makeChildFqn(Fqn<String> root, String parentId,
QPathEntry childName)
{
- return Fqn.fromRelativeElements(root, parentId);
+ return Fqn.fromRelativeElements(root, parentId, childName.getAsString(true));
}
/**
@@ -541,18 +658,17 @@
}
/**
- * Make Item absolute Fqn, i.e. /$ITEMS/itemID.
+ * Make child node parent absolute Fqn, i.e. /root/itemId.
*
- * @param itemId String
+ * @param root Fqn
+ * @param parentId String
* @return Fqn
*/
- protected Fqn<String> makeItemFqn(String itemId)
+ protected Fqn<String> makeChildListFqn(Fqn<String> root, String parentId)
{
- return Fqn.fromRelativeElements(itemsRoot, itemId);
+ return Fqn.fromRelativeElements(root, parentId);
}
- // ****************
-
/**
* Internal put Item.
*
@@ -696,6 +812,28 @@
}
/**
+ * Update Node's mixin and ACL.
+ *
+ * @param node NodeData
+ */
+ protected void updateMixin(NodeData node)
+ {
+ NodeData prevData = (NodeData)cache.put(makeItemFqn(node.getIdentifier()),
ITEM_DATA, node);
+ if (prevData != null)
+ {
+ // do update ACL if needed
+ if (!prevData.getACL().equals(node.getACL()))
+ {
+ updateChildsACL(node.getIdentifier(), node.getACL());
+ }
+ }
+ else if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Previous NodeData not found for mixin update " +
node.getQPath().getAsString());
+ }
+ }
+
+ /**
* Update Node hierachy in case of same-name siblings reorder.
* Assumes the new (updated) nodes already putted in the cache. Previous name of
updated nodes will be calculated
* and that node will be deleted (if has same id as the new node). Childs paths will
be updated to a new node path.
@@ -728,63 +866,6 @@
}
/**
- * Update child Nodes ACLs.
- *
- * @param parentId String - root node id of JCR subtree.
- * @param acl AccessControlList
- */
- protected void updateChildsACL(final String parentId, final AccessControlList acl)
- {
- for (Iterator<NodeData> iter = new
ChildNodesIterator<NodeData>(parentId); iter.hasNext();)
- {
- NodeData prevNode = iter.next();
-
- // is ACL changes on this node (i.e. ACL inheritance brokes)
- for (InternalQName mixin : prevNode.getMixinTypeNames())
- {
- if (mixin.equals(Constants.EXO_PRIVILEGEABLE) ||
mixin.equals(Constants.EXO_OWNEABLE))
- {
- continue;
- }
- }
-
- // recreate with new path for child Nodes only
- TransientNodeData newNode =
- new TransientNodeData(prevNode.getQPath(), prevNode.getIdentifier(),
prevNode.getPersistedVersion(),
- prevNode.getPrimaryTypeName(), prevNode.getMixinTypeNames(),
prevNode.getOrderNumber(), prevNode
- .getParentIdentifier(), acl);
-
- // update this node
- cache.put(makeItemFqn(newNode.getIdentifier()), ITEM_DATA, newNode);
-
- // update childs recursive
- updateChildsACL(newNode.getIdentifier(), acl);
- }
- }
-
- /**
- * Update Node's mixin and ACL.
- *
- * @param node NodeData
- */
- protected void updateMixin(NodeData node)
- {
- NodeData prevData = (NodeData)cache.put(makeItemFqn(node.getIdentifier()),
ITEM_DATA, node);
- if (prevData != null)
- {
- // do update ACL if needed
- if (!prevData.getACL().equals(node.getACL()))
- {
- updateChildsACL(node.getIdentifier(), node.getACL());
- }
- }
- else if (LOG.isDebugEnabled())
- {
- LOG.debug("Previous NodeData not found for mixin update " +
node.getQPath().getAsString());
- }
- }
-
- /**
* Update Nodes tree with new path.
*
* @param parentId String - root node id of JCR subtree.
@@ -843,138 +924,39 @@
}
}
- class ChildItemsIterator<T extends ItemData> implements Iterator<T>
+ /**
+ * Update child Nodes ACLs.
+ *
+ * @param parentId String - root node id of JCR subtree.
+ * @param acl AccessControlList
+ */
+ protected void updateChildsACL(final String parentId, final AccessControlList acl)
{
-
- final Iterator<Object> childs;
-
- final String parentId;
-
- final Fqn<String> root;
-
- T next;
-
- ChildItemsIterator(Fqn<String> root, String parentId)
+ for (Iterator<NodeData> iter = new
ChildNodesIterator<NodeData>(parentId); iter.hasNext();)
{
- this.parentId = parentId;
- this.root = root;
+ NodeData prevNode = iter.next();
- Fqn<String> parentFqn = makeChildListFqn(root, parentId);
- // TODO replace getNode with get attr -> use ITEMS with CHILDS etc
- Node<Serializable, Object> parent = cache.getNode(parentFqn);
- if (parent != null)
+ // is ACL changes on this node (i.e. ACL inheritance brokes)
+ for (InternalQName mixin : prevNode.getMixinTypeNames())
{
- this.childs = cache.getChildrenNames(parentFqn).iterator();
- fetchNext();
- }
- else
- {
- this.childs = null;
- this.next = null;
- }
- }
-
- public boolean hasNext()
- {
- return next != null;
- }
-
- public T next()
- {
- if (next == null)
- {
- throw new NoSuchElementException();
- }
-
- final T current = next;
- fetchNext();
- return current;
- }
-
- public void remove()
- {
- throw new IllegalArgumentException("Not implemented");
- }
-
- protected void fetchNext()
- {
- if (childs.hasNext())
- {
- // traverse to the first existing or the end of childs
- T n = null;
- do
+ if (mixin.equals(Constants.EXO_PRIVILEGEABLE) ||
mixin.equals(Constants.EXO_OWNEABLE))
{
- String itemId = (String)cache.get(makeChildListFqn(root, parentId,
(String)childs.next()), ITEM_ID);
- if (itemId != null)
- {
- n = (T)cache.get(makeItemFqn(itemId), ITEM_DATA);
- }
+ continue;
}
- while (n == null && childs.hasNext());
- next = n;
}
- else
- {
- next = null;
- }
- }
- }
- class ChildNodesIterator<N extends NodeData> extends
ChildItemsIterator<N>
- {
+ // recreate with new path for child Nodes only
+ TransientNodeData newNode =
+ new TransientNodeData(prevNode.getQPath(), prevNode.getIdentifier(),
prevNode.getPersistedVersion(),
+ prevNode.getPrimaryTypeName(), prevNode.getMixinTypeNames(),
prevNode.getOrderNumber(), prevNode
+ .getParentIdentifier(), acl);
- ChildNodesIterator(String parentId)
- {
- super(childNodes, parentId);
- }
+ // update this node
+ cache.put(makeItemFqn(newNode.getIdentifier()), ITEM_DATA, newNode);
- @Override
- public N next()
- {
- return super.next();
+ // update childs recursive
+ updateChildsACL(newNode.getIdentifier(), acl);
}
}
- class ChildPropertiesIterator<P extends PropertyData> extends
ChildItemsIterator<P>
- {
-
- ChildPropertiesIterator(String parentId)
- {
- super(childProps, parentId);
- }
-
- @Override
- public P next()
- {
- return super.next();
- }
- }
-
- /**
- * Node order comparator for getChildNodes().
- */
- class NodesOrderComparator<N extends NodeData> implements
Comparator<NodeData>
- {
-
- /**
- * {@inheritDoc}
- */
- public int compare(NodeData n1, NodeData n2)
- {
- return n1.getOrderNumber() - n2.getOrderNumber();
- }
- }
-
- protected static String readJBCConfig(final WorkspaceEntry wsConfig) throws
RepositoryConfigurationException
- {
- if (wsConfig.getCache() != null)
- {
- return wsConfig.getCache().getParameterValue(JBOSSCACHE_CONFIG);
- }
- else
- {
- throw new RepositoryConfigurationException("Cache configuration not
found");
- }
- }
-
}