[exo-jcr-commits] exo-jcr SVN: r3383 - in jcr/branches/1.12.x/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/persistent and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Nov 3 04:19:29 EDT 2010
Author: tolusha
Date: 2010-11-03 04:19:28 -0400 (Wed, 03 Nov 2010)
New Revision: 3383
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
Log:
JCR-1491: Stroting results of the method getReferencesData into the cache
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-03 08:03:25 UTC (rev 3382)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-03 08:19:28 UTC (rev 3383)
@@ -107,6 +107,26 @@
*/
List<PropertyData> listChildProperties(final NodeData parentData);
+ /**
+ * Get referenced properties.
+ *
+ * @param identifier
+ * referenceable id
+ * @return
+ * list of REFERENCE properties.
+ */
+ List<PropertyData> getReferencedProperties(String identifier);
+
+ /**
+ * Add referenced properties.
+ *
+ * @param identifier
+ * referenceable id
+ * @param refProperties
+ * list of properties
+ */
+ void addReferencedProperties(String identifier, List<PropertyData> refProperties);
+
/**
* Adds (or updates if found) ItemData.
*
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-11-03 08:03:25 UTC (rev 3382)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-11-03 08:19:28 UTC (rev 3383)
@@ -26,12 +26,15 @@
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPathEntry;
import org.exoplatform.services.jcr.datamodel.ValueData;
+import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.JBossCacheWorkspaceStorageCache;
import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCStorageConnection;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.transaction.TransactionService;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -96,6 +99,11 @@
*/
static private final int GET_LIST_PROPERTIES = 5;
+ /**
+ * GET_REFERENCES type.
+ */
+ static public final int GET_REFERENCES = 6;
+
/**
* Request type.
*/
@@ -380,6 +388,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public ItemData getItemData(NodeData parentData, QPathEntry name) throws RepositoryException
{
return getItemData(parentData, name, ItemType.UNKNOWN);
@@ -477,7 +486,26 @@
public List<PropertyData> getReferencesData(String identifier, boolean skipVersionStorage)
throws RepositoryException
{
- return super.getReferencesData(identifier, skipVersionStorage);
+ List<PropertyData> props = getReferencedPropertiesData(identifier);
+
+ if (skipVersionStorage)
+ {
+ List<PropertyData> result = new ArrayList<PropertyData>();
+
+ Iterator<PropertyData> iterator = props.iterator();
+ while (iterator.hasNext())
+ {
+ PropertyData prop = iterator.next();
+ if (!prop.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
+ {
+ result.add(prop);
+ }
+ }
+
+ return result;
+ }
+
+ return props;
}
/**
@@ -659,6 +687,54 @@
}
}
+ /**
+ * Get referenced properties data.
+ *
+ * @param identifier
+ * referenceable identifier
+ * @return List<PropertyData>
+ * @throws RepositoryException
+ * Repository error
+ */
+ protected List<PropertyData> getReferencedPropertiesData(String identifier) throws RepositoryException
+ {
+ List<PropertyData> refProps = null;
+ if (cache.isEnabled())
+ {
+ refProps = cache.getReferencedProperties(identifier);
+ if (refProps != null)
+ {
+ return refProps;
+ }
+ }
+ final DataRequest request = new DataRequest(identifier, DataRequest.GET_REFERENCES);
+
+ try
+ {
+ request.start();
+ if (cache.isEnabled())
+ {
+ // Try first to get the value from the cache since a
+ // request could have been launched just before
+ refProps = cache.getReferencedProperties(identifier);
+ if (refProps != null)
+ {
+ return refProps;
+ }
+ }
+ refProps = super.getReferencesData(identifier, false);
+ if (cache.isEnabled())
+ {
+ cache.addReferencedProperties(identifier, refProps);
+ }
+ return refProps;
+ }
+ finally
+ {
+ request.done();
+ }
+ }
+
/**
* Get persisted ItemData.
*
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-11-03 08:03:25 UTC (rev 3382)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-11-03 08:19:28 UTC (rev 3383)
@@ -1064,6 +1064,21 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ }
+
/**
* {@inheritDoc}
*/
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-11-03 08:03:25 UTC (rev 3382)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-11-03 08:19:28 UTC (rev 3383)
@@ -18,14 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
-import java.io.Serializable;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.transaction.TransactionManager;
-
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -42,6 +34,14 @@
import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jgroups.Address;
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
/**
* Decorator over the JBossCache that stores changes in buffer, then sorts and applies to JBossCache.
*
@@ -650,11 +650,11 @@
* @param key
* @param value
*/
- public void addToList(Fqn fqn, String key, Object value)
+ public void addToList(Fqn fqn, String key, Object value, boolean forceModify)
{
CompressedChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, changesContainer.getHistoryIndex(),
- local.get(), useExpiration, expirationTimeOut));
+ changesContainer.add(new AddToListContainer(fqn, key, value, parentCache, forceModify, changesContainer
+ .getHistoryIndex(), local.get(), useExpiration, expirationTimeOut));
}
/**
@@ -828,12 +828,15 @@
private final Object value;
+ private final boolean forceModify;
+
public AddToListContainer(Fqn fqn, Serializable key, Object value, Cache<Serializable, Object> cache,
- int historicalIndex, boolean local, boolean useExpiration, long timeOut)
+ boolean forceModify, int historicalIndex, boolean local, boolean useExpiration, long timeOut)
{
super(fqn, ChangesType.PUT_KEY, cache, historicalIndex, local, useExpiration, timeOut);
this.key = key;
this.value = value;
+ this.forceModify = forceModify;
}
@Override
@@ -844,8 +847,8 @@
// 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)
+ // if set found or null, perform add
+ if (existingObject instanceof Set || (existingObject == null && forceModify))
{
// set found
if (existingObject instanceof Set)
@@ -862,7 +865,7 @@
setCacheLocalMode();
cache.put(fqn, key, newSet);
}
- else
+ else if (existingObject != null)
{
LOG.error("Unexpected object found by FQN:" + getFqn() + " and key:" + key + ". Expected Set, but found:"
+ existingObject.getClass().getName());
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-03 08:03:25 UTC (rev 3382)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-03 08:19:28 UTC (rev 3383)
@@ -33,6 +33,7 @@
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.Constants;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
@@ -46,6 +47,7 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.ExpirationAlgorithmConfig;
+import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@@ -56,6 +58,7 @@
import java.util.NoSuchElementException;
import java.util.Set;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.transaction.TransactionManager;
@@ -114,6 +117,8 @@
public static final String LOCKS = "$LOCKS".intern();
+ public static final String REFERENCE = "$REFERENCE".intern();
+
public static final String ITEM_DATA = "$data".intern();
public static final String ITEM_ID = "$id".intern();
@@ -124,6 +129,8 @@
protected final Fqn<String> itemsRoot;
+ protected final Fqn<String> refRoot;
+
protected final Fqn<String> childNodes;
protected final Fqn<String> childProps;
@@ -312,6 +319,7 @@
.getParameterTime(JBOSSCACHE_EXPIRATION, JBOSSCACHE_EXPIRATION_DEFAULT));
this.itemsRoot = Fqn.fromElements(ITEMS);
+ this.refRoot = Fqn.fromElements(REFERENCE);
this.childNodes = Fqn.fromElements(CHILD_NODES);
this.childProps = Fqn.fromElements(CHILD_PROPS);
this.childNodesList = Fqn.fromElements(CHILD_NODES_LIST);
@@ -325,6 +333,7 @@
createResidentNode(childProps);
createResidentNode(childPropsList);
createResidentNode(itemsRoot);
+ createResidentNode(refRoot);
}
/**
@@ -483,6 +492,89 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ // get set of property uuids
+ final Set<String> set = (Set<String>)cache.get(makeRefFqn(identifier), ITEM_LIST);
+ if (set != null)
+ {
+ final List<PropertyData> props = new ArrayList<PropertyData>();
+
+ for (String propId : set)
+ {
+ PropertyData prop = (PropertyData)cache.get(makeItemFqn(propId), ITEM_DATA);
+ if (prop == null)
+ {
+ return null;
+ }
+
+ // add property as many times as has referenced values
+ for (ValueData vdata : prop.getValues())
+ {
+ try
+ {
+ if (new String(vdata.getAsByteArray(), Constants.DEFAULT_ENCODING).equals(identifier))
+ {
+ props.add(prop);
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ // Do not nothing.
+ }
+ catch (IOException e)
+ {
+ // Do not nothing.
+ }
+ }
+ }
+ return props;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ boolean inTransaction = cache.isTransactionActive();
+ try
+ {
+ if (!inTransaction)
+ {
+ cache.beginTransaction();
+ }
+
+ cache.setLocal(true);
+
+ // remove previous all
+ cache.removeNode(makeRefFqn(identifier));
+
+ Set<Object> set = new HashSet<Object>();
+ for (PropertyData prop : refProperties)
+ {
+ putProperty(prop, ModifyChildOption.NOT_MODIFY);
+ set.add(prop.getIdentifier());
+ }
+ cache.put(makeRefFqn(identifier), ITEM_LIST, set);
+ }
+ finally
+ {
+ cache.setLocal(false);
+ if (!inTransaction)
+ {
+ cache.commitTransaction();
+ }
+ }
+ }
+
/**
* {@inheritDoc}
*/
@@ -735,7 +827,7 @@
public long getSize()
{
// Total number of JBC nodes in the cache - the total amount of resident nodes
- return cache.getNumberOfNodes() - 5;
+ return cache.getNumberOfNodes() - 6;
}
/**
@@ -759,6 +851,17 @@
return Fqn.fromRelativeElements(itemsRoot, itemId);
}
+ /**
+ * Make Item absolute Fqn, i.e. /$REF/itemID.
+ *
+ * @param itemId String
+ * @return Fqn
+ */
+ protected Fqn<String> makeRefFqn(String itemId)
+ {
+ return Fqn.fromRelativeElements(refRoot, itemId);
+ }
+
/**
* Make child Item absolute Fqn, i.e. /root/parentId/childName.
*
@@ -843,15 +946,12 @@
cache.put(
makeChildFqn(childNodes, node.getParentIdentifier(), node.getQPath().getEntries()[node.getQPath()
.getEntries().length - 1]), ITEM_ID, node.getIdentifier());
- // if MODIFY and List present OR FORCE_MODIFY, then write
- if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.getNode(makeChildListFqn(childNodesList,
- node.getParentIdentifier())) != null)
- || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY)
{
cache.addToList(makeChildListFqn(childNodesList, node.getParentIdentifier()), ITEM_LIST,
- node.getIdentifier());
+ node.getIdentifier(), modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
-
}
// add in ITEMS
return (ItemData)cache.put(makeItemFqn(node.getIdentifier()), ITEM_DATA, node);
@@ -866,13 +966,11 @@
cache.put(
makeChildFqn(childNodes, node.getParentIdentifier(), node.getQPath().getEntries()[node.getQPath()
.getEntries().length - 1]), ITEM_ID, node.getIdentifier());
- // if MODIFY and List present OR FORCE_MODIFY, then write
- if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.getNode(makeChildListFqn(childNodesList,
- node.getParentIdentifier())) != null)
- || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY)
{
cache.addToList(makeChildListFqn(childNodesList, node.getParentIdentifier()), ITEM_LIST,
- node.getIdentifier());
+ node.getIdentifier(), modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
}
// add in ITEMS
@@ -891,13 +989,37 @@
cache.put(
makeChildFqn(childProps, prop.getParentIdentifier(),
prop.getQPath().getEntries()[prop.getQPath().getEntries().length - 1]), ITEM_ID, prop.getIdentifier());
- // if MODIFY and List present OR FORCE_MODIFY, then write
- if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.getNode(makeChildListFqn(childPropsList,
- prop.getParentIdentifier())) != null)
- || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY)
{
- cache.addToList(makeChildListFqn(childPropsList, prop.getParentIdentifier()), ITEM_LIST, prop.getIdentifier());
+ cache.addToList(makeChildListFqn(childPropsList, prop.getParentIdentifier()), ITEM_LIST, prop.getIdentifier(),
+ modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
+
+ // add referenced property
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY && prop.getType() == PropertyType.REFERENCE)
+ {
+ for (ValueData vdata : prop.getValues())
+ {
+ String nodeIdentifier = null;
+ try
+ {
+ nodeIdentifier = new String(vdata.getAsByteArray(), Constants.DEFAULT_ENCODING);
+ }
+ catch (IllegalStateException e)
+ {
+ // Do nothing. Never happens.
+ }
+ catch (IOException e)
+ {
+ // Do nothing. Never happens.
+ }
+
+ cache.addToList(makeRefFqn(nodeIdentifier), ITEM_LIST, prop.getIdentifier(),
+ modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
+ }
+ }
+
// add in ITEMS
return (PropertyData)cache.put(makeItemFqn(prop.getIdentifier()), ITEM_DATA, prop);
}
@@ -930,6 +1052,8 @@
// remove from CHILD_PROPS_LIST as parent
cache.removeNode(makeChildListFqn(childPropsList, item.getIdentifier()));
}
+
+ cache.removeNode(makeRefFqn(item.getIdentifier()));
}
else
{
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-11-03 08:03:25 UTC (rev 3382)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-11-03 08:19:28 UTC (rev 3383)
@@ -338,6 +338,15 @@
return childProperties;
}
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ return null;
+ }
+
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ }
+
public long getSize()
{
return 0;
More information about the exo-jcr-commits
mailing list