Author: tolusha
Date: 2010-04-07 10:03:09 -0400 (Wed, 07 Apr 2010)
New Revision: 2218
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
Log:
EXOJCR-609: store missing values
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-04-07
13:07:13 UTC (rev 2217)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-04-07
14:03:09 UTC (rev 2218)
@@ -25,6 +25,7 @@
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.NullNodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
@@ -483,7 +484,7 @@
fixPropertyValues((PropertyData)data);
}
- return data == ITEM_DATA_NULL_VALUE ? null : data;
+ return data instanceof NullNodeData ? null : data;
}
/**
@@ -492,10 +493,10 @@
@Override
public ItemData getItemData(String identifier) throws RepositoryException
{
- // 2. Try from cache
+ // 1. Try from cache
ItemData data = getCachedItemData(identifier);
- // 3. Try from container
+ // 2 Try from container
if (data == null)
{
final DataRequest request = new DataRequest(identifier);
@@ -525,7 +526,7 @@
fixPropertyValues((PropertyData)data);
}
- return data == ITEM_DATA_NULL_VALUE ? null : data;
+ return data instanceof NullNodeData ? null : data;
}
/**
@@ -533,7 +534,7 @@
*/
@Override
public List<PropertyData> getReferencesData(String identifier, boolean
skipVersionStorage)
- throws RepositoryException
+ throws RepositoryException
{
return super.getReferencesData(identifier, skipVersionStorage);
}
@@ -610,7 +611,7 @@
* Repository error
*/
protected List<NodeData> getChildNodesData(NodeData nodeData, boolean
forcePersistentRead)
- throws RepositoryException
+ throws RepositoryException
{
List<NodeData> childNodes = null;
@@ -667,7 +668,7 @@
* Repository error
*/
protected List<PropertyData> getChildPropertiesData(NodeData nodeData, boolean
forcePersistentRead)
- throws RepositoryException
+ throws RepositoryException
{
List<PropertyData> childProperties = null;
@@ -729,7 +730,7 @@
ItemData data = super.getItemData(parentData, name);
if (cache.isEnabled())
{
- cache.put(data == null ? ITEM_DATA_NULL_VALUE : data);
+ cache.put(data == null ? new NullNodeData(parentData, name) : data);
}
return data;
}
@@ -746,7 +747,14 @@
ItemData data = super.getItemData(identifier);
if (cache.isEnabled())
{
- cache.put(data == null ? ITEM_DATA_NULL_VALUE : data);
+ if (data != null)
+ {
+ cache.put(data);
+ }
+ else if (identifier != null)
+ {
+ cache.put(new NullNodeData(identifier));
+ }
}
return data;
}
@@ -763,7 +771,7 @@
* Repository error
*/
protected List<PropertyData> listChildPropertiesData(NodeData nodeData, boolean
forcePersistentRead)
- throws RepositoryException
+ throws RepositoryException
{
List<PropertyData> propertiesList;
@@ -857,7 +865,7 @@
* @throws RepositoryException
*/
protected ValueData getPropertyValue(String propertyId, int orderNumb, int
persistedVersion)
- throws IllegalStateException, RepositoryException
+ throws IllegalStateException, RepositoryException
{
// TODO use interface not JDBC
JDBCStorageConnection conn =
(JDBCStorageConnection)dataContainer.openConnection();
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-07
13:07:13 UTC (rev 2217)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-04-07
14:03:09 UTC (rev 2218)
@@ -156,6 +156,14 @@
this.local.set(local);
}
+ /**
+ * Returns current state.
+ */
+ public boolean isLocal()
+ {
+ return this.local.get();
+ }
+
public int getNumberOfNodes()
{
return ((CacheSPI<Serializable, Object>)parentCache).getNumberOfNodes();
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-07
13:07:13 UTC (rev 2217)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-04-07
14:03:09 UTC (rev 2218)
@@ -28,6 +28,7 @@
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.NullNodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
@@ -95,6 +96,8 @@
public static final String ITEMS = "$ITEMS".intern();
+ public static final String NULL_ITEMS = "$NULL_ITEMS".intern();
+
public static final String CHILD_NODES = "$CHILD_NODES".intern();
public static final String CHILD_PROPS = "$CHILD_PROPS".intern();
@@ -115,6 +118,8 @@
protected final Fqn<String> itemsRoot;
+ protected final Fqn<String> nullItemsRoot;
+
protected final Fqn<String> childNodes;
protected final Fqn<String> childProps;
@@ -274,6 +279,7 @@
this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()));
this.itemsRoot = Fqn.fromElements(ITEMS);
+ this.nullItemsRoot = Fqn.fromElements(NULL_ITEMS);
this.childNodes = Fqn.fromElements(CHILD_NODES);
this.childProps = Fqn.fromElements(CHILD_PROPS);
this.childNodesList = Fqn.fromElements(CHILD_NODES_LIST);
@@ -287,6 +293,7 @@
createResidentNode(childProps);
createResidentNode(childPropsList);
createResidentNode(itemsRoot);
+ createResidentNode(nullItemsRoot);
}
/**
@@ -356,13 +363,21 @@
cache.beginTransaction();
}
cache.setLocal(true);
- if (item.isNode())
+
+ if (item instanceof NullNodeData)
{
- putNode((NodeData)item, ModifyChildOption.NOT_MODIFY);
+ putNullNode((NullNodeData)item);
}
else
{
- putProperty((PropertyData)item, ModifyChildOption.NOT_MODIFY);
+ if (item.isNode())
+ {
+ putNode((NodeData)item, ModifyChildOption.NOT_MODIFY);
+ }
+ else
+ {
+ putProperty((PropertyData)item, ModifyChildOption.NOT_MODIFY);
+ }
}
}
finally
@@ -557,18 +572,19 @@
// get as node first
String itemId = (String)cache.get(makeChildFqn(childNodes, parentId, name),
ITEM_ID);
- if (itemId == null)
+ if (itemId != null)
{
- // try as property
- itemId = (String)cache.get(makeChildFqn(childProps, parentId, name), ITEM_ID);
+ return getFromCacheById(itemId);
}
+ // try as property
+ itemId = (String)cache.get(makeChildFqn(childProps, parentId, name), ITEM_ID);
if (itemId != null)
{
- return get(itemId);
+ return getFromCacheById(itemId);
}
- return null;
+ return (ItemData)cache.get(makeNullItemFqn(parentId + "$" +
name.getAsString(true)), ITEM_DATA);
}
/**
@@ -576,7 +592,9 @@
*/
public ItemData get(String id)
{
- return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
+ ItemData data = getFromCacheById(id);
+
+ return data != null ? data : (ItemData)cache.get(makeNullItemFqn(id), ITEM_DATA);
}
/**
@@ -695,6 +713,17 @@
}
/**
+ * Make Item absolute Fqn, i.e. /$NULL_ITEMS/itemID.
+ *
+ * @param itemId String
+ * @return Fqn
+ */
+ protected Fqn<String> makeNullItemFqn(String itemId)
+ {
+ return Fqn.fromRelativeElements(nullItemsRoot, itemId);
+ }
+
+ /**
* Make child Item absolute Fqn, i.e. /root/parentId/childName.
*
* @param root Fqn
@@ -733,6 +762,14 @@
}
/**
+ * Gets item data from cache by item identifier.
+ */
+ protected ItemData getFromCacheById(String id)
+ {
+ return (ItemData)cache.get(makeItemFqn(id), ITEM_DATA);
+ }
+
+ /**
* Internal put Item.
*
* @param item ItemData, new data to put in the cache
@@ -771,6 +808,15 @@
*/
protected ItemData putNode(NodeData node, ModifyChildOption modifyListsOfChild)
{
+
+ // remove possible NullNodeData from cache
+ boolean local = cache.isLocal();
+ cache.setLocal(false);
+
+ removeNullNode(node);
+
+ cache.setLocal(local);
+
// if not a root node
if (node.getParentIdentifier() != null)
{
@@ -790,6 +836,41 @@
return (ItemData)cache.put(makeItemFqn(node.getIdentifier()), ITEM_DATA, node);
}
+ /**
+ * Internal put NullNode.
+ *
+ * @param node, NodeData, new data to put in the cache
+ * @return ItemData, previous data or null
+ */
+ protected ItemData putNullNode(NullNodeData node)
+ {
+ return (ItemData)cache.put(makeNullItemFqn(node.getIdentifier()), ITEM_DATA,
node);
+ }
+
+ /**
+ * Removes NullNode from cache.
+ *
+ * @param item
+ * that possible has corresponding NullNode in cache
+ *
+ */
+ protected void removeNullNode(ItemData item)
+ {
+ Fqn<String> fqn = makeNullItemFqn(item.getIdentifier());
+ if ((NullNodeData)cache.get(fqn, ITEM_DATA) != null)
+ {
+ cache.removeNode(fqn);
+ }
+
+ fqn =
+ makeNullItemFqn(item.getParentIdentifier() + "$"
+ + item.getQPath().getEntries()[item.getQPath().getEntries().length -
1].getAsString(true));
+ if (cache.get(fqn, ITEM_DATA) != null)
+ {
+ cache.removeNode(fqn);
+ }
+ }
+
protected ItemData putNodeInBufferedCache(NodeData node, ModifyChildOption
modifyListsOfChild)
{
// if not a root node
@@ -819,6 +900,15 @@
*/
protected PropertyData putProperty(PropertyData prop, ModifyChildOption
modifyListsOfChild)
{
+
+ // remove possible NullNodeData from cache
+ boolean local = cache.isLocal();
+ cache.setLocal(false);
+
+ removeNullNode(prop);
+
+ cache.setLocal(local);
+
// add in CHILD_PROPS
cache.put(makeChildFqn(childProps, prop.getParentIdentifier(),
prop.getQPath().getEntries()[prop.getQPath()
.getEntries().length - 1]), ITEM_ID, prop.getIdentifier());
@@ -829,6 +919,10 @@
{
cache.addToList(makeChildListFqn(childPropsList, prop.getParentIdentifier()),
ITEM_LIST, prop.getIdentifier());
}
+
+ ItemData result =
+ get(prop.getParentIdentifier(),
prop.getQPath().getEntries()[prop.getQPath().getEntries().length - 1]);
+
// add in ITEMS
return (PropertyData)cache.put(makeItemFqn(prop.getIdentifier()), ITEM_DATA,
prop);
}
Modified:
jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
===================================================================
---
jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-04-07
13:07:13 UTC (rev 2217)
+++
jcr/branches/1.14.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-04-07
14:03:09 UTC (rev 2218)
@@ -24,7 +24,9 @@
import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.NullNodeData;
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.storage.SystemDataContainerHolder;
@@ -163,7 +165,8 @@
public void testGetItemDataByNodeDataNQPathEntry() throws Exception
{
- final NodeData nodeData = new PersistedNodeData("getItemData", null,
null, 0, 1, null, null, null);
+ final NodeData nodeData =
+ new PersistedNodeData("getItemData", new QPath(new QPathEntry[]{}),
null, 0, 1, null, null, null);
assertEquals(0, con.getItemDataByNodeDataNQPathEntryCalls.get());
MyTask task = new MyTask()
{