[exo-jcr-commits] exo-jcr SVN: r2186 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Mar 30 03:52:33 EDT 2010
Author: nfilotto
Date: 2010-03-30 03:52:32 -0400 (Tue, 30 Mar 2010)
New Revision: 2186
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
Log:
EXOJCR-609: first implementation
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-03-30 06:32:47 UTC (rev 2185)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-03-30 07:52:32 UTC (rev 2186)
@@ -18,11 +18,15 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent;
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.dataflow.ItemDataVisitor;
import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
+import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.JBossCacheWorkspaceStorageCache;
@@ -50,8 +54,76 @@
*/
public class CacheableWorkspaceDataManager extends WorkspacePersistentDataManager
{
+ /**
+ * The identifier of the <code>null</code> value
+ */
+ protected static final String ITEM_DATA_NULL_VALUE_ID = "$";
+
+ /**
+ * The name of the <code>null</code> value
+ */
+ protected static final String ITEM_DATA_NULL_VALUE_NAME = null;
/**
+ * The <code>null</code> value for the itemData
+ */
+ protected static final ItemData ITEM_DATA_NULL_VALUE = new NodeData()
+ {
+
+ public void accept(ItemDataVisitor visitor) throws RepositoryException
+ {
+ }
+
+ public String getIdentifier()
+ {
+ return ITEM_DATA_NULL_VALUE_ID;
+ }
+
+ public String getParentIdentifier()
+ {
+ return null;
+ }
+
+ public int getPersistedVersion()
+ {
+ return 0;
+ }
+
+ QPath path = new QPath(new QPathEntry[]{new QPathEntry(null, ITEM_DATA_NULL_VALUE_NAME, 0)});
+
+ public QPath getQPath()
+ {
+ return path;
+ }
+
+ public boolean isNode()
+ {
+ return true;
+ }
+
+ public AccessControlList getACL()
+ {
+ return null;
+ }
+
+ public InternalQName[] getMixinTypeNames()
+ {
+ return null;
+ }
+
+ public int getOrderNumber()
+ {
+ return 0;
+ }
+
+ public InternalQName getPrimaryTypeName()
+ {
+ return null;
+ }
+
+ };
+
+ /**
* Items cache.
*/
protected final WorkspaceStorageCache cache;
@@ -94,7 +166,7 @@
* GET_LIST_PROPERTIES type.
*/
static private final int GET_LIST_PROPERTIES = 5;
-
+
/**
* Request type.
*/
@@ -386,7 +458,7 @@
if (data == null)
{
final DataRequest request = new DataRequest(parentData.getIdentifier(), name);
-
+
try
{
request.start();
@@ -395,7 +467,7 @@
data = getCachedItemData(parentData, name);
if (data == null)
{
- data = getPersistedItemData(parentData, name);
+ data = getPersistedItemData(parentData, name);
}
else if (!data.isNode())
{
@@ -412,7 +484,7 @@
fixPropertyValues((PropertyData)data);
}
- return data;
+ return data == ITEM_DATA_NULL_VALUE ? null : data;
}
/**
@@ -427,7 +499,7 @@
if (data == null)
{
final DataRequest request = new DataRequest(identifier);
-
+
try
{
request.start();
@@ -436,7 +508,7 @@
data = getCachedItemData(identifier);
if (data == null)
{
- data = getPersistedItemData(identifier);
+ data = getPersistedItemData(identifier);
}
else if (!data.isNode())
{
@@ -453,7 +525,7 @@
fixPropertyValues((PropertyData)data);
}
- return data;
+ return data == ITEM_DATA_NULL_VALUE ? null : data;
}
/**
@@ -622,8 +694,7 @@
}
childProperties = super.getChildPropertiesData(nodeData);
- // TODO childProperties.size() > 0 for SDB
- if (childProperties.size() > 0 && cache.isEnabled())
+ if (cache.isEnabled())
{
NodeData parentData = (NodeData)getItemData(nodeData.getIdentifier());
@@ -654,9 +725,9 @@
protected ItemData getPersistedItemData(NodeData parentData, QPathEntry name) throws RepositoryException
{
ItemData data = super.getItemData(parentData, name);
- if (data != null && cache.isEnabled())
+ if (cache.isEnabled())
{
- cache.put(data);
+ cache.put(data == null ? ITEM_DATA_NULL_VALUE : data);
}
return data;
}
@@ -671,9 +742,9 @@
protected ItemData getPersistedItemData(String identifier) throws RepositoryException
{
ItemData data = super.getItemData(identifier);
- if (data != null && cache.isEnabled())
+ if (cache.isEnabled())
{
- cache.put(data);
+ cache.put(data == null ? ITEM_DATA_NULL_VALUE : data);
}
return data;
}
@@ -718,8 +789,7 @@
}
}
propertiesList = super.listChildPropertiesData(nodeData);
- // TODO propertiesList.size() > 0 for SDB
- if (propertiesList.size() > 0 && cache.isEnabled())
+ if (cache.isEnabled())
{
NodeData parentData = (NodeData)getItemData(nodeData.getIdentifier());
@@ -733,7 +803,7 @@
finally
{
request.done();
- }
+ }
}
protected boolean isTxAware()
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-03-30 06:32:47 UTC (rev 2185)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-03-30 07:52:32 UTC (rev 2186)
@@ -476,7 +476,7 @@
else
{
// cache fact of empty childs list
- cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST, new HashSet<Object>());
+ cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST, Collections.EMPTY_SET);
}
}
finally
@@ -514,11 +514,10 @@
set.add(child.getIdentifier());
}
cache.put(makeChildListFqn(childPropsList, parent.getIdentifier()), ITEM_LIST, set);
-
}
else
{
- LOG.warn("Empty properties list cached " + (parent != null ? parent.getQPath().getAsString() : parent));
+ cache.put(makeChildListFqn(childPropsList, parent.getIdentifier()), ITEM_LIST, Collections.EMPTY_SET);
}
}
finally
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-03-30 06:32:47 UTC (rev 2185)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-03-30 07:52:32 UTC (rev 2186)
@@ -53,6 +53,7 @@
{
private static final int READER = 100;
+
private static final int TIMES = 20;
private CacheableWorkspaceDataManager cwdm;
@@ -61,6 +62,12 @@
private MyWorkspaceStorageConnection con;
+ private CacheableWorkspaceDataManager cwdmEmpty;
+
+ private WorkspaceDataContainer wdcEmpty;
+
+ private MyWorkspaceStorageConnection conEmpty;
+
@Override
protected void setUp() throws Exception
{
@@ -69,6 +76,11 @@
this.wdc = new MyWorkspaceDataContainer(con);
this.cwdm =
new CacheableWorkspaceDataManager(wdc, new MyWorkspaceStorageCache(), new SystemDataContainerHolder(wdc));
+ this.conEmpty = new MyWorkspaceStorageConnection(true);
+ this.wdcEmpty = new MyWorkspaceDataContainer(conEmpty);
+ this.cwdmEmpty =
+ new CacheableWorkspaceDataManager(wdcEmpty, new MyWorkspaceStorageCache(), new SystemDataContainerHolder(
+ wdcEmpty));
}
@Override
@@ -96,7 +108,7 @@
startSignal.await();
for (int i = 0; i < TIMES; i++)
{
- task.execute();
+ task.execute();
}
}
catch (Exception e)
@@ -120,9 +132,9 @@
e.printStackTrace();
}
throw errors.get(0);
- }
+ }
}
-
+
public void testGetItemById() throws Exception
{
assertEquals(0, con.getItemDataByIdCalls.get());
@@ -132,15 +144,26 @@
{
ItemData item = cwdm.getItemData("getItemData");
assertNotNull(item);
- }
+ }
};
multiThreadingTest(task);
assertEquals(1, con.getItemDataByIdCalls.get());
+ assertEquals(0, conEmpty.getItemDataByIdCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ ItemData item = cwdmEmpty.getItemData("getItemData");
+ assertNull(item);
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1, conEmpty.getItemDataByIdCalls.get());
}
-
+
public void testGetItemDataByNodeDataNQPathEntry() throws Exception
{
- final NodeData nodeData = new PersistedNodeData("getItemData", null, null, 0, 1, null, null, null);
+ final NodeData nodeData = new PersistedNodeData("getItemData", null, null, 0, 1, null, null, null);
assertEquals(0, con.getItemDataByNodeDataNQPathEntryCalls.get());
MyTask task = new MyTask()
{
@@ -148,15 +171,26 @@
{
ItemData item = cwdm.getItemData(nodeData, new QPathEntry("http://www.foo.com", "foo", 0));
assertNotNull(item);
- }
+ }
};
multiThreadingTest(task);
assertEquals(1, con.getItemDataByNodeDataNQPathEntryCalls.get());
+ assertEquals(0, conEmpty.getItemDataByNodeDataNQPathEntryCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ ItemData item = cwdmEmpty.getItemData(nodeData, new QPathEntry("http://www.foo.com", "foo", 0));
+ assertNull(item);
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1, conEmpty.getItemDataByNodeDataNQPathEntryCalls.get());
}
-
+
public void testGetChildPropertiesData() throws Exception
{
- final NodeData nodeData = new PersistedNodeData("getChildPropertiesData", null, null, 0, 1, null, null, null);
+ final NodeData nodeData = new PersistedNodeData("getChildPropertiesData", null, null, 0, 1, null, null, null);
assertEquals(0, con.getChildPropertiesDataCalls.get());
MyTask task = new MyTask()
{
@@ -165,7 +199,7 @@
List<PropertyData> properties = cwdm.getChildPropertiesData(nodeData);
assertNotNull(properties);
assertFalse(properties.isEmpty());
- }
+ }
};
multiThreadingTest(task);
assertEquals(1, con.getChildPropertiesDataCalls.get());
@@ -176,15 +210,38 @@
List<PropertyData> properties = cwdm.getChildPropertiesData(nodeData, true);
assertNotNull(properties);
assertFalse(properties.isEmpty());
- }
+ }
};
multiThreadingTest(task);
assertEquals(1 + READER * TIMES, con.getChildPropertiesDataCalls.get());
+ assertEquals(0, conEmpty.getChildPropertiesDataCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ List<PropertyData> properties = cwdmEmpty.getChildPropertiesData(nodeData);
+ assertNotNull(properties);
+ assertTrue(properties.isEmpty());
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1, conEmpty.getChildPropertiesDataCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ List<PropertyData> properties = cwdmEmpty.getChildPropertiesData(nodeData, true);
+ assertNotNull(properties);
+ assertTrue(properties.isEmpty());
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1 + READER * TIMES, conEmpty.getChildPropertiesDataCalls.get());
}
-
+
public void testListChildPropertiesData() throws Exception
{
- final NodeData nodeData = new PersistedNodeData("listChildPropertiesData", null, null, 0, 1, null, null, null);
+ final NodeData nodeData = new PersistedNodeData("listChildPropertiesData", null, null, 0, 1, null, null, null);
assertEquals(0, con.listChildPropertiesDataCalls.get());
MyTask task = new MyTask()
{
@@ -193,7 +250,7 @@
List<PropertyData> properties = cwdm.listChildPropertiesData(nodeData);
assertNotNull(properties);
assertFalse(properties.isEmpty());
- }
+ }
};
multiThreadingTest(task);
assertEquals(1, con.listChildPropertiesDataCalls.get());
@@ -204,15 +261,38 @@
List<PropertyData> properties = cwdm.listChildPropertiesData(nodeData, true);
assertNotNull(properties);
assertFalse(properties.isEmpty());
- }
+ }
};
multiThreadingTest(task);
assertEquals(1 + READER * TIMES, con.listChildPropertiesDataCalls.get());
+ assertEquals(0, conEmpty.listChildPropertiesDataCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ List<PropertyData> properties = cwdmEmpty.listChildPropertiesData(nodeData);
+ assertNotNull(properties);
+ assertTrue(properties.isEmpty());
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1, conEmpty.listChildPropertiesDataCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ List<PropertyData> properties = cwdmEmpty.listChildPropertiesData(nodeData, true);
+ assertNotNull(properties);
+ assertTrue(properties.isEmpty());
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1 + READER * TIMES, conEmpty.listChildPropertiesDataCalls.get());
}
-
+
public void testGetChildNodes() throws Exception
{
- final NodeData nodeData = new PersistedNodeData("getChildNodes", null, null, 0, 1, null, null, null);
+ final NodeData nodeData = new PersistedNodeData("getChildNodes", null, null, 0, 1, null, null, null);
assertEquals(0, con.getChildNodesDataCalls.get());
MyTask task = new MyTask()
{
@@ -221,7 +301,7 @@
List<NodeData> nodes = cwdm.getChildNodesData(nodeData);
assertNotNull(nodes);
assertFalse(nodes.isEmpty());
- }
+ }
};
multiThreadingTest(task);
assertEquals(1, con.getChildNodesDataCalls.get());
@@ -232,15 +312,38 @@
List<NodeData> nodes = cwdm.getChildNodesData(nodeData, true);
assertNotNull(nodes);
assertFalse(nodes.isEmpty());
- }
+ }
};
multiThreadingTest(task);
assertEquals(1 + READER * TIMES, con.getChildNodesDataCalls.get());
+ assertEquals(0, conEmpty.getChildNodesDataCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ List<NodeData> nodes = cwdmEmpty.getChildNodesData(nodeData);
+ assertNotNull(nodes);
+ assertTrue(nodes.isEmpty());
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1, conEmpty.getChildNodesDataCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ List<NodeData> nodes = cwdmEmpty.getChildNodesData(nodeData, true);
+ assertNotNull(nodes);
+ assertTrue(nodes.isEmpty());
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(1 + READER * TIMES, conEmpty.getChildNodesDataCalls.get());
}
-
+
public void testGetChildNodesCount() throws Exception
{
- final NodeData nodeData = new PersistedNodeData("getChildNodesCount", null, null, 0, 1, null, null, null);
+ final NodeData nodeData = new PersistedNodeData("getChildNodesCount", null, null, 0, 1, null, null, null);
assertEquals(0, con.getChildNodesCountCalls.get());
MyTask task = new MyTask()
{
@@ -248,7 +351,7 @@
{
int result = cwdm.getChildNodesCount(nodeData);
assertEquals(1, result);
- }
+ }
};
multiThreadingTest(task);
assertEquals(READER * TIMES, con.getChildNodesCountCalls.get());
@@ -260,17 +363,40 @@
{
int result = cwdm.getChildNodesCount(nodeData);
assertEquals(1, result);
- }
+ }
};
multiThreadingTest(task);
assertEquals(READER * TIMES, con.getChildNodesCountCalls.get());
+ assertEquals(0, conEmpty.getChildNodesCountCalls.get());
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ int result = cwdmEmpty.getChildNodesCount(nodeData);
+ assertEquals(0, result);
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(READER * TIMES, conEmpty.getChildNodesCountCalls.get());
+ // Add data to the cache
+ cwdmEmpty.getChildNodesData(nodeData);
+ task = new MyTask()
+ {
+ public void execute() throws Exception
+ {
+ int result = cwdmEmpty.getChildNodesCount(nodeData);
+ assertEquals(0, result);
+ }
+ };
+ multiThreadingTest(task);
+ assertEquals(READER * TIMES, conEmpty.getChildNodesCountCalls.get());
}
private static interface MyTask
{
void execute() throws Exception;
}
-
+
private static class MyWorkspaceStorageCache implements WorkspaceStorageCache
{
@@ -365,9 +491,21 @@
}
- private static class MyWorkspaceStorageConnection implements WorkspaceStorageConnection
+ public static class MyWorkspaceStorageConnection implements WorkspaceStorageConnection
{
+ public final boolean emptyResult;
+
+ public MyWorkspaceStorageConnection()
+ {
+ this(false);
+ }
+
+ public MyWorkspaceStorageConnection(boolean emptyResult)
+ {
+ this.emptyResult = emptyResult;
+ }
+
public void add(NodeData data) throws RepositoryException, UnsupportedOperationException,
InvalidItemStateException, IllegalStateException
{
@@ -401,7 +539,7 @@
public int getChildNodesCount(NodeData parent) throws RepositoryException
{
getChildNodesCountCalls.incrementAndGet();
- return 1;
+ return emptyResult ? 0 : 1;
}
public AtomicInteger getChildNodesDataCalls = new AtomicInteger();
@@ -409,7 +547,8 @@
public List<NodeData> getChildNodesData(NodeData parent) throws RepositoryException, IllegalStateException
{
getChildNodesDataCalls.incrementAndGet();
- return Arrays.asList((NodeData)new PersistedNodeData("getChildNodesData", null, null, 0, 1, null, null, null));
+ return emptyResult ? new ArrayList<NodeData>() : Arrays.asList((NodeData)new PersistedNodeData(
+ "getChildNodesData", null, null, 0, 1, null, null, null));
}
public AtomicInteger getChildPropertiesDataCalls = new AtomicInteger();
@@ -418,10 +557,9 @@
IllegalStateException
{
getChildPropertiesDataCalls.incrementAndGet();
- return Arrays
- .asList((PropertyData)new PersistedPropertyData("getChildPropertiesData", null, null, 0,
- PropertyType.STRING, false, Arrays
- .asList((ValueData)new ByteArrayPersistedValueData(1, "foo".getBytes()))));
+ return emptyResult ? new ArrayList<PropertyData>() : Arrays.asList((PropertyData)new PersistedPropertyData(
+ "getChildPropertiesData", null, null, 0, PropertyType.STRING, false, Arrays
+ .asList((ValueData)new ByteArrayPersistedValueData(1, "foo".getBytes()))));
}
public AtomicInteger getItemDataByNodeDataNQPathEntryCalls = new AtomicInteger();
@@ -430,7 +568,7 @@
IllegalStateException
{
getItemDataByNodeDataNQPathEntryCalls.incrementAndGet();
- return new PersistedNodeData("getItemData", null, null, 0, 1, null, null, null);
+ return emptyResult ? null : new PersistedNodeData("getItemData", null, null, 0, 1, null, null, null);
}
public AtomicInteger getItemDataByIdCalls = new AtomicInteger();
@@ -438,7 +576,8 @@
public ItemData getItemData(String identifier) throws RepositoryException, IllegalStateException
{
getItemDataByIdCalls.incrementAndGet();
- return new PersistedNodeData("getItemData", null, null, 0, 1, null, null, null);
+ return emptyResult && identifier.equals("getItemData") ? null : new PersistedNodeData("getItemData", null,
+ null, 0, 1, null, null, null);
}
public AtomicInteger getReferencesDataCalls = new AtomicInteger();
@@ -463,8 +602,9 @@
IllegalStateException
{
listChildPropertiesDataCalls.incrementAndGet();
- return Arrays.asList((PropertyData)new PersistedPropertyData("listChildPropertiesData", null, null, 0, PropertyType.STRING,
- false, Arrays.asList((ValueData)new ByteArrayPersistedValueData(1, "foo".getBytes()))));
+ return emptyResult ? new ArrayList<PropertyData>() : Arrays.asList((PropertyData)new PersistedPropertyData(
+ "listChildPropertiesData", null, null, 0, PropertyType.STRING, false, Arrays
+ .asList((ValueData)new ByteArrayPersistedValueData(1, "foo".getBytes()))));
}
public void rename(NodeData data) throws RepositoryException, UnsupportedOperationException,
More information about the exo-jcr-commits
mailing list