[exo-jcr-commits] exo-jcr SVN: r1405 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Jan 15 07:48:12 EST 2010
Author: nzamosenchuk
Date: 2010-01-15 07:48:11 -0500 (Fri, 15 Jan 2010)
New Revision: 1405
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.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-391: Initial impl of code, managing list of child-items as serialized sets.
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-01-15 12:06:43 UTC (rev 1404)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-01-15 12:48:11 UTC (rev 1405)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
@@ -32,7 +34,9 @@
import org.jgroups.Address;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -58,6 +62,9 @@
private ThreadLocal<CompressedChangesList> changesList = new ThreadLocal<CompressedChangesList>();
+ protected static final Log LOG =
+ ExoLogger.getLogger("org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.BufferedJBossCache");
+
public BufferedJBossCache(Cache<Serializable, Object> parentCache)
{
super();
@@ -532,8 +539,43 @@
return ((CacheSPI<Serializable, Object>)parentCache).getTransactionManager();
}
+ /**
+ * Gets object by key. If it is List<Object> adds new value to it.
+ *
+ * @param fqn
+ * @param key
+ * @param value
+ */
+ public void addToList(Fqn fqn, String key, Object value)
+ {
+ CompressedChangesList changesContainer = changesList.get();
+ if (changesContainer == null)
+ {
+ throw new IllegalStateException("changesContainer should not be empty");
+ }
+ changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex()));
+ }
+
+ /**
+ * Gets object by key. If it is List<Object> removes value from it.
+ *
+ * @param fqn
+ * @param key
+ * @param value
+ */
+ public void removeFromList(Fqn fqn, String key, Object value)
+ {
+ CompressedChangesList changesContainer = changesList.get();
+ if (changesContainer == null)
+ {
+ throw new IllegalStateException("changesContainer should not be empty");
+ }
+ changesContainer
+ .add(new RemoveFromListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex()));
+ }
+
public static enum ChangesType {
- REMOVE, REMOVE_KEY, PUT, PUT_KEY;
+ REMOVE, REMOVE_KEY, PUT, PUT_KEY, PUT_TO_LIST;
}
/**
@@ -647,6 +689,86 @@
}
/**
+ * Put to list container.
+ * It tries to get list by given key. If it is list adds new value and puts list.
+ */
+ public static class AddToListContainer extends ChangesContainer
+ {
+ private final Serializable key;
+
+ private final Object value;
+
+ public AddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex)
+ {
+ super(fqn, ChangesType.PUT_KEY, cache, historicalIndex);
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public void apply()
+ {
+ // force writeLock on next read
+ cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ // object found by FQN and key;
+ Object existingObject = cache.get(getFqn(), key);
+ Set<Object> newSet = new HashSet<Object>();
+ // if set found of null, perform add
+ if (existingObject instanceof Set || existingObject == null)
+ {
+ // set found
+ if (existingObject instanceof Set)
+ {
+ newSet.addAll((Set<Object>)existingObject);
+ }
+ newSet.add(value);
+ cache.put(fqn, key, newSet);
+ }
+ else
+ {
+ LOG.error("Unexpected value found by FQN:" + getFqn() + " and key:" + key + ". Expected list, found:"
+ + existingObject.getClass().getName());
+ }
+ }
+ }
+
+ /**
+ * Removes from list container.
+ * It tries to get list by given key. If it is list removes value and puts list.
+ */
+ public static class RemoveFromListContainer extends ChangesContainer
+ {
+ private final Serializable key;
+
+ private final Object value;
+
+ public RemoveFromListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
+ int historicalIndex)
+ {
+ super(fqn, ChangesType.REMOVE_KEY, cache, historicalIndex);
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public void apply()
+ {
+ // force writeLock on next read
+ cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true);
+ // object found by FQN and key;
+ Object existingObject = cache.get(getFqn(), key);
+ // if found value is really set! add to it.
+ if (existingObject instanceof Set)
+ {
+ Set<Object> newSet = new HashSet<Object>((Set<Object>)existingObject);
+ newSet.remove(value);
+ cache.put(fqn, key, newSet);
+ }
+ }
+ }
+
+ /**
* Remove container.
*/
public static class RemoveKeyContainer extends ChangesContainer
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 2010-01-15 12:06:43 UTC (rev 1404)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-15 12:48:11 UTC (rev 1405)
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -112,6 +113,8 @@
public static final String ITEM_ID = "$id".intern();
+ public static final String ITEM_LIST = "$lists".intern();
+
/**
* Empty cache node data for CHILD_x_LIST.
*/
@@ -471,7 +474,8 @@
else
{
// cache fact of empty childs list
- cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
+ cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST, new HashSet<Object>());
+ //cache.put(makeChildListFqn(childNodesList, parent.getIdentifier()), NULL_DATA);
}
}
@@ -551,11 +555,12 @@
public List<NodeData> getChildNodes(final NodeData parent)
{
final List<NodeData> childs = new ArrayList<NodeData>();
- final Node<Serializable, Object> parentNode =
- cache.getNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
- if (parentNode != null)
+ //final Node<Serializable, Object> parentNode =
+ // cache.getNode(makeChildListFqn(childNodesList, parent.getIdentifier()));
+ final Set<Object> set = (Set<Object>)cache.get(makeChildListFqn(childNodesList, parent.getIdentifier()), ITEM_LIST);
+ if (set != null)
{
- for (Object child : parentNode.getChildrenNames())
+ for (Object child : set)
{
NodeData node = (NodeData)cache.get(makeItemFqn((String)child), ITEM_DATA);
if (node == null)
@@ -603,10 +608,11 @@
protected List<PropertyData> getChildProps(String parentId, boolean withValue)
{
final List<PropertyData> childs = new ArrayList<PropertyData>();
- final Node<Serializable, Object> parentNode = cache.getNode(makeChildListFqn(childPropsList, parentId));
- if (parentNode != null)
+ //final Node<Serializable, Object> parentNode = cache.getNode(makeChildListFqn(childPropsList, parentId));
+ final Set<Object> list = (Set<Object>)cache.get(makeChildListFqn(childPropsList, parentId), ITEM_LIST);
+ if (list != null)
{
- for (Object child : parentNode.getChildrenNames())
+ for (Object child : list)
{
PropertyData node = (PropertyData)cache.get(makeItemFqn((String)child), ITEM_DATA);
if (node == null)
@@ -747,7 +753,8 @@
if (cache.getNode(makeChildListFqn(childNodesList, node.getParentIdentifier())) != null
|| modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
{
- cache.put(makeChildListFqn(childNodesList, node.getParentIdentifier(), node.getIdentifier()), NULL_DATA);
+ //cache.put(makeChildListFqn(childNodesList, node.getParentIdentifier(), node.getIdentifier()), NULL_DATA);
+ cache.addToList(makeChildListFqn(childNodesList, node.getParentIdentifier()), ITEM_LIST, node.getIdentifier());
}
}
}
@@ -781,7 +788,8 @@
if (cache.getNode(makeChildListFqn(childPropsList, prop.getParentIdentifier())) != null
|| modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
{
- cache.put(makeChildListFqn(childPropsList, prop.getParentIdentifier(), prop.getIdentifier()), NULL_DATA);
+ //cache.put(makeChildListFqn(childPropsList, prop.getParentIdentifier(), prop.getIdentifier()), NULL_DATA);
+ cache.addToList(makeChildListFqn(childPropsList, prop.getParentIdentifier()), ITEM_LIST, prop.getIdentifier());
}
}
@@ -808,7 +816,8 @@
.getQPath().getEntries().length - 1]));
// remove from CHILD_NODES_LIST of parent
- cache.removeNode(makeChildListFqn(childNodesList, item.getParentIdentifier(), item.getIdentifier()));
+ //cache.removeNode(makeChildListFqn(childNodesList, item.getParentIdentifier(), item.getIdentifier()));
+ cache.removeFromList(makeChildListFqn(childNodesList, item.getParentIdentifier()), ITEM_LIST, item.getIdentifier());
// remove from CHILD_NODES as parent
cache.removeNode(makeChildListFqn(childNodes, item.getIdentifier()));
@@ -830,7 +839,8 @@
.getQPath().getEntries().length - 1]));
// remove from CHILD_PROPS_LIST
- cache.removeNode(makeChildListFqn(childPropsList, item.getParentIdentifier(), item.getIdentifier()));
+ //cache.removeNode(makeChildListFqn(childPropsList, item.getParentIdentifier(), item.getIdentifier()));
+ cache.removeFromList(makeChildListFqn(childPropsList, item.getParentIdentifier()), ITEM_LIST, item.getIdentifier());
// TODO REFERENCEs hadnling
//if (prop.getType() == PropertyType.REFERENCE)
More information about the exo-jcr-commits
mailing list