exo-jcr SVN: r3386 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-11-03 08:25:11 -0400 (Wed, 03 Nov 2010)
New Revision: 3386
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
Log:
EXOJCR-1030: NodeImpl.removeLockable modified to remain consistent
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-11-03 10:11:06 UTC (rev 3385)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-11-03 12:25:11 UTC (rev 3386)
@@ -2820,7 +2820,7 @@
{
// locked, should be unlocked
- if (!session.getLockManager().isLockHolder(this.nodeData()))
+ if (!session.getLockManager().isLockHolder(this))
{
throw new LockException("There are no permission to unlock the node " + getPath());
}
13 years, 7 months
exo-jcr SVN: r3385 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/core/lock and 1 other directories.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-11-03 06:11:06 -0400 (Wed, 03 Nov 2010)
New Revision: 3385
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLock.java
Log:
EXOJCR-1030: "Impossible to retrieve the lock on a node even by the root" fixed
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-11-03 09:02:48 UTC (rev 3384)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/NodeImpl.java 2010-11-03 10:11:06 UTC (rev 3385)
@@ -2401,7 +2401,7 @@
throw new LockException("The node not locked " + getPath());
}
- if (!session.getLockManager().isLockHolder(this.nodeData()))
+ if (!session.getLockManager().isLockHolder(this))
{
throw new LockException("There are no permission to unlock the node " + getPath());
}
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java 2010-11-03 09:02:48 UTC (rev 3384)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/AbstractSessionLockManager.java 2010-11-03 10:11:06 UTC (rev 3385)
@@ -19,7 +19,9 @@
package org.exoplatform.services.jcr.impl.core.lock;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
+import org.exoplatform.services.security.IdentityConstants;
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
@@ -90,6 +92,30 @@
/**
* {@inheritDoc}
*/
+ public boolean isLockHolder(NodeImpl node) throws RepositoryException
+ {
+ NodeData nodeData = (NodeData)node.getData();
+
+ // check if session has system credentials
+ if (IdentityConstants.SYSTEM.equals(node.getSession().getUserID()))
+ {
+ return true;
+ }
+
+ //check is parent node also new
+ if (transientManager.isNew(nodeData.getIdentifier()) && transientManager.isNew(nodeData.getParentIdentifier()))
+ {
+ return true;
+ }
+ else
+ {
+ return isPersistedLockHolder(nodeData);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public boolean isLockHolder(NodeData node) throws RepositoryException
{
//check is parent node also new
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2010-11-03 09:02:48 UTC (rev 3384)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2010-11-03 10:11:06 UTC (rev 3385)
@@ -106,17 +106,32 @@
* Returns <code>true</code> if the specified session holds a lock on the given node; otherwise
* returns <code>false</code>. <p/> Note that <code>isLockHolder(session, node)==true</code>
* implies <code>holdsLock(node)==true</code>.
- *
+ *
* @param session
* session
* @param node
- * node
+ * node data
* @return if the specified session holds a lock on the given node; otherwise returns
* <code>false</code>
+ * @deprecated
*/
boolean isLockHolder(NodeData node) throws RepositoryException;
/**
+ * Returns <code>true</code> if the specified session holds a lock on the given node; otherwise
+ * returns <code>false</code>. <p/> Note that <code>isLockHolder(session, node)==true</code>
+ * implies <code>holdsLock(node)==true</code>.
+ *
+ * @param session
+ * session
+ * @param nodeImpl
+ * node implementation
+ * @return if the specified session holds a lock on the given node; otherwise returns
+ * <code>false</code>
+ */
+ boolean isLockHolder(NodeImpl nodeImpl) throws RepositoryException;
+
+ /**
* Invoked by a session to inform that a lock token has been removed.
*
* @param session
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLock.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLock.java 2010-11-03 09:02:48 UTC (rev 3384)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLock.java 2010-11-03 10:11:06 UTC (rev 3385)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.JcrAPIBaseTest;
import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.security.IdentityConstants;
import java.io.ByteArrayInputStream;
import java.util.Calendar;
@@ -451,4 +452,55 @@
}
}
+ public void testUnlockWithSystemSession() throws Exception
+ {
+ Node lockedNode = root.addNode("locked node 2");
+ Session session2 = null, session3 = null;
+ try
+ {
+ Node node = (Node)session.getItem(lockedNode.getPath());
+
+ if (!node.isNodeType("mix:lockable"))
+ {
+ if (node.canAddMixin("mix:lockable"))
+ {
+ node.addMixin("mix:lockable");
+ session.save();
+ }
+ }
+ node.lock(true, false);
+
+ session2 = repository.login(credentials, "ws");
+ node = (Node)session2.getItem(lockedNode.getPath());
+ assertTrue(node.isLocked());
+ try
+ {
+ node.unlock();
+ fail("a LockException is expected");
+ }
+ catch (LockException e)
+ {
+ // a LockException is expected
+ }
+ // The system session
+ session3 = repository.login(new CredentialsImpl(IdentityConstants.SYSTEM, "".toCharArray()), "ws");
+ node = (Node)session3.getItem(lockedNode.getPath());
+ assertTrue(node.isLocked());
+ node.unlock();
+ }
+ finally
+ {
+ lockedNode.remove();
+ session.save();
+ if (session2 != null)
+ {
+ session2.logout();
+ }
+ if (session3 != null)
+ {
+ session3.logout();
+ }
+ }
+ }
+
}
13 years, 7 months
exo-jcr SVN: r3384 - in jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/persistent and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-11-03 05:02:48 -0400 (Wed, 03 Nov 2010)
New Revision: 3384
Modified:
jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.12.5-GA-perf/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.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-03 08:19:28 UTC (rev 3383)
+++ jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-03 09:02:48 UTC (rev 3384)
@@ -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.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.5-GA-perf/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)
+++ jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-11-03 09:02:48 UTC (rev 3384)
@@ -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.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
===================================================================
--- jcr/branches/1.12.5-GA-perf/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)
+++ jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-11-03 09:02:48 UTC (rev 3384)
@@ -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.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.12.5-GA-perf/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)
+++ jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-11-03 09:02:48 UTC (rev 3384)
@@ -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.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.5-GA-perf/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)
+++ jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-03 09:02:48 UTC (rev 3384)
@@ -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.5-GA-perf/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java
===================================================================
--- jcr/branches/1.12.5-GA-perf/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)
+++ jcr/branches/1.12.5-GA-perf/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-11-03 09:02:48 UTC (rev 3384)
@@ -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;
13 years, 7 months
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.
by do-not-reply@jboss.org
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;
13 years, 7 months
exo-jcr SVN: r3382 - in jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp: client and 1 other directories.
by do-not-reply@jboss.org
Author: dkuleshov
Date: 2010-11-03 04:03:25 -0400 (Wed, 03 Nov 2010)
New Revision: 3382
Modified:
jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServer.java
jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java
jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServiceImpl.java
jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/client/FtpClientSessionImpl.java
jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/command/FtpCommandImpl.java
Log:
JCR-1494: now FTP server does show list of workspaces after repository restoring
Modified: jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServer.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServer.java 2010-11-02 15:51:38 UTC (rev 3381)
+++ jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServer.java 2010-11-03 08:03:25 UTC (rev 3382)
@@ -45,6 +45,10 @@
int getClientsCount();
+ /**
+ *
+ * @return {@link ManageableRepository} or <code>null</code> if repository can not be retrieved
+ */
ManageableRepository getRepository();
FtpCommand getCommand(String commandName);
Modified: jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java 2010-11-02 15:51:38 UTC (rev 3381)
+++ jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java 2010-11-03 08:03:25 UTC (rev 3382)
@@ -26,6 +26,8 @@
import org.exoplatform.services.ftp.config.FtpConfig;
import org.exoplatform.services.ftp.data.FtpDataChannelManager;
import org.exoplatform.services.ftp.data.FtpDataChannelManagerImpl;
+import org.exoplatform.services.jcr.RepositoryService;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -37,6 +39,9 @@
import java.net.Socket;
import java.util.ArrayList;
+import javax.jcr.RepositoryException;
+
+
/**
* Created by The eXo Platform SAS Author : Vitaly Guly <gavrik-vetal(a)ukr.net/mail.ru>
*
@@ -52,7 +57,7 @@
private Catalog commandCatalog;
- private ManageableRepository repository;
+ private RepositoryService repositoryService;
private FtpConfig configuration;
@@ -62,11 +67,11 @@
private ArrayList<FtpClientSession> clients = new ArrayList<FtpClientSession>();
- public FtpServerImpl(FtpConfig configuration, CommandService commandService, ManageableRepository repository)
+ public FtpServerImpl(FtpConfig configuration, CommandService commandService, RepositoryService repositoryService)
throws Exception
{
this.configuration = configuration;
- this.repository = repository;
+ this.repositoryService = repositoryService;
InputStream commandStream = getClass().getResourceAsStream(COMMAND_PATH);
@@ -153,7 +158,21 @@
public ManageableRepository getRepository()
{
- return repository;
+
+ try
+ {
+ return repositoryService.getDefaultRepository();
+ }
+ catch (RepositoryException e)
+ {
+ log.info("Repository exception. " + e.getMessage(), e);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ log.info("Repository configuration exception. " + e.getMessage(), e);
+ }
+
+ return null;
}
public FtpCommand getCommand(String commandName)
Modified: jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServiceImpl.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServiceImpl.java 2010-11-02 15:51:38 UTC (rev 3381)
+++ jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServiceImpl.java 2010-11-03 08:03:25 UTC (rev 3382)
@@ -61,7 +61,7 @@
log.info("Start service.");
try
{
- ftpServer = new FtpServerImpl(config, commandService, repositoryService.getRepository());
+ ftpServer = new FtpServerImpl(config, commandService, repositoryService);
ftpServer.start();
}
catch (Exception e)
Modified: jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/client/FtpClientSessionImpl.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/client/FtpClientSessionImpl.java 2010-11-02 15:51:38 UTC (rev 3381)
+++ jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/client/FtpClientSessionImpl.java 2010-11-03 08:03:25 UTC (rev 3382)
@@ -329,6 +329,10 @@
public Session getSession(String workspaceName) throws Exception
{
+ if (ftpServer.getRepository() == null)
+ {
+ throw new RepositoryException("Repository can not be retrieved.");
+ }
Session curSession = sessionFactory.getSession(workspaceName, ftpServer.getRepository());
curSession.refresh(false);
return curSession;
Modified: jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/command/FtpCommandImpl.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/command/FtpCommandImpl.java 2010-11-02 15:51:38 UTC (rev 3381)
+++ jcr/branches/1.12.x/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/command/FtpCommandImpl.java 2010-11-03 08:03:25 UTC (rev 3382)
@@ -111,6 +111,10 @@
{
if (newPath.size() == 0)
{
+ if (clientSession().getFtpServer().getRepository() == null)
+ {
+ throw new RepositoryException("Repository can not be retrieved.");
+ }
String[] workspaces = clientSession().getFtpServer().getRepository().getWorkspaceNames();
for (int i = 0; i < workspaces.length; i++)
{
13 years, 7 months
exo-jcr SVN: r3381 - in jcr/branches/1.12.x/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/impl/core and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-11-02 11:51:38 -0400 (Tue, 02 Nov 2010)
New Revision: 3381
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java
Log:
JCR-1469: JCR clustering consumes lot of native threads
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2010-11-02 14:29:13 UTC (rev 3380)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2010-11-02 15:51:38 UTC (rev 3381)
@@ -58,13 +58,19 @@
public static final String JGROUPS_MUX_ENABLED = "jgroups-multiplexer-stack";
+ /**
+ * Keep only one instance of the {@link JChannelFactory} to prevent creating several times the
+ * same multiplexer stack
+ */
+ private static final JChannelFactory CHANNEL_FACTORY = new JChannelFactory();
+
private final TemplateConfigurationHelper configurationHelper;
private final TransactionManager transactionManager;
private ConfigurationManager configurationManager;
- private final Log log = ExoLogger.getLogger("exo.jcr.component.core.ExoJBossCacheFactory");
+ private static final Log log = ExoLogger.getLogger("exo.jcr.component.core.ExoJBossCacheFactory");
/**
* Creates ExoJbossCacheFactory with provided configuration transaction managers.
@@ -143,16 +149,14 @@
if (jgroupsConfigurationFilePath != null)
{
// Create and inject multiplexer factory
- JChannelFactory muxFactory = new JChannelFactory();
- muxFactory.setMultiplexerConfig(configurationManager.getResource(jgroupsConfigurationFilePath));
- cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(muxFactory);
+ CHANNEL_FACTORY.setMultiplexerConfig(configurationManager.getResource(jgroupsConfigurationFilePath));
+ cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(CHANNEL_FACTORY);
log.info("Multiplexer stack successfully enabled for the cache.");
}
}
catch (Exception e)
{
// exception occurred setting mux factory
- e.printStackTrace();
throw new RepositoryConfigurationException("Error setting multiplexer configuration.", e);
}
}
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java 2010-11-02 14:29:13 UTC (rev 3380)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java 2010-11-02 15:51:38 UTC (rev 3381)
@@ -16,6 +16,17 @@
*/
package org.exoplatform.services.jcr.impl.core;
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.config.CacheEntry;
+import org.exoplatform.services.jcr.config.ContainerEntry;
+import org.exoplatform.services.jcr.config.LockManagerEntry;
+import org.exoplatform.services.jcr.config.LockPersisterEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.config.WorkspaceInitializerEntry;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
@@ -25,14 +36,6 @@
import javax.jcr.Node;
import javax.jcr.NodeIterator;
-import org.exoplatform.services.jcr.JcrImplBaseTest;
-import org.exoplatform.services.jcr.config.ContainerEntry;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
-import org.exoplatform.services.jcr.config.SimpleParameterEntry;
-import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.config.WorkspaceInitializerEntry;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-
/**
* Created by The eXo Platform SAS.
*
@@ -196,9 +199,34 @@
ws1back.setAccessManager(ws1e.getAccessManager());
ws1back.setAutoInitializedRootNt(ws1e.getAutoInitializedRootNt());
ws1back.setAutoInitPermissions(ws1e.getAutoInitPermissions());
- ws1back.setCache(ws1e.getCache());
+
+ CacheEntry cacheConfig = new CacheEntry(new ArrayList(ws1e.getCache().getParameters()));
+ if (cacheConfig.getParameterValue("jbosscache-cluster-name", null) != null)
+ {
+ // Ensure that the cluster name is unique
+ cacheConfig.putParameterValue("jbosscache-cluster-name", "JCR-cluster-" + ws1back.getUniqueName());
+ }
+ cacheConfig.setEnabled(ws1e.getCache().getEnabled());
+ cacheConfig.setType(ws1e.getCache().getType());
+ ws1back.setCache(cacheConfig);
ws1back.setContainer(ws1e.getContainer());
- ws1back.setLockManager(ws1e.getLockManager());
+ LockManagerEntry lockManagerConfig = new LockManagerEntry();
+ lockManagerConfig.setParameters(new ArrayList(ws1e.getLockManager().getParameters()));
+ if (lockManagerConfig.getParameterValue("jbosscache-cluster-name", null) != null)
+ {
+ // Ensure that the cluster name is unique
+ lockManagerConfig.putParameterValue("jbosscache-cluster-name", "JCR-cluster-locks-" + ws1back.getUniqueName());
+ }
+ lockManagerConfig.setType(ws1e.getLockManager().getType());
+ lockManagerConfig.setTimeout(ws1e.getLockManager().getTimeout());
+ if (ws1e.getLockManager().getPersister() != null)
+ {
+ LockPersisterEntry LockPersisterConfig = new LockPersisterEntry();
+ LockPersisterConfig.setParameters(new ArrayList(ws1e.getLockManager().getPersister().getParameters()));
+ LockPersisterConfig.setType(ws1e.getLockManager().getPersister().getType());
+ lockManagerConfig.setPersister(LockPersisterConfig);
+ }
+ ws1back.setLockManager(lockManagerConfig);
// Initializer
WorkspaceInitializerEntry wiEntry = new WorkspaceInitializerEntry();
13 years, 7 months
exo-jcr SVN: r3380 - in jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules: ws and 1 other directory.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-11-02 10:29:13 -0400 (Tue, 02 Nov 2010)
New Revision: 3380
Added:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws/overwrite-default-providers.xml
Modified:
jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws.xml
Log:
EXOJCR-1024 : add docbook with feature description
Added: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws/overwrite-default-providers.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws/overwrite-default-providers.xml (rev 0)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws/overwrite-default-providers.xml 2010-11-02 14:29:13 UTC (rev 3380)
@@ -0,0 +1,213 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<chapter id="WS.OverwriteDefaultProviders">
+ <?dbhtml filename="overwrite-default-providers.html"?>
+
+ <title>OverwriteDefaultProviders</title>
+
+ <section>
+ <title>Motivation</title>
+
+ <para>There is set of providers embedded in eXo JAX-RS
+ implementation.</para>
+
+ <para>Implementations of MessageBodyReader and MessageBodyWriters are
+ taking care about serialization/deserialization of message body (HTTP
+ request/response's body).</para>
+
+ <para>The next set of media and Java types processed automatically, thanks
+ to embedded Readers (Writers).</para>
+
+ <table>
+ <title>Embedded Reader and Writers of message body</title>
+
+ <tgroup cols="2">
+ <colspec align="center" />
+
+ <thead>
+ <row>
+ <entry align="center">Media Type</entry>
+
+ <entry align="center">Java Type</entry>
+ </row>
+ </thead>
+
+ <tbody>
+ <row>
+ <entry>*/*</entry>
+
+ <entry>byte[]</entry>
+ </row>
+
+ <row>
+ <entry>*/*</entry>
+
+ <entry>javax.activation.DataSource</entry>
+ </row>
+
+ <row>
+ <entry>*/*</entry>
+
+ <entry>java.io.File</entry>
+ </row>
+
+ <row>
+ <entry>*/*</entry>
+
+ <entry>java.io.InputStream</entry>
+ </row>
+
+ <row>
+ <entry>*/*</entry>
+
+ <entry>java.io.Reader</entry>
+ </row>
+
+ <row>
+ <entry>*/*</entry>
+
+ <entry>java.lang.String</entry>
+ </row>
+
+ <row>
+ <entry>*/*</entry>
+
+ <entry>javax.ws.rs.core.StreamingOutput (Writer ONLY)</entry>
+ </row>
+
+ <row>
+ <entry>application/json</entry>
+
+ <entry>1. Object with simple constructor + get/set methods; 2.
+ Java Collection (java.uitl.List<T>, java.uitl.Set<T>,
+ java.util.Map<String, T>, etc) where T as described in
+ 1.</entry>
+ </row>
+
+ <row>
+ <entry>application/x-www-form-urlencoded</entry>
+
+ <entry>javax.ws.rs.core.MultivaluedMap<String,
+ String></entry>
+ </row>
+
+ <row>
+ <entry>multipart/*</entry>
+
+ <entry>java.util.Iterator<org.apache.commons.fileupload.FileItem></entry>
+ </row>
+
+ <row>
+ <entry>application/xml, application/xhtml+xml, text/xml</entry>
+
+ <entry>javax.xml.bind.JAXBElement</entry>
+ </row>
+
+ <row>
+ <entry>application/xml, application/xhtml+xml, text/xml</entry>
+
+ <entry>Object with JAXB annotations</entry>
+ </row>
+
+ <row>
+ <entry>application/xml, application/xhtml+xml, text/xml</entry>
+
+ <entry>javax.xml.transform.stream.StreamSource</entry>
+ </row>
+
+ <row>
+ <entry>application/xml, application/xhtml+xml, text/xml</entry>
+
+ <entry>javax.xml.transform.sax.SAXSource</entry>
+ </row>
+
+ <row>
+ <entry>application/xml, application/xhtml+xml, text/xml</entry>
+
+ <entry>javax.xml.transform.dom.DOMSource</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <para>In some case it may be required to use alternative provider for the
+ same media and java type but such changes must not impact to any other
+ services.</para>
+ </section>
+
+ <section>
+ <title>Usage</title>
+
+ <para>To be able overwrite default JAX-RS provider(s) developer
+ need:</para>
+
+ <orderedlist>
+ <listitem>
+ <para>Deploy own RESTful service(s) by using subclass of
+ javax.ws.rs.core.Application (hereinafter Application).</para>
+ </listitem>
+
+ <listitem>
+ <para>Service(s) NOT NEED to implement marker interface
+ ResourceContainer and MUST NOT be configured as component(s) of eXo
+ Container. Instead of it Application must be configured as component
+ of eXo Container.</para>
+ </listitem>
+
+ <listitem>
+ <para>If RESTful services or providers require some dependencies from
+ eXo Container then Application should inject it by own constructor and
+ then delegate to services or providers. As alternative method
+ getClasses() may be used for deliver services/providers classes
+ instead of instances. In this case services/providers will work in
+ per-request mode and RESTful framework will take care about resolving
+ dependencies.</para>
+ </listitem>
+ </orderedlist>
+ </section>
+
+ <section>
+ <title>Example</title>
+
+ <para>In example below see how to use Jackson JSON provider instead of
+ embedded in eXo RESTful framework.</para>
+
+ <para>Create subclass of javax.ws.rs.core.Application with code as bellow
+ and add it to the eXo Container configuration.</para>
+
+ <programlisting>package org.exoplatform.test.jackson;
+
+import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class Application1 extends Application
+{
+ @Override
+ public Set<Class<?>> getClasses()
+ {
+ Set<Class<?>> cls = new HashSet<Class<?>>(1);
+ cls.add(Resource1.class);
+ return cls;
+ }
+
+ @Override
+ public Set<Object> getSingletons()
+ {
+ Set<Object> objs = new HashSet<Object>(1);
+ objs.add(new JacksonJaxbJsonProvider());
+ return objs;
+ }
+}</programlisting>
+
+ <para>In this example we assumes Resource1 is Java class which carries
+ JAX-RS annotations and it uses JSON. In this case RESTful framework will
+ use JacksonJaxbJsonProvider for serializing/deserializing of all messages
+ to/from Resource1. But it will not impact to other services in any kind.
+ </para>
+ </section>
+</chapter>
Modified: jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws.xml
===================================================================
--- jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws.xml 2010-11-02 13:47:09 UTC (rev 3379)
+++ jcr/trunk/exo.jcr.docs/exo.jcr.docs.developer/en/src/main/docbook/en-US/modules/ws.xml 2010-11-02 14:29:13 UTC (rev 3380)
@@ -12,6 +12,9 @@
<xi:include href="ws/introduction-to-rest.xml"
xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="ws/overwrite-default-providers.xml"
+ xmlns:xi="http://www.w3.org/2001/XInclude" />
+
<xi:include href="ws/restservicelist-service.xml"
xmlns:xi="http://www.w3.org/2001/XInclude" />
13 years, 7 months
exo-jcr SVN: r3379 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-11-02 09:47:09 -0400 (Tue, 02 Nov 2010)
New Revision: 3379
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-1029: Storing result of the method getReferencesData into the cache
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-11-02 11:13:27 UTC (rev 3378)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2010-11-02 13:47:09 UTC (rev 3379)
@@ -684,11 +684,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));
}
/**
@@ -861,13 +861,16 @@
private final Serializable key;
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
@@ -879,7 +882,7 @@
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 (existingObject instanceof Set || (existingObject == null && forceModify))
{
// set found
if (existingObject instanceof Set)
@@ -896,7 +899,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/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-11-02 11:13:27 UTC (rev 3378)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-02 13:47:09 UTC (rev 3379)
@@ -1025,13 +1025,11 @@
// add in CHILD_NODES
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());
+ cache.addToList(makeChildListFqn(childNodesList, node.getParentIdentifier()), ITEM_LIST,
+ node.getIdentifier(), modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
}
@@ -1082,13 +1080,11 @@
// add in CHILD_NODES
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());
+ cache.addToList(makeChildListFqn(childNodesList, node.getParentIdentifier()), ITEM_LIST,
+ node.getIdentifier(), modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
}
// add in ITEMS
@@ -1115,18 +1111,17 @@
// add in CHILD_PROPS
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);
}
get(prop.getParentIdentifier(), prop.getQPath().getEntries()[prop.getQPath().getEntries().length - 1]);
// add referenced property
- if (prop.getType() == PropertyType.REFERENCE)
+ if (modifyListsOfChild != ModifyChildOption.NOT_MODIFY && prop.getType() == PropertyType.REFERENCE)
{
for (ValueData vdata : prop.getValues())
{
@@ -1144,13 +1139,8 @@
// Do nothing. Never happens.
}
- Fqn refFqn = makeRefFqn(nodeIdentifier);
- Set<String> set = (Set<String>)cache.get(refFqn, ITEM_LIST);
- if (set != null)
- {
- set.add(prop.getIdentifier());
- cache.addToList(refFqn, ITEM_LIST, prop.getIdentifier());
- }
+ cache.addToList(makeRefFqn(nodeIdentifier), ITEM_LIST, prop.getIdentifier(),
+ modifyListsOfChild == ModifyChildOption.FORCE_MODIFY);
}
}
@@ -1198,22 +1188,6 @@
// remove from CHILD_PROPS_LIST
cache.removeFromList(makeChildListFqn(childPropsList, item.getParentIdentifier()), ITEM_LIST, item
.getIdentifier());
-
- // remove referenced property
- PropertyData prop = (PropertyData)item;
- if (prop.getType() == PropertyType.REFERENCE)
- {
- // value data is empty on delete, so will try to remove from all lists
- for (Object child : cache.getChildrenNames(refRoot))
- {
- Fqn refFqn = makeRefFqn((String)child);
- Set<String> set = (Set<String>)cache.get(refFqn, ITEM_LIST);
- if (set != null && set.contains(prop.getIdentifier()))
- {
- cache.removeFromList(refFqn, ITEM_LIST, prop.getIdentifier());
- }
- }
- }
}
// remove from ITEMS
cache.removeNode(makeItemFqn(item.getIdentifier()));
13 years, 7 months
exo-jcr SVN: r3378 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-11-02 07:13:27 -0400 (Tue, 02 Nov 2010)
New Revision: 3378
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
Log:
EXOJCR-1029: Storing result of the method getReferencesData into the cache
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-11-02 09:39:26 UTC (rev 3377)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-11-02 11:13:27 UTC (rev 3378)
@@ -35,6 +35,7 @@
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;
@@ -469,7 +470,6 @@
}
}
-
/**
* {@inheritDoc}
*/
@@ -530,14 +530,19 @@
if (skipVersionStorage)
{
+ List<PropertyData> result = new ArrayList<PropertyData>();
+
Iterator<PropertyData> iterator = props.iterator();
while (iterator.hasNext())
{
- if (iterator.next().getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
+ PropertyData prop = iterator.next();
+ if (!prop.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
{
- iterator.remove();
+ result.add(prop);
}
}
+
+ return result;
}
return props;
@@ -672,11 +677,10 @@
* @throws RepositoryException
* Repository error
*/
- protected List<PropertyData> getReferencedPropertiesData(String identifier)
- throws RepositoryException
+ protected List<PropertyData> getReferencedPropertiesData(String identifier) throws RepositoryException
{
List<PropertyData> refProps = null;
- if (!cache.isEnabled())
+ if (cache.isEnabled())
{
refProps = cache.getReferencedProperties(identifier);
if (refProps != null)
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-11-02 09:39:26 UTC (rev 3377)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-02 11:13:27 UTC (rev 3378)
@@ -761,7 +761,7 @@
{
try
{
- if (new String(vdata.getAsByteArray()).equals(identifier))
+ if (new String(vdata.getAsByteArray(), Constants.DEFAULT_ENCODING).equals(identifier))
{
props.add(prop);
}
@@ -1133,7 +1133,7 @@
String nodeIdentifier = null;
try
{
- nodeIdentifier = new String(vdata.getAsByteArray());
+ nodeIdentifier = new String(vdata.getAsByteArray(), Constants.DEFAULT_ENCODING);
}
catch (IllegalStateException e)
{
@@ -1149,7 +1149,7 @@
if (set != null)
{
set.add(prop.getIdentifier());
- cache.put(refFqn, ITEM_LIST, set);
+ cache.addToList(refFqn, ITEM_LIST, prop.getIdentifier());
}
}
}
@@ -1210,8 +1210,7 @@
Set<String> set = (Set<String>)cache.get(refFqn, ITEM_LIST);
if (set != null && set.contains(prop.getIdentifier()))
{
- set.remove(prop.getIdentifier());
- cache.put(refFqn, ITEM_LIST, set);
+ cache.removeFromList(refFqn, ITEM_LIST, prop.getIdentifier());
}
}
}
13 years, 7 months
exo-jcr SVN: r3377 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/persistent and 2 other directories.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-11-02 05:39:26 -0400 (Tue, 02 Nov 2010)
New Revision: 3377
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
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/LinkedWorkspaceStorageCacheImpl.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-1029: Storing result of the method getReferencesData into the cache
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-02 08:59:39 UTC (rev 3376)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/dataflow/persistent/WorkspaceStorageCache.java 2010-11-02 09:39:26 UTC (rev 3377)
@@ -108,6 +108,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.
*
* @param item
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-11-02 08:59:39 UTC (rev 3376)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/CacheableWorkspaceDataManager.java 2010-11-02 09:39:26 UTC (rev 3377)
@@ -18,14 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent;
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CountDownLatch;
-
-import javax.jcr.RepositoryException;
-import javax.transaction.TransactionManager;
-
import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
import org.exoplatform.services.jcr.dataflow.persistent.MandatoryItemsPersistenceListener;
import org.exoplatform.services.jcr.dataflow.persistent.WorkspaceStorageCache;
@@ -36,12 +28,22 @@
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.Iterator;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CountDownLatch;
+
+import javax.jcr.RepositoryException;
+import javax.transaction.TransactionManager;
+
/**
* Created by The eXo Platform SAS.
*
@@ -73,7 +75,6 @@
protected class DataRequest
{
/**
- /**
* GET_NODES type.
*/
static public final int GET_NODES = 1;
@@ -99,6 +100,11 @@
static private final int GET_LIST_PROPERTIES = 5;
/**
+ * GET_REFERENCES type.
+ */
+ static public final int GET_REFERENCES = 6;
+
+ /**
* Request type.
*/
protected final int type;
@@ -520,7 +526,21 @@
public List<PropertyData> getReferencesData(String identifier, boolean skipVersionStorage)
throws RepositoryException
{
- return super.getReferencesData(identifier, skipVersionStorage);
+ List<PropertyData> props = getReferencedPropertiesData(identifier);
+
+ if (skipVersionStorage)
+ {
+ Iterator<PropertyData> iterator = props.iterator();
+ while (iterator.hasNext())
+ {
+ if (iterator.next().getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
+ {
+ iterator.remove();
+ }
+ }
+ }
+
+ return props;
}
/**
@@ -644,6 +664,55 @@
}
/**
+ * 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 child PropertyData.
*
* @param nodeData
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-11-02 08:59:39 UTC (rev 3376)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/LinkedWorkspaceStorageCacheImpl.java 2010-11-02 09:39:26 UTC (rev 3377)
@@ -1648,6 +1648,21 @@
/**
* {@inheritDoc}
*/
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public List<PropertyData> listChildProperties(final NodeData parentData)
{
if (enabled && parentData != null)
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-11-02 08:59:39 UTC (rev 3376)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-11-02 09:39:26 UTC (rev 3377)
@@ -18,19 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
-import java.io.Serializable;
-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.NoSuchElementException;
-import java.util.Set;
-
-import javax.jcr.RepositoryException;
-import javax.transaction.TransactionManager;
-
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
@@ -47,6 +34,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;
@@ -61,6 +49,21 @@
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;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.transaction.TransactionManager;
+
/**
* Created by The eXo Platform SAS.<p/>
*
@@ -127,6 +130,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();
@@ -137,6 +142,8 @@
protected final Fqn<String> itemsRoot;
+ protected final Fqn<String> refRoot;
+
protected final Fqn<String> nullItemsRoot;
protected final Fqn<String> childNodes;
@@ -336,6 +343,7 @@
JBOSSCACHE_EXPIRATION_DEFAULT));
this.itemsRoot = Fqn.fromRelativeElements(rootFqn, ITEMS);
+ this.refRoot = Fqn.fromRelativeElements(rootFqn, REFERENCE);
this.nullItemsRoot = Fqn.fromRelativeElements(rootFqn, NULL_ITEMS);
this.childNodes = Fqn.fromRelativeElements(rootFqn, CHILD_NODES);
this.childProps = Fqn.fromRelativeElements(rootFqn, CHILD_PROPS);
@@ -346,6 +354,7 @@
this.cache.start();
createResidentNode(childNodes);
+ createResidentNode(refRoot);
createResidentNode(childNodesList);
createResidentNode(childProps);
createResidentNode(childPropsList);
@@ -729,6 +738,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()).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();
+ }
+ }
+ }
+
+ /**
* Internal get child properties.
*
* @param parentId String
@@ -771,7 +863,7 @@
public long getSize()
{
// Total number of JBC nodes in the cache - the total amount of resident nodes
- return numNodes(cache.getNode(rootFqn)) - 6;
+ return numNodes(cache.getNode(rootFqn)) - 7;
}
/**
@@ -812,6 +904,17 @@
}
/**
+ * 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 Item absolute Fqn, i.e. /$NULL_ITEMS/itemID.
*
* @param itemId String
@@ -1022,6 +1125,35 @@
get(prop.getParentIdentifier(), prop.getQPath().getEntries()[prop.getQPath().getEntries().length - 1]);
+ // add referenced property
+ if (prop.getType() == PropertyType.REFERENCE)
+ {
+ for (ValueData vdata : prop.getValues())
+ {
+ String nodeIdentifier = null;
+ try
+ {
+ nodeIdentifier = new String(vdata.getAsByteArray());
+ }
+ catch (IllegalStateException e)
+ {
+ // Do nothing. Never happens.
+ }
+ catch (IOException e)
+ {
+ // Do nothing. Never happens.
+ }
+
+ Fqn refFqn = makeRefFqn(nodeIdentifier);
+ Set<String> set = (Set<String>)cache.get(refFqn, ITEM_LIST);
+ if (set != null)
+ {
+ set.add(prop.getIdentifier());
+ cache.put(refFqn, ITEM_LIST, set);
+ }
+ }
+ }
+
// add in ITEMS
return (PropertyData)cache.put(makeItemFqn(prop.getIdentifier()), ITEM_DATA, prop);
}
@@ -1054,6 +1186,8 @@
// remove from CHILD_PROPS_LIST as parent
cache.removeNode(makeChildListFqn(childPropsList, item.getIdentifier()));
}
+
+ cache.removeNode(makeRefFqn(item.getIdentifier()));
}
else
{
@@ -1064,6 +1198,23 @@
// remove from CHILD_PROPS_LIST
cache.removeFromList(makeChildListFqn(childPropsList, item.getParentIdentifier()), ITEM_LIST, item
.getIdentifier());
+
+ // remove referenced property
+ PropertyData prop = (PropertyData)item;
+ if (prop.getType() == PropertyType.REFERENCE)
+ {
+ // value data is empty on delete, so will try to remove from all lists
+ for (Object child : cache.getChildrenNames(refRoot))
+ {
+ Fqn refFqn = makeRefFqn((String)child);
+ Set<String> set = (Set<String>)cache.get(refFqn, ITEM_LIST);
+ if (set != null && set.contains(prop.getIdentifier()))
+ {
+ set.remove(prop.getIdentifier());
+ cache.put(refFqn, ITEM_LIST, set);
+ }
+ }
+ }
}
// remove from ITEMS
cache.removeNode(makeItemFqn(item.getIdentifier()));
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-11-02 08:59:39 UTC (rev 3376)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCacheableWorkspaceDataManager.java 2010-11-02 09:39:26 UTC (rev 3377)
@@ -25,7 +25,6 @@
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.ItemType;
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;
@@ -387,6 +386,15 @@
return childNodes != null ? childNodes.size() : -1;
}
+ public List<PropertyData> getReferencedProperties(String identifier)
+ {
+ return null;
+ }
+
+ public void addReferencedProperties(String identifier, List<PropertyData> refProperties)
+ {
+ }
+
}
private static class MyWorkspaceStorageConnection implements WorkspaceStorageConnection
13 years, 7 months