[exo-jcr-commits] exo-jcr SVN: r3514 - in jcr/branches/1.14-ISPN/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/persistent and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Nov 22 11:14:37 EST 2010
Author: nzamosenchuk
Date: 2010-11-22 11:14:36 -0500 (Mon, 22 Nov 2010)
New Revision: 3514
Added:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/CacheRefsId.java
Modified:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/BufferedISPNCache.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
Log:
EXOJCR-1039: Porting code for storing result of getReferences in the cache made within JCR-1491 and EXOJCR-1029 , into the Infninispan-based classes.
Attention! Please take in to the consideration, that JBoss-related code contains stub methods! For testing purposes only! MODIFICATIONS OF JBC CODE SHOULD NOT BE PORTED INTO THE TRUNK!
Modified: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-22 16:08:28 UTC (rev 3513)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -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.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-11-22 16:08:28 UTC (rev 3513)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -29,12 +29,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;
@@ -99,6 +102,11 @@
*/
static private final int GET_LIST_PROPERTIES = 5;
+ /**
+ * GET_REFERENCES type.
+ */
+ static public final int GET_REFERENCES = 6;
+
/**
* Request type.
*/
@@ -383,6 +391,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public ItemData getItemData(NodeData parentData, QPathEntry name) throws RepositoryException
{
return getItemData(parentData, name, ItemType.UNKNOWN);
@@ -484,7 +493,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;
}
/**
@@ -666,6 +694,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.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-11-22 16:08:28 UTC (rev 3513)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -841,6 +841,21 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ }
+
/**
* {@inheritDoc}
*/
Modified: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/BufferedISPNCache.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/BufferedISPNCache.java 2010-11-22 16:08:28 UTC (rev 3513)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/BufferedISPNCache.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -194,11 +194,14 @@
{
private final Object value;
+ private final boolean forceModify;
+
public AddToListContainer(CacheKey key, Object value, AdvancedCache<Serializable, Object> cache,
- int historicalIndex, boolean local, Boolean allowLocalChanges)
+ boolean forceModify, int historicalIndex, boolean local, Boolean allowLocalChanges)
{
super(key, ChangesType.PUT, cache, historicalIndex, local, allowLocalChanges);
this.value = value;
+ this.forceModify = forceModify;
}
@Override
@@ -211,7 +214,7 @@
Set<Object> newSet = new HashSet<Object>();
// if set found of null, perform add
- if (existingObject instanceof Set || existingObject == null)
+ if (existingObject instanceof Set || (existingObject == null && forceModify))
{
// set found
if (existingObject instanceof Set)
@@ -223,7 +226,7 @@
setCacheLocalMode();
cache.put(key, newSet);
}
- else
+ else if (existingObject != null)
{
LOG.error("Unexpected object found by key " + key.toString() + ". Expected Set, but found:"
+ existingObject.getClass().getName());
@@ -931,11 +934,11 @@
* @param key
* @param value
*/
- public void addToList(CacheKey key, Object value)
+ public void addToList(CacheKey key, Object value, boolean forceModify)
{
CompressedISPNChangesBuffer changesContainer = getChangesBufferSafe();
- changesContainer.add(new AddToListContainer(key, value, parentCache, changesContainer.getHistoryIndex(), local
- .get(), allowLocalChanges));
+ changesContainer.add(new AddToListContainer(key, value, parentCache, forceModify, changesContainer
+ .getHistoryIndex(), local.get(), allowLocalChanges));
}
/**
Added: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/CacheRefsId.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/CacheRefsId.java (rev 0)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/CacheRefsId.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent.infinispan;
+
+/**
+ * Created by The eXo Platform SAS
+ *
+ * Date: 10.06.2008
+ *
+ * Cache record used to store item Id key.
+ *
+ * @author <a href="mailto:peter.nedonosko at exoplatform.com.ua">Peter Nedonosko</a>
+ * @version $Id: CachePropsId.java 2845 2010-07-30 13:29:37Z tolusha $
+ */
+public class CacheRefsId extends CacheKey
+{
+
+ public static final String PREFIX = "R";
+
+ CacheRefsId(String id)
+ {
+ super(PREFIX + id);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof CacheRefsId)
+ {
+ CacheRefsId cachePropsId = (CacheRefsId)obj;
+ return (cachePropsId.hash == hash && cachePropsId.id.equals(id));
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
Property changes on: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/CacheRefsId.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java 2010-11-22 16:08:28 UTC (rev 3513)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -37,6 +37,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;
@@ -45,6 +46,7 @@
import org.exoplatform.services.log.Log;
import org.infinispan.Cache;
+import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@@ -55,6 +57,7 @@
import java.util.NoSuchElementException;
import java.util.Set;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -650,10 +653,10 @@
cache.put(new CacheQPath(node.getParentIdentifier(), node.getQPath(), ItemType.NODE), node.getIdentifier());
// if MODIFY and List present OR FORCE_MODIFY, then write
- if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.get(new CacheNodesId(node.getParentIdentifier())) != null)
- || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY)
{
- cache.addToList(new CacheNodesId(node.getParentIdentifier()), node.getIdentifier());
+ cache.addToList(new CacheNodesId(node.getParentIdentifier()), node.getIdentifier(),
+ modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
}
@@ -667,10 +670,10 @@
cache.put(new CacheQPath(node.getParentIdentifier(), node.getQPath(), ItemType.NODE), node.getIdentifier());
// if MODIFY and List present OR FORCE_MODIFY, then write
- if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.get(new CacheNodesId(node.getParentIdentifier())) != null)
- || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY)
{
- cache.addToList(new CacheNodesId(node.getParentIdentifier()), node.getIdentifier());
+ cache.addToList(new CacheNodesId(node.getParentIdentifier()), node.getIdentifier(),
+ modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
}
@@ -726,14 +729,38 @@
protected PropertyData putProperty(PropertyData prop, ModifyChildOption modifyListsOfChild)
{
// if MODIFY and List present OR FORCE_MODIFY, then write
- if ((modifyListsOfChild == ModifyChildOption.MODIFY && cache.get(new CachePropsId(prop.getParentIdentifier())) != null)
- || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY)
{
- cache.addToList(new CachePropsId(prop.getParentIdentifier()), prop.getIdentifier());
+ cache.addToList(new CachePropsId(prop.getParentIdentifier()), prop.getIdentifier(),
+ modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
cache.put(new CacheQPath(prop.getParentIdentifier(), prop.getQPath(), ItemType.PROPERTY), prop.getIdentifier());
+ // add referenced property
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY && prop.getType() == PropertyType.REFERENCE)
+ {
+ List<ValueData> lData = prop.getValues();
+ for (int i = 0, length = lData.size(); i < length; i++)
+ {
+ ValueData vdata = lData.get(i);
+ 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(new CacheRefsId(nodeIdentifier), prop.getIdentifier(),
+ modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
+ }
+ }
// NullItemData must never be returned inside internal cache operations.
PropertyData propData = (PropertyData)cache.put(new CacheId(prop.getIdentifier()), prop, true);
return (propData instanceof NullPropertyData) ? null : propData;
@@ -752,6 +779,7 @@
cache.remove(new CachePropsId(item.getIdentifier()));
cache.removeFromList(new CacheNodesId(item.getParentIdentifier()), item.getIdentifier());
+ cache.remove(new CacheRefsId(item.getIdentifier()));
}
else
{
@@ -1003,4 +1031,88 @@
}
}
+ /**
+ * @see org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache#addReferencedProperties(java.lang.String, java.util.List)
+ */
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ boolean inTransaction = cache.isTransactionActive();
+ try
+ {
+ if (!inTransaction)
+ {
+ cache.beginTransaction();
+ }
+ cache.setLocal(true);
+ // remove previous all (to be sure about consistency)
+ cache.remove(new CacheRefsId(identifier));
+
+ Set<Object> set = new HashSet<Object>();
+ for (PropertyData prop : refProperties)
+ {
+ putProperty(prop, ModifyChildOption.NOT_MODIFY);
+ set.add(prop.getIdentifier());
+ }
+ cache.put(new CacheRefsId(identifier), set);
+ }
+ finally
+ {
+ cache.setLocal(false);
+ if (!inTransaction)
+ {
+ cache.commitTransaction();
+ }
+ }
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache#getReferencedProperties(java.lang.String)
+ */
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ // get list of children uuids
+ final Set<String> set = (Set<String>)cache.get(new CacheRefsId(identifier));
+ if (set != null)
+ {
+ final List<PropertyData> props = new ArrayList<PropertyData>();
+
+ for (String childId : set)
+ {
+ PropertyData prop = (PropertyData)cache.get(new CacheId(childId));
+
+ if (prop == null || prop instanceof NullItemData)
+ {
+ return null;
+ }
+ // add property as many times as has referenced values
+ List<ValueData> lData = prop.getValues();
+ for (int i = 0, length = lData.size(); i < length; i++)
+ {
+ ValueData vdata = lData.get(i);
+ try
+ {
+ if (new String(vdata.getAsByteArray(), Constants.DEFAULT_ENCODING).equals(identifier))
+ {
+ props.add(prop);
+ }
+ }
+ catch (IllegalStateException e)
+ {
+ // property was not added, force read from lower layer
+ return null;
+ }
+ catch (IOException e)
+ {
+ // property was not added, force read from lower layer
+ return null;
+ }
+ }
+ }
+ return props;
+ }
+ else
+ {
+ return null;
+ }
+ }
}
Modified: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-22 16:08:28 UTC (rev 3513)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -1337,4 +1337,22 @@
}
}
}
+
+ /**
+ * @see org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache#addReferencedProperties(java.lang.String, java.util.List)
+ */
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache#getReferencedProperties(java.lang.String)
+ */
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
Modified: jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-11-22 16:08:28 UTC (rev 3513)
+++ jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-11-22 16:14:36 UTC (rev 3514)
@@ -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