Author: skabashnyuk
Date: 2009-12-24 10:52:07 -0500 (Thu, 24 Dec 2009)
New Revision: 1171
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-334 : code clean up.
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24
15:38:31 UTC (rev 1170)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2009-12-24
15:52:07 UTC (rev 1171)
@@ -61,197 +61,10 @@
protected final Map<Integer, DataRequest> requestCache;
/**
- * ItemData request, used on get operations.
*
*/
- protected class DataRequest
- {
+ private TransactionManager transactionManager;
- /**
- * GET_NODES type.
- */
- static public final int GET_NODES = 1;
-
- /**
- * GET_PROPERTIES type.
- */
- static public final int GET_PROPERTIES = 2;
-
- /**
- * GET_ITEM_ID type.
- */
- static private final int GET_ITEM_ID = 3;
-
- /**
- * GET_ITEM_NAME type.
- */
- static private final int GET_ITEM_NAME = 4;
-
- /**
- * Request type.
- */
- protected final int type;
-
- /**
- * Item parentId.
- */
- protected final String parentId;
-
- /**
- * Item id.
- */
- protected final String id;
-
- /**
- * Item name.
- */
- protected final QPathEntry name;
-
- /**
- * Hash code.
- */
- protected final int hcode;
-
- /**
- * Readiness latch.
- */
- protected CountDownLatch ready = new CountDownLatch(1);
-
- /**
- * DataRequest constructor.
- *
- * @param parentId
- * parent id
- * @param type
- * request type
- */
- DataRequest(String parentId, int type)
- {
- this.parentId = parentId;
- this.name = null;
- this.id = null;
- this.type = type;
-
- // hashcode
- this.hcode = 31 * (31 + this.type) + this.parentId.hashCode();
- }
-
- /**
- * DataRequest constructor.
- *
- * @param parentId
- * parent id
- * @param name
- * Item name
- */
- DataRequest(String parentId, QPathEntry name)
- {
- this.parentId = parentId;
- this.name = name;
- this.id = null;
- this.type = GET_ITEM_NAME;
-
- // hashcode
- int hc = 31 * (31 + this.type) + this.parentId.hashCode();
- this.hcode = 31 * hc + this.name.hashCode();
- }
-
- /**
- * DataRequest constructor.
- *
- * @param id
- * Item id
- */
- DataRequest(String id)
- {
- this.parentId = null;
- this.name = null;
- this.id = id;
- this.type = GET_ITEM_ID;
-
- // hashcode
- this.hcode = 31 * (31 + this.type) + this.id.hashCode();
- }
-
- /**
- * Find the same, and if found wait till the one will be finished.
- *
- * WARNING. This method effective with cache use only!!! Without cache the database
will control
- * requests performance/chaching process.
- *
- * @return this data request
- */
- DataRequest waitSame()
- {
- DataRequest prev = null;
- synchronized (requestCache)
- {
- prev = requestCache.get(this.hashCode());
- }
- if (prev != null)
- prev.await();
- return this;
- }
-
- /**
- * Start the request, each same will wait till this will be finished
- */
- void start()
- {
- synchronized (requestCache)
- {
- requestCache.put(this.hashCode(), this);
- }
- }
-
- /**
- * Done the request. Must be called after the data request will be finished. This
call allow
- * another same requests to be performed.
- */
- void done()
- {
- this.ready.countDown();
- synchronized (requestCache)
- {
- requestCache.remove(this.hashCode());
- }
- }
-
- /**
- * Await this thread for another one running same request.
- *
- */
- void await()
- {
- try
- {
- this.ready.await();
- }
- catch (InterruptedException e)
- {
- LOG.warn("Can't wait for same request process. " + e, e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
- {
- return this.hcode == obj.hashCode();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
- {
- return hcode;
- }
- }
-
/**
* CacheableWorkspaceDataManager constructor.
*
@@ -267,29 +80,62 @@
{
super(dataContainer, systemDataContainerHolder);
this.cache = cache;
+
this.requestCache = new HashMap<Integer, DataRequest>();
addItemPersistenceListener(cache);
+ if (cache instanceof JBossCacheWorkspaceStorageCache)
+ {
+ transactionManager =
((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ }
+ else
+ {
+ transactionManager = null;
+ }
}
/**
- * {@inheritDoc}
+ * Get Items Cache.
+ *
+ * @return WorkspaceStorageCache
*/
- public ItemData getItemData(String identifier) throws RepositoryException
+ public WorkspaceStorageCache getCache()
{
- // 2. Try from cache
- ItemData data = getCachedItemData(identifier);
+ return cache;
+ }
- // 3. Try from container
- if (data == null)
+ public int getChildNodesCount(NodeData parent) throws RepositoryException
+ {
+ if (cache.isEnabled())
{
- return getPersistedItemData(identifier);
+ List<NodeData> childNodes = cache.getChildNodes(parent);
+ if (childNodes != null)
+ {
+ return childNodes.size();
+ }
}
- return data;
+
+ return super.getChildNodesCount(parent);
}
/**
* {@inheritDoc}
*/
+ public List<NodeData> getChildNodesData(NodeData nodeData) throws
RepositoryException
+ {
+ return getChildNodesData(nodeData, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> getChildPropertiesData(NodeData nodeData) throws
RepositoryException
+ {
+ return getChildPropertiesData(nodeData, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ItemData getItemData(NodeData parentData, QPathEntry name) throws
RepositoryException
{
@@ -306,78 +152,121 @@
}
/**
+ * {@inheritDoc}
+ */
+ public ItemData getItemData(String identifier) throws RepositoryException
+ {
+ // 2. Try from cache
+ ItemData data = getCachedItemData(identifier);
+
+ // 3. Try from container
+ if (data == null)
+ {
+ return getPersistedItemData(identifier);
+ }
+ return data;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> getReferencesData(String identifier, boolean
skipVersionStorage)
+ throws RepositoryException
+ {
+ return super.getReferencesData(identifier, skipVersionStorage);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> listChildPropertiesData(NodeData nodeData) throws
RepositoryException
+ {
+ return listChildPropertiesData(nodeData, false);
+ }
+
+ /**
* @see
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#save(org.exoplatform.services.jcr.dataflow.ItemStateChangesLog)
*/
@Override
public void save(ItemStateChangesLog changesLog) throws RepositoryException
{
- TransactionManager tm =
((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
-
- try
+ if (transactionManager == null)
{
- tm.begin();
super.save(changesLog);
- tm.commit();
}
- catch (RollbackException e)
+ else
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (RepositoryException e)
- {
try
{
- tm.rollback();
+ transactionManager.begin();
+ super.save(changesLog);
+ transactionManager.commit();
}
- catch (Exception e1)
+ catch (RollbackException e)
{
- // Treat the exception
+ // Indicate that the transaction has been rolled back rather than committed.
throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
- throw e;
- }
- catch (Exception e)
- {
- try
+ catch (RepositoryException e)
{
- tm.rollback();
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ throw e;
}
- catch (Exception e1)
+ catch (Exception e)
{
- // Treat the exception
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e1.getLocalizedMessage(), e1.getCause());
+ }
throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
}
-
}
/**
- * {@inheritDoc}
+ * Get cached ItemData.
+ *
+ * @param parentData
+ * parent
+ * @param name
+ * Item name
+ * @return ItemData
+ * @throws RepositoryException
+ * error
*/
- public List<NodeData> getChildNodesData(NodeData nodeData) throws
RepositoryException
+ protected ItemData getCachedItemData(NodeData parentData, QPathEntry name) throws
RepositoryException
{
- return getChildNodesData(nodeData, false);
+ return cache.get(parentData.getIdentifier(), name);
}
/**
- * {@inheritDoc}
+ * Returns an item from cache by Identifier or null if the item don't cached.
+ *
+ * @param identifier
+ * Item id
+ * @return ItemData
+ * @throws RepositoryException
+ * error
*/
- public List<PropertyData> getChildPropertiesData(NodeData nodeData) throws
RepositoryException
+ protected ItemData getCachedItemData(String identifier) throws RepositoryException
{
- return getChildPropertiesData(nodeData, false);
+ return cache.get(identifier);
}
/**
- * {@inheritDoc}
- */
- public List<PropertyData> listChildPropertiesData(NodeData nodeData) throws
RepositoryException
- {
- return listChildPropertiesData(nodeData, false);
- }
-
- /**
* Get child NodesData.
*
* @param nodeData
@@ -417,38 +306,43 @@
if (parentData != null)
{
-
- TransactionManager tm =
((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
-
- try
+ if (transactionManager == null)
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.addChildNodes(parentData, childNodes);
- }
- else
- {
- tm.begin();
- cache.addChildNodes(parentData, childNodes);
- tm.commit();
- }
+ cache.addChildNodes(parentData, childNodes);
}
- catch (RollbackException e)
+ else
{
- // Indicate that the transaction has been rolled back rather than
committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (Exception e)
- {
+
try
{
- tm.rollback();
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildNodes(parentData, childNodes);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.addChildNodes(parentData, childNodes);
+ transactionManager.commit();
+ }
}
- catch (Exception e1)
+ catch (RollbackException e)
{
- // Treat the exception
+ // Indicate that the transaction has been rolled back rather than
committed.
throw new RepositoryException(e.getLocalizedMessage(),
e.getCause());
}
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(),
e.getCause());
+ }
+ }
}
}
}
@@ -460,20 +354,6 @@
}
}
- public int getChildNodesCount(NodeData parent) throws RepositoryException
- {
- if (cache.isEnabled())
- {
- List<NodeData> childNodes = cache.getChildNodes(parent);
- if (childNodes != null)
- {
- return childNodes.size();
- }
- }
-
- return super.getChildNodesCount(parent);
- }
-
/**
* Get child PropertyData.
*
@@ -516,37 +396,42 @@
if (parentData != null)
{
-
- TransactionManager tm =
((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
- try
+ if (transactionManager == null)
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.addChildProperties(parentData, childProperties);
- }
- else
- {
- tm.begin();
- cache.addChildProperties(parentData, childProperties);
- tm.commit();
- }
+ cache.addChildProperties(parentData, childProperties);
}
- catch (RollbackException e)
+ else
{
- // Indicate that the transaction has been rolled back rather than
committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (Exception e)
- {
try
{
- tm.rollback();
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildProperties(parentData, childProperties);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.addChildProperties(parentData, childProperties);
+ transactionManager.commit();
+ }
}
- catch (Exception e1)
+ catch (RollbackException e)
{
- // Treat the exception
+ // Indicate that the transaction has been rolled back rather than
committed.
throw new RepositoryException(e.getLocalizedMessage(),
e.getCause());
}
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(),
e.getCause());
+ }
+ }
}
}
}
@@ -559,57 +444,40 @@
}
/**
- * Get child PropertyData list (without ValueData).
+ * Get persisted ItemData.
*
- * @param nodeData
+ * @param parentData
* parent
- * @param forcePersistentRead
- * true if persistent read is required (without cache)
- * @return List<PropertyData>
+ * @param name
+ * Item name
+ * @return ItemData
* @throws RepositoryException
- * Repository error
+ * error
*/
- protected List<PropertyData> listChildPropertiesData(NodeData nodeData, boolean
forcePersistentRead)
- throws RepositoryException
+ protected ItemData getPersistedItemData(NodeData parentData, QPathEntry name) throws
RepositoryException
{
- final DataRequest request = new DataRequest(nodeData.getIdentifier(),
DataRequest.GET_PROPERTIES);
-
- List<PropertyData> propertiesList;
- if (!forcePersistentRead && cache.isEnabled())
+ ItemData data = null;
+ data = super.getItemData(parentData, name);
+ if (data != null && cache.isEnabled())
{
- request.waitSame(); // wait if getChildProp... working somewhere
- propertiesList = cache.listChildProperties(nodeData);
- if (propertiesList != null)
- return propertiesList;
- }
-
- propertiesList = super.listChildPropertiesData(nodeData);
- // TODO propertiesList.size() > 0 for SDB
- if (propertiesList.size() > 0 && cache.isEnabled())
- {
- NodeData parentData = (NodeData)cache.get(nodeData.getIdentifier());
- if (parentData == null)
+ if (transactionManager == null)
{
- parentData = (NodeData)super.getItemData(nodeData.getIdentifier());
+ cache.put(data);
}
-
- if (parentData != null)
+ else
{
-
- TransactionManager tm =
((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
-
try
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
{
- cache.addChildPropertiesList(parentData, propertiesList);
+ cache.put(data);
}
else
{
- tm.begin();
- cache.addChildPropertiesList(parentData, propertiesList);
- tm.commit();
+ transactionManager.begin();
+ cache.put(data);
+ transactionManager.commit();
}
}
catch (RollbackException e)
@@ -621,7 +489,7 @@
{
try
{
- tm.rollback();
+ transactionManager.rollback();
}
catch (Exception e1)
{
@@ -631,161 +499,334 @@
}
}
}
- return propertiesList;
+ return data;
}
/**
- * {@inheritDoc}
- */
- public List<PropertyData> getReferencesData(String identifier, boolean
skipVersionStorage)
- throws RepositoryException
- {
- return super.getReferencesData(identifier, skipVersionStorage);
- }
-
- /**
- * Get Items Cache.
+ * Call
+ * {@link
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
+ * WorkspaceDataManager.getItemDataByIdentifier(java.lang.String)} and cache result if
non null
+ * returned.
*
- * @return WorkspaceStorageCache
+ * @see
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
*/
- public WorkspaceStorageCache getCache()
+ protected ItemData getPersistedItemData(String identifier) throws RepositoryException
{
- return cache;
- }
+ ItemData data = super.getItemData(identifier);
+ if (data != null && cache.isEnabled())
+ {
+ if (transactionManager == null)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ try
+ {
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.put(data);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.put(data);
+ transactionManager.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than
committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ }
+ }
- /**
- * Get cached ItemData.
- *
- * @param parentData
- * parent
- * @param name
- * Item name
- * @return ItemData
- * @throws RepositoryException
- * error
- */
- protected ItemData getCachedItemData(NodeData parentData, QPathEntry name) throws
RepositoryException
- {
- return cache.get(parentData.getIdentifier(), name);
+ }
+ return data;
}
/**
- * Get persisted ItemData.
+ * Get child PropertyData list (without ValueData).
*
- * @param parentData
+ * @param nodeData
* parent
- * @param name
- * Item name
- * @return ItemData
+ * @param forcePersistentRead
+ * true if persistent read is required (without cache)
+ * @return List<PropertyData>
* @throws RepositoryException
- * error
+ * Repository error
*/
- protected ItemData getPersistedItemData(NodeData parentData, QPathEntry name) throws
RepositoryException
+ protected List<PropertyData> listChildPropertiesData(NodeData nodeData, boolean
forcePersistentRead)
+ throws RepositoryException
{
- ItemData data = null;
- data = super.getItemData(parentData, name);
- if (data != null && cache.isEnabled())
+ final DataRequest request = new DataRequest(nodeData.getIdentifier(),
DataRequest.GET_PROPERTIES);
+
+ List<PropertyData> propertiesList;
+ if (!forcePersistentRead && cache.isEnabled())
{
- TransactionManager tm =
((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ request.waitSame(); // wait if getChildProp... working somewhere
+ propertiesList = cache.listChildProperties(nodeData);
+ if (propertiesList != null)
+ return propertiesList;
+ }
- try
+ propertiesList = super.listChildPropertiesData(nodeData);
+ // TODO propertiesList.size() > 0 for SDB
+ if (propertiesList.size() > 0 && cache.isEnabled())
+ {
+ NodeData parentData = (NodeData)cache.get(nodeData.getIdentifier());
+ if (parentData == null)
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.put(data);
- }
- else
- {
- tm.begin();
- cache.put(data);
- tm.commit();
- }
+ parentData = (NodeData)super.getItemData(nodeData.getIdentifier());
}
- catch (RollbackException e)
+
+ if (parentData != null)
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
- catch (Exception e)
- {
- try
+ if (transactionManager == null)
{
- tm.rollback();
+ cache.addChildPropertiesList(parentData, propertiesList);
}
- catch (Exception e1)
+ else
{
- // Treat the exception
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ try
+ {
+ if (transactionManager.getStatus() == Status.STATUS_ACTIVE)
+ {
+ cache.addChildPropertiesList(parentData, propertiesList);
+ }
+ else
+ {
+ transactionManager.begin();
+ cache.addChildPropertiesList(parentData, propertiesList);
+ transactionManager.commit();
+ }
+ }
+ catch (RollbackException e)
+ {
+ // Indicate that the transaction has been rolled back rather than
committed.
+ throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ }
+ catch (Exception e)
+ {
+ try
+ {
+ transactionManager.rollback();
+ }
+ catch (Exception e1)
+ {
+ // Treat the exception
+ throw new RepositoryException(e.getLocalizedMessage(),
e.getCause());
+ }
+ }
}
}
}
- return data;
+ return propertiesList;
}
/**
- * Returns an item from cache by Identifier or null if the item don't cached.
+ * ItemData request, used on get operations.
*
- * @param identifier
- * Item id
- * @return ItemData
- * @throws RepositoryException
- * error
*/
- protected ItemData getCachedItemData(String identifier) throws RepositoryException
+ protected class DataRequest
{
- return cache.get(identifier);
- }
- /**
- * Call
- * {@link
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
- * WorkspaceDataManager.getItemDataByIdentifier(java.lang.String)} and cache result if
non null
- * returned.
- *
- * @see
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager#getItemData(java.lang.String)
- */
- protected ItemData getPersistedItemData(String identifier) throws RepositoryException
- {
- ItemData data = super.getItemData(identifier);
- if (data != null && cache.isEnabled())
+ /**
+ * GET_NODES type.
+ */
+ static public final int GET_NODES = 1;
+
+ /**
+ * GET_PROPERTIES type.
+ */
+ static public final int GET_PROPERTIES = 2;
+
+ /**
+ * GET_ITEM_ID type.
+ */
+ static private final int GET_ITEM_ID = 3;
+
+ /**
+ * GET_ITEM_NAME type.
+ */
+ static private final int GET_ITEM_NAME = 4;
+
+ /**
+ * Request type.
+ */
+ protected final int type;
+
+ /**
+ * Item parentId.
+ */
+ protected final String parentId;
+
+ /**
+ * Item id.
+ */
+ protected final String id;
+
+ /**
+ * Item name.
+ */
+ protected final QPathEntry name;
+
+ /**
+ * Hash code.
+ */
+ protected final int hcode;
+
+ /**
+ * Readiness latch.
+ */
+ protected CountDownLatch ready = new CountDownLatch(1);
+
+ /**
+ * DataRequest constructor.
+ *
+ * @param id
+ * Item id
+ */
+ DataRequest(String id)
{
+ this.parentId = null;
+ this.name = null;
+ this.id = id;
+ this.type = GET_ITEM_ID;
- TransactionManager tm =
((JBossCacheWorkspaceStorageCache)cache).getTransactionManager();
+ // hashcode
+ this.hcode = 31 * (31 + this.type) + this.id.hashCode();
+ }
+ /**
+ * DataRequest constructor.
+ *
+ * @param parentId
+ * parent id
+ * @param type
+ * request type
+ */
+ DataRequest(String parentId, int type)
+ {
+ this.parentId = parentId;
+ this.name = null;
+ this.id = null;
+ this.type = type;
+
+ // hashcode
+ this.hcode = 31 * (31 + this.type) + this.parentId.hashCode();
+ }
+
+ /**
+ * DataRequest constructor.
+ *
+ * @param parentId
+ * parent id
+ * @param name
+ * Item name
+ */
+ DataRequest(String parentId, QPathEntry name)
+ {
+ this.parentId = parentId;
+ this.name = name;
+ this.id = null;
+ this.type = GET_ITEM_NAME;
+
+ // hashcode
+ int hc = 31 * (31 + this.type) + this.parentId.hashCode();
+ this.hcode = 31 * hc + this.name.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ return this.hcode == obj.hashCode();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode()
+ {
+ return hcode;
+ }
+
+ /**
+ * Await this thread for another one running same request.
+ *
+ */
+ void await()
+ {
try
{
- if (tm.getStatus() == Status.STATUS_ACTIVE)
- {
- cache.put(data);
- }
- else
- {
- tm.begin();
- cache.put(data);
- tm.commit();
- }
+ this.ready.await();
}
- catch (RollbackException e)
+ catch (InterruptedException e)
{
- // Indicate that the transaction has been rolled back rather than committed.
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
+ LOG.warn("Can't wait for same request process. " + e, e);
}
- catch (Exception e)
+ }
+
+ /**
+ * Done the request. Must be called after the data request will be finished. This
call allow
+ * another same requests to be performed.
+ */
+ void done()
+ {
+ this.ready.countDown();
+ synchronized (requestCache)
{
- try
- {
- tm.rollback();
- }
- catch (Exception e1)
- {
- // Treat the exception
- throw new RepositoryException(e.getLocalizedMessage(), e.getCause());
- }
+ requestCache.remove(this.hashCode());
}
+ }
+ /**
+ * Start the request, each same will wait till this will be finished
+ */
+ void start()
+ {
+ synchronized (requestCache)
+ {
+ requestCache.put(this.hashCode(), this);
+ }
}
- return data;
+
+ /**
+ * Find the same, and if found wait till the one will be finished.
+ *
+ * WARNING. This method effective with cache use only!!! Without cache the database
will control
+ * requests performance/chaching process.
+ *
+ * @return this data request
+ */
+ DataRequest waitSame()
+ {
+ DataRequest prev = null;
+ synchronized (requestCache)
+ {
+ prev = requestCache.get(this.hashCode());
+ }
+ if (prev != null)
+ prev.await();
+ return this;
+ }
}
}
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-24
15:38:31 UTC (rev 1170)
+++
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-24
15:52:07 UTC (rev 1171)
@@ -137,146 +137,6 @@
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));
- }
-
- 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");
- }
- }
-
- /**
* JBossCacheWorkspaceStorageCache constructor.
*
*/
@@ -344,147 +204,35 @@
}
- /**
- * {@inheritDoc}
- */
- public void put(ItemData item)
+ public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig) throws
RepositoryException,
+ RepositoryConfigurationException
{
- txStart();
- try
- {
- putItem(item);
-
- txCommit();
- }
- catch (Throwable e)
- {
- txRollback();
- LOG.error("put error " + (item != null ? item.getQPath().getAsString()
: item), e);
- }
+ this(readJBCConfig(wsConfig));
}
/**
* {@inheritDoc}
*/
- public void remove(ItemData item)
+ public void addChildNodes(NodeData parent, List<NodeData> childs)
{
- txStart();
- try
- {
- removeItem(item);
- txCommit();
- }
- catch (Throwable e)
- {
- txRollback();
- LOG.error("remove error " + (item != null ?
item.getQPath().getAsString() : item), e);
- }
- }
+ // remove previous all (to be sure about consistency)
+ cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
- /**
- * {@inheritDoc}
- */
- public void onSaveItems(final ItemStateChangesLog itemStates)
- {
- txStart();
- try
+ if (childs.size() > 0)
{
-
- ItemState prevState = null;
-
- for (ItemState state : itemStates.getAllStates())
+ // add all new
+ for (NodeData child : childs)
{
-
- 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;
+ putNode(child);
}
-
- txCommit();
}
- catch (Throwable e)
+ else
{
- txRollback();
- LOG.error("onSaveItems error " + itemStates, e);
+ // cache fact of empty childs list
+ cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
}
- }
- /**
- * {@inheritDoc}
- */
- public void addChildNodes(NodeData parent, List<NodeData> childs)
- {
- txStart();
- try
- {
- // remove previous all (to be sure about consistency)
- cache.removeNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
-
- if (childs.size() > 0)
- {
- // add all new
- for (NodeData child : childs)
- {
- putNode(child);
- }
- }
- else
- {
- // cache fact of empty childs list
- cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()),
NULL_DATA);
- }
-
- txCommit();
- }
- catch (Throwable e)
- {
- txRollback();
- LOG.error("addChildNodes error " + (parent != null ?
parent.getQPath().getAsString() : parent), e);
- }
}
/**
@@ -492,32 +240,23 @@
*/
public void addChildProperties(NodeData parent, List<PropertyData> childs)
{
- txStart();
- try
- {
- // remove previous all (to be sure about consistency)
- cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
- if (childs.size() > 0)
+ // remove previous all (to be sure about consistency)
+ cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
+
+ if (childs.size() > 0)
+ {
+ // add all new
+ for (PropertyData child : childs)
{
- // add all new
- for (PropertyData child : childs)
- {
- putProperty(child);
- }
+ putProperty(child);
}
- else
- {
- LOG.warn("Empty properties list cached " + (parent != null ?
parent.getQPath().getAsString() : parent));
- }
-
- txCommit();
}
- catch (Throwable e)
+ else
{
- txRollback();
- LOG.error("addChildProperties error " + (parent != null ?
parent.getQPath().getAsString() : parent), e);
+ LOG.warn("Empty properties list cached " + (parent != null ?
parent.getQPath().getAsString() : parent));
}
+
}
/**
@@ -542,6 +281,14 @@
/**
* {@inheritDoc}
*/
+ public ItemData get(String id)
+ {
+ return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ItemData get(String parentId, QPathEntry name)
{
@@ -564,14 +311,6 @@
/**
* {@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>();
@@ -612,12 +351,120 @@
/**
* {@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
@@ -656,175 +503,28 @@
}
/**
- * {@inheritDoc}
- */
- public long getSize()
- {
- // TODO
- return -1;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isEnabled()
- {
- // TODO
- return true;
- }
-
- // ****************
-
- protected void txStart()
- {
- // if (!txStarted)
- // {
- // txStarted = true;
- // //this.cache.startBatch();
- // TransactionManager tm = ((CacheSPI<Serializable,
Object>)cache).getTransactionManager();
- // try
- // {
- // tm.begin();
- // }
- // catch (NotSupportedException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SystemException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // }
- }
-
- protected void txCommit()
- {
- // if (LOG.isDebugEnabled())
- // {
- // LOG.debug("commit " + txStarted);
- // }
- //
- // // end batch
- // if (txStarted)
- // {
- // //this.cache.endBatch(true);
- // TransactionManager tm = ((CacheSPI<Serializable,
Object>)cache).getTransactionManager();
- // try
- // {
- // tm.commit();
- // }
- // catch (SecurityException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (IllegalStateException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (RollbackException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (HeuristicMixedException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (HeuristicRollbackException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SystemException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // txStarted = false;
- // }
- // else
- // {
- // // TODO
- // LOG.warn("Commit call without changes made.");
- // }
- }
-
- /**
- * Return TransactionManager.
- * @return TransactionManager.
- */
- public TransactionManager getTransactionManager()
- {
- return ((CacheSPI<Serializable, Object>)cache).getTransactionManager();
- }
-
- protected void txRollback()
- {
- // if (LOG.isDebugEnabled())
- // {
- // LOG.debug("rollback " + txStarted);
- // }
- //
- // // rollback batch
- // if (txStarted)
- // {
- // //this.cache.endBatch(false);
- // TransactionManager tm = ((CacheSPI<Serializable,
Object>)cache).getTransactionManager();
- // try
- // {
- // tm.rollback();
- // }
- // catch (IllegalStateException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SecurityException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // catch (SystemException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // txStarted = false;
- // }
- // else
- // {
- // // TODO
- // LOG.warn("Rollback call without changes made.");
- // }
- }
-
- /**
- * Make Item absolute Fqn, i.e. /$ITEMS/itemID.
+ * Make child Item absolute Fqn, i.e. /root/parentId/childName.
*
- * @param itemId String
+ * @param root Fqn
+ * @param parentId String
+ * @param childName QPathEntry
* @return Fqn
*/
- protected Fqn<String> makeItemFqn(String itemId)
+ protected Fqn<String> makeChildFqn(Fqn<String> root, String parentId,
QPathEntry childName)
{
- return Fqn.fromRelativeElements(itemsRoot, itemId);
+ return Fqn.fromRelativeElements(root, parentId, childName.getAsString(true));
}
/**
- * Make child Item absolute Fqn, i.e. /root/parentId/childName.
+ * Make child node parent absolute Fqn, i.e. /root/itemId.
*
* @param root Fqn
* @param parentId String
- * @param childName QPathEntry
* @return Fqn
*/
- protected Fqn<String> makeChildFqn(Fqn<String> root, String parentId,
QPathEntry childName)
+ protected Fqn<String> makeChildListFqn(Fqn<String> root, String parentId)
{
- return Fqn.fromRelativeElements(root, parentId, childName.getAsString(true));
+ return Fqn.fromRelativeElements(root, parentId);
}
/**
@@ -841,17 +541,18 @@
}
/**
- * Make child node parent absolute Fqn, i.e. /root/itemId.
+ * Make Item absolute Fqn, i.e. /$ITEMS/itemID.
*
- * @param root Fqn
- * @param parentId String
+ * @param itemId String
* @return Fqn
*/
- protected Fqn<String> makeChildListFqn(Fqn<String> root, String parentId)
+ protected Fqn<String> makeItemFqn(String itemId)
{
- return Fqn.fromRelativeElements(root, parentId);
+ return Fqn.fromRelativeElements(itemsRoot, itemId);
}
+ // ****************
+
/**
* Internal put Item.
*
@@ -995,28 +696,6 @@
}
/**
- * 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.
@@ -1049,6 +728,63 @@
}
/**
+ * 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.
@@ -1107,39 +843,138 @@
}
}
- /**
- * 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)
+ class ChildItemsIterator<T extends ItemData> implements Iterator<T>
{
- for (Iterator<NodeData> iter = new
ChildNodesIterator<NodeData>(parentId); iter.hasNext();)
+
+ final Iterator<Object> childs;
+
+ final String parentId;
+
+ final Fqn<String> root;
+
+ T next;
+
+ ChildItemsIterator(Fqn<String> root, String parentId)
{
- NodeData prevNode = iter.next();
+ this.parentId = parentId;
+ this.root = root;
- // is ACL changes on this node (i.e. ACL inheritance brokes)
- for (InternalQName mixin : prevNode.getMixinTypeNames())
+ 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)
{
- if (mixin.equals(Constants.EXO_PRIVILEGEABLE) ||
mixin.equals(Constants.EXO_OWNEABLE))
+ 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
{
- continue;
+ 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;
+ }
+ }
+ }
- // 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);
+ class ChildNodesIterator<N extends NodeData> extends
ChildItemsIterator<N>
+ {
- // update this node
- cache.put(makeItemFqn(newNode.getIdentifier()), ITEM_DATA, newNode);
+ ChildNodesIterator(String parentId)
+ {
+ super(childNodes, parentId);
+ }
- // update childs recursive
- updateChildsACL(newNode.getIdentifier(), acl);
+ @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();
+ }
+ }
+
+ /**
+ * 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");
+ }
+ }
+
}