exo-jcr SVN: r788 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2009-11-20 07:27:00 -0500 (Fri, 20 Nov 2009)
New Revision: 788
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
Log:
EXOJCR-246: reference delete property fixed
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-20 11:36:15 UTC (rev 787)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-20 12:27:00 UTC (rev 788)
@@ -18,14 +18,12 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.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.core.lock.LockData;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.ValueDataConvertor;
@@ -197,7 +195,7 @@
if (data.getType() == PropertyType.REFERENCE)
{
- Fqn propUUID = makeNodeFqn(data.getIdentifier());
+ Fqn propIdentifier = Fqn.fromElements(data.getIdentifier());
for (ValueData value : data.getValues())
{
@@ -227,7 +225,7 @@
refParent = refsRoot.addChild(refNode);
}
- refParent.addChild(propUUID);
+ refParent.addChild(propIdentifier);
}
}
@@ -256,22 +254,25 @@
{
startBatch();
- for (InternalQName mixin : data.getMixinTypeNames())
- {
- if (mixin.equals(Constants.MIX_REFERENCEABLE))
- {
- // check and release references
- Node<Serializable, Object> node = refsRoot.addChild(Fqn.fromElements(data.getIdentifier()));
- if (node != null)
- {
- if (node.getChildrenNames().size() != 0)
- {
- throw new RepositoryException("Referenceable node removed but still have live references.");
- }
- }
- break;
- }
- }
+ // TODO remove this check
+ // for (InternalQName mixin : data.getMixinTypeNames())
+ // {
+ //
+ //
+ // if (mixin.equals(Constants.MIX_REFERENCEABLE))
+ // {
+ // // check and release references
+ // Node<Serializable, Object> node = refsRoot.addChild(Fqn.fromElements(data.getIdentifier()));
+ // if (node != null)
+ // {
+ // if (node.getChildrenNames().size() != 0)
+ // {
+ // throw new RepositoryException("Referenceable node removed but still have live references.");
+ // }
+ // }
+ // break;
+ // }
+ // }
if (data.getParentIdentifier() != null)
{
@@ -312,11 +313,20 @@
if (data.getType() == PropertyType.REFERENCE)
{
+ // get values from cahce
+
Fqn propUUID = makeNodeFqn(data.getIdentifier());
- for (ValueData value : data.getValues())
+ Node<Serializable, Object> prop = propsRoot.getChild(propUUID);
+ PropertyData oldData = (PropertyData)prop.get(ITEM_DATA);
+ if (oldData == null)
{
+ throw new RepositoryException("FATAL PropertyData already empty " + data.getQPath().getAsString());
+ }
+ for (ValueData value : oldData.getValues())
+ {
+
String refNodeUUID;
try
{
16 years, 8 months
exo-jcr SVN: r787 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-11-20 06:36:15 -0500 (Fri, 20 Nov 2009)
New Revision: 787
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockImpl.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
Log:
EXOJCR-243: small fix related to refresh() and getLockToken()
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2009-11-20 11:17:03 UTC (rev 786)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2009-11-20 11:36:15 UTC (rev 787)
@@ -121,11 +121,6 @@
return false;
}
- public String getTokenHash()
- {
- return tokenHash;
- }
-
/**
* @return the nodeIdentifier
*/
@@ -150,6 +145,11 @@
return birthday + timeOut - System.currentTimeMillis() / 1000;
}
+ public String getTokenHash()
+ {
+ return tokenHash;
+ }
+
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
@@ -174,14 +174,6 @@
}
/**
- * @return
- */
- protected long getTimeOut()
- {
- return timeOut;
- }
-
- /**
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
@@ -235,4 +227,12 @@
}
+ /**
+ * @return
+ */
+ protected long getTimeOut()
+ {
+ return timeOut;
+ }
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockImpl.java 2009-11-20 11:17:03 UTC (rev 786)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockImpl.java 2009-11-20 11:36:15 UTC (rev 787)
@@ -21,6 +21,7 @@
import org.exoplatform.services.jcr.core.lock.ExtendedLock;
import org.exoplatform.services.jcr.dataflow.ItemState;
import org.exoplatform.services.jcr.dataflow.LockPlainChangesLogImpl;
+import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
@@ -45,8 +46,7 @@
private SessionDataManager sessionDataManager;
- // Token is not stored in lockData any more
- private String token;
+ private SessionLockManager lockManager;
private String sessionId;
@@ -54,11 +54,12 @@
* @param session
* @param lockData
*/
- public LockImpl(SessionDataManager sessionDataManager, LockData lockData, String token, String sessionId)
+ public LockImpl(SessionLockManager lockManager, SessionDataManager sessionDataManager, LockData lockData,
+ String sessionId)
{
this.lockData = lockData;
this.sessionDataManager = sessionDataManager;
- this.token = token;
+ this.lockManager = lockManager;
this.live = true;
this.sessionId = sessionId;
}
@@ -76,7 +77,7 @@
*/
public String getLockToken()
{
- return token;
+ return lockManager.getLockToken(lockData);
}
/**
@@ -127,7 +128,9 @@
new LockData(lockData.getNodeIdentifier(), lockData.getTokenHash(), lockData.isDeep(), lockData
.isSessionScoped(), lockData.getOwner(), lockData.getTimeOut());
addChangesLog.setLockData(newLockData);
- sessionDataManager.getWorkspaceDataManager().save(addChangesLog);
+ TransactionChangesLog log = new TransactionChangesLog();
+ log.addLog(addChangesLog);
+ sessionDataManager.getWorkspaceDataManager().save(log);
this.lockData = newLockData;
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java 2009-11-20 11:17:03 UTC (rev 786)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java 2009-11-20 11:36:15 UTC (rev 787)
@@ -38,7 +38,7 @@
import javax.jcr.RepositoryException;
/**
- * This is a persistent lock manager, that currently is responsible for removing expired locks
+ * This is a persistent lock manager (workspace-layer), that currently is responsible for removing expired locks
*
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id$
@@ -89,6 +89,7 @@
protected void removeExpired()
{
List<LockData> lockDatas;
+ // try to acquire list of locks
try
{
lockDatas = dataManager.getLocksData();
@@ -99,7 +100,7 @@
log.error(e.getMessage(), e);
return;
}
-
+ // if acquired, try to remove each expired
if (lockDatas != null)
{
for (LockData lockData : lockDatas)
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2009-11-20 11:17:03 UTC (rev 786)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2009-11-20 11:36:15 UTC (rev 787)
@@ -52,6 +52,8 @@
import javax.jcr.lock.LockException;
/**
+ * Session-layer lock manager.
+ *
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id$
*
@@ -121,7 +123,7 @@
}
else
lockTimeOut = DEFAULT_LOCK_TIMEOUT;
- this.tokens = new HashMap<String, String>();
+ this.tokens = new HashMap<String, String>();
this.tokenHash = new HashMap<String, String>();
}
@@ -137,17 +139,6 @@
}
/**
- * Removes token from current session
- * @param token
- */
- public void removeLockToken(String token)
- {
- String hash = getHash(token);
- tokens.remove(token);
- tokenHash.remove(hash);
- }
-
- /**
* Tries to get Lock for node. Is node is not a lockholder, then parent with deep lock is looked for.
*
* @param node
@@ -164,7 +155,7 @@
throw new LockException("Node not locked: " + node.getQPath());
}
// if session doesn't have token, null will be returned
- return new LockImpl(sessionDataManager, lockData, tokenHash.get(lockData.getTokenHash()), sessionID);
+ return new LockImpl(this, sessionDataManager, lockData, sessionID);
}
/**
@@ -177,28 +168,26 @@
}
/**
- * Checks if node actually has a lock.
+ * Returns real token, if session has it
*
- * @param node
+ * @param lockData
* @return
- * @throws RepositoryException
*/
- public boolean holdsLock(NodeData node) throws RepositoryException
+ public String getLockToken(LockData lockData)
{
- return getLockData(node, SEARCH_EXACMATCH) != null;
+ return tokenHash.get(lockData.getTokenHash());
}
/**
- * Checks if current session has a token (access) for this node.
+ * Checks if node actually has a lock.
*
* @param node
* @return
* @throws RepositoryException
*/
- public boolean isLockHolder(NodeData node) throws RepositoryException
+ public boolean holdsLock(NodeData node) throws RepositoryException
{
- LockData lockData = getLockData(node, SEARCH_EXACMATCH | SEARCH_PARENT);
- return lockData != null && isLockHolder(lockData);
+ return getLockData(node, SEARCH_EXACMATCH) != null;
}
/**
@@ -219,6 +208,19 @@
}
/**
+ * Checks if current session has a token (access) for this node.
+ *
+ * @param node
+ * @return
+ * @throws RepositoryException
+ */
+ public boolean isLockHolder(NodeData node) throws RepositoryException
+ {
+ LockData lockData = getLockData(node, SEARCH_EXACMATCH | SEARCH_PARENT);
+ return lockData != null && isLockHolder(lockData);
+ }
+
+ /**
* Actually locks the node, adding jcr:lockOwner and jcr:lockIsDeep properties to node and adds lock token
* to current session.
*
@@ -264,13 +266,71 @@
new TransientValueData(isDeep));
changesLog.add(ItemState.createAddedState(propData));
- LockImpl newLock = new LockImpl(sessionDataManager, lockData, token, sessionID);
+ LockImpl newLock = new LockImpl(this, sessionDataManager, lockData, sessionID);
sessionDataManager.getTransactManager().save(changesLog);
return newLock;
}
/**
+ * @see org.exoplatform.services.jcr.core.SessionLifecycleListener#onCloseSession(org.exoplatform.services.jcr.core.ExtendedSession)
+ */
+ public void onCloseSession(ExtendedSession session)
+ {
+ // the logic as it was before, if session holds token for lock, and lock is open scoped - remove it.
+ List<LockData> lockDatas;
+ try
+ {
+ lockDatas = sessionDataManager.getLocksData();
+ }
+ catch (RepositoryException e)
+ {
+ // exception getting list of locks, return.
+ log.error(e.getMessage(), e);
+ return;
+ }
+ // list acquired, traversing to cleanup locks;
+ if (lockDatas != null)
+ {
+ for (LockData lockData : lockDatas)
+ {
+ if (lockData.isSessionScoped() && isLockHolder(lockData))
+ {
+ NodeData node;
+ // if can't unlock this, still try to unlock the next one
+ try
+ {
+ node = (NodeData)sessionDataManager.getItemData(lockData.getNodeIdentifier());
+ if (node != null)
+ {
+ unlock(node);
+ }
+ else
+ {
+ log.error("Node with uuid=" + lockData.getNodeIdentifier() + " is null!");
+ }
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Can't unlock node on session logout, id:" + lockData.getNodeIdentifier(), e);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes token from current session
+ * @param token
+ */
+ public void removeLockToken(String token)
+ {
+ String hash = getHash(token);
+ tokens.remove(token);
+ tokenHash.remove(hash);
+ }
+
+ /**
* Actually unlock the node also removing jcr:lockOwner and jcr:lockIsDeep properties
*
* @param node
@@ -389,44 +449,4 @@
return (SystemIdentity.SYSTEM.equals(sessionID) || tokenHash.get(lockData.getTokenHash()) != null);
}
- /**
- * @see org.exoplatform.services.jcr.core.SessionLifecycleListener#onCloseSession(org.exoplatform.services.jcr.core.ExtendedSession)
- */
- public void onCloseSession(ExtendedSession session)
- {
- // the logic as it was before, if session holds token for lock, and lock is open scoped - remove it.
- List<LockData> lockDatas;
- try
- {
- lockDatas = sessionDataManager.getLocksData();
- }
- catch (RepositoryException e)
- {
- // exception getting list of locks, return.
- log.error(e.getMessage(), e);
- return;
- }
- // list acquired, traversing to cleanup locks;
- if (lockDatas != null)
- {
- for (LockData lockData : lockDatas)
- {
- if (lockData.isSessionScoped() && isLockHolder(lockData))
- {
- NodeData node;
- // if can't unlock this, still try to unlock the next one
- try
- {
- node = (NodeData)sessionDataManager.getItemData(lockData.getNodeIdentifier());
- unlock(node);
- }
- catch (RepositoryException e)
- {
- log.error("Can't unlock node on session logout, id:" + lockData.getNodeIdentifier(), e);
- }
- }
- }
- }
- }
-
}
16 years, 8 months
exo-jcr SVN: r786 - in jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-20 06:17:03 -0500 (Fri, 20 Nov 2009)
New Revision: 786
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheRestartTest.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
Log:
EXOJCR-203 : The test JBossCacheRestartTest was added.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java 2009-11-20 09:50:37 UTC (rev 785)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java 2009-11-20 11:17:03 UTC (rev 786)
@@ -215,6 +215,9 @@
mixins.add(Constants.EXO_PRIVILEGEABLE);
mixins.add(Constants.EXO_OWNEABLE);
addDbProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_MIXINTYPES, mixins, true);
+
+ // add property exo:owner
+ addDbProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.EXO_OWNER, "admin", false);
conn.commit();
}
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheRestartTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheRestartTest.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheRestartTest.java 2009-11-20 11:17:03 UTC (rev 786)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import java.io.Serializable;
+
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+public class JBossCacheRestartTest
+ extends AbstractJBossCacheStorageConnectionTest
+{
+ protected String getDataSourceName()
+ {
+ return "jdbc_name";
+ }
+
+ public void testAddNode() throws Exception
+ {
+ // add root (/)
+ initJCRRoot();
+
+ // check before stop
+ Node<Serializable, Object> rNode = cache.getRoot().getChild(Fqn.fromElements(JBossCacheStorage.NODES, Constants.ROOT_UUID));
+ assertNotNull("Node expected", rNode);
+ checkNode(rNode, Constants.ROOT_UUID, Constants.ROOT_PATH);
+
+ // stop cache
+ cache.stop();
+ cache.destroy();
+
+ // start cache
+ super.setUp();
+
+ // check after restart
+ rNode = cache.getRoot().getChild(Fqn.fromElements(JBossCacheStorage.NODES, Constants.ROOT_UUID));
+ assertNotNull("Node expected", rNode);
+ checkNode(rNode, Constants.ROOT_UUID, Constants.ROOT_PATH);
+ }
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheRestartTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
16 years, 8 months
exo-jcr SVN: r785 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-20 04:50:37 -0500 (Fri, 20 Nov 2009)
New Revision: 785
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
Log:
EXOJCR-203: Node.move re-view & commented the impl, TODO on the problem of cache reload;
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-20 09:48:12 UTC (rev 784)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-20 09:50:37 UTC (rev 785)
@@ -49,6 +49,8 @@
public static final String ITEM_DATA = "$data".intern();
public static final String ITEM_ID = "$id".intern();
+
+ public static final String INVALID_DATA = "$invalidData".intern();
@Deprecated
public static final String SESSION_ID = "$sessionId".intern();
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-20 09:48:12 UTC (rev 784)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-20 09:50:37 UTC (rev 785)
@@ -93,6 +93,54 @@
this.cache = cache;
}
+ // helpers
+ @Deprecated
+ protected NodeData getNodeData(Node<Serializable, Object> node)
+ {
+ Object data = node.get(ITEM_DATA);
+ if (data != null)
+ {
+ // check if invalid
+ if (data.equals(INVALID_DATA))
+ {
+ // evict to force read from DB
+ cache.evict(node.getFqn(), true);
+ Thread.yield();
+
+ // and ask again
+ Node<Serializable, Object> freshNode = cache.getNode(node.getFqn());
+ if (freshNode != null)
+ {
+ Object freshData = freshNode.get(ITEM_DATA);
+ if (freshData != null)
+ {
+ return (NodeData)freshData;
+ }
+ else
+ {
+ // TODO
+ return null;
+ }
+ }
+ else
+ {
+ // TODO
+ return null;
+ }
+ }
+ else
+ {
+ return (NodeData)data;
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ // Connection API
+
/**
* {@inheritDoc}
*/
@@ -259,7 +307,7 @@
Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
- throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
+ throw new RepositoryException("Property's parent doesn't exist " + data.getQPath().getAsString());
}
if (data.getType() == PropertyType.REFERENCE)
@@ -339,8 +387,8 @@
Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(nodeId));
if (node == null)
{
- throw new RepositoryException("FATAL Node record not found(" + nodeId + "), but listed in proprties of "
- + parent.getQPath().getAsString());
+ throw new RepositoryException("FATAL Node record not found(" + nodeId
+ + "), but listed in child nodes of " + parent.getQPath().getAsString());
}
NodeData nodeData = (NodeData)node.get(ITEM_DATA);
if (nodeData == null)
@@ -548,6 +596,7 @@
}
else
{
+ // TODO move usecase: re-load on demand, try cache.evict(node.getFqn());
throw new RepositoryException("FATAL NodeData empty " + identifier);
}
}
@@ -614,94 +663,88 @@
{
//TODO we expecting that on session.move() there will be only one rename() method call
- startBatch();
-
- String nodeUUID = data.getIdentifier();
-
- //1. Update renamed node and also get old nodeData
- Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(nodeUUID));
- if (node == null)
- {
- throw new RepositoryException("FATAL renamed node is not exist" + data.getQPath().getAsString());
- }
-
- NodeData oldNodeData = (NodeData)node.put(ITEM_DATA, data);
- if (oldNodeData == null)
- {
- throw new RepositoryException("FATAL NodeData is empty " + data.getQPath().getAsString());
- }
-
- // 2. remove renamed node from child list of previous parent node
- // check if parent is cached
- Node<Serializable, Object> oldparent = nodesRoot.getChild(makeNodeFqn(oldNodeData.getParentIdentifier()));
- if (oldparent == null)
- {
- throw new RepositoryException("Nodes old parent doesn't exist " + data.getQPath().getAsString());
- }
-
- // remove node form old parent child list
- boolean removed =
- oldparent
- .removeChild(makeChildNodeFqn(oldNodeData.getQPath().getEntries()[oldNodeData.getQPath().getEntries().length - 1]));
- if (!removed)
- {
- throw new RepositoryException("Node was not removed from child list of old parent "
- + data.getQPath().getAsString());
- }
-
- // 3. add node to child list of new parent node
- if (data.getParentIdentifier() != null)
- {
- // check if parent is cached
- Node<Serializable, Object> newparent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
- if (newparent == null)
- {
- throw new RepositoryException("Nodes new parent doesn't exist " + data.getQPath().getAsString());
- }
-
- // add child to Parent
- Node<Serializable, Object> childNode =
- newparent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
-
- // set child id attr
- childNode.put(ITEM_ID, data.getIdentifier());
- }
-
- // 4. update all child nodes
- Set<Node<Serializable, Object>> childNodes = node.getChildren();
-
- for (Node<Serializable, Object> child : childNodes)
- {
- String childNodeId = (String)child.get(ITEM_ID);
- if (childNodeId == null)
- {
- throw new RepositoryException("FATAL Child Node Id key is null. Parent " + data.getQPath().getAsString());
- }
-
- // TODO NodeData or PropertyData? As ItemData check then and cast.
- Node<Serializable, Object> childnode = nodesRoot.getChild(makeNodeFqn(childNodeId));
- if (childnode == null)
- {
- throw new RepositoryException("FATAL Node record not found(" + childNodeId + "), but listed in childs of "
- + data.getQPath().getAsString());
- }
- NodeData nodeData = (NodeData)childnode.get(ITEM_DATA);
- if (nodeData == null)
- {
- // TODO should not occurs by contract
- throw new RepositoryException("Child node data is null. Parent " + data.getQPath().getAsString());
- }
-
- //repack child NodeData with new QPath
- //TODO check it
- QPath newPath = QPath.makeChildPath(data.getQPath(), nodeData.getQPath().getName());
- TransientNodeData newNodeData =
- new TransientNodeData(newPath, nodeData.getIdentifier(), nodeData.getPersistedVersion(), nodeData
- .getPrimaryTypeName(), nodeData.getMixinTypeNames(), nodeData.getOrderNumber(), nodeData
- .getParentIdentifier(), nodeData.getACL());
- childnode.put(ITEM_DATA, newNodeData);
- }
-
+// startBatch();
+//
+// String nodeId = data.getIdentifier();
+//
+// //1. Update renamed node and also get old nodeData
+// Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(nodeId));
+// if (node == null)
+// {
+// throw new InvalidItemStateException("Renamed node is not exist" + data.getQPath().getAsString());
+// }
+//
+// NodeData prevData = (NodeData)node.put(ITEM_DATA, data);
+// if (prevData == null)
+// {
+// throw new RepositoryException("FATAL NodeData is empty " + data.getQPath().getAsString());
+// }
+//
+// // 2. remove renamed node from child list of previous parent node
+// // check if parent is cached
+// Node<Serializable, Object> prevParent = nodesRoot.getChild(makeNodeFqn(prevData.getParentIdentifier()));
+// if (prevParent == null)
+// {
+// throw new InvalidItemStateException("Node's previous parent doesn't exist "
+// + prevData.getQPath().getAsString() + ". Node " + data.getQPath().getAsString());
+// }
+//
+// // remove node form old parent child list
+// if (!prevParent
+// .removeChild(makeChildNodeFqn(prevData.getQPath().getEntries()[prevData.getQPath().getEntries().length - 1])))
+// {
+// throw new RepositoryException("FATAL Node doesn't listed in children nodes of previous parent "
+// + prevData.getQPath().getAsString() + ". Node " + data.getQPath().getAsString());
+// }
+//
+// // 3. add node to child list of new parent node
+// // check if parent is cached
+// Node<Serializable, Object> newParent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
+// if (newParent == null)
+// {
+// throw new InvalidItemStateException("Node's new parent doesn't exist " + data.getParentIdentifier()
+// + ". Node " + data.getQPath().getAsString());
+// }
+//
+// // add child to Parent
+// Node<Serializable, Object> childNode =
+// newParent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+//
+// // set child id attr
+// childNode.put(ITEM_ID, data.getIdentifier());
+//
+// // 4. update all child nodes
+// for (Node<Serializable, Object> child : node.getChildren())
+// {
+// String childNodeId = (String)child.get(ITEM_ID);
+// if (childNodeId == null)
+// {
+// throw new RepositoryException("FATAL Child Node Id key is null. Parent " + data.getQPath().getAsString());
+// }
+//
+// // TODO NodeData or PropertyData? As ItemData check then and cast.
+// Node<Serializable, Object> childnode = nodesRoot.getChild(makeNodeFqn(childNodeId)); //cache.evict(fqn)
+// if (childnode == null)
+// {
+// throw new RepositoryException("FATAL Node record not found(" + childNodeId + "), but listed in childs of "
+// + data.getQPath().getAsString());
+// }
+// NodeData nodeData = (NodeData)childnode.get(ITEM_DATA);
+// if (nodeData == null)
+// {
+// // TODO should not occurs by contract
+// throw new RepositoryException("Child node data is null. Parent " + data.getQPath().getAsString());
+// }
+//
+// //repack child NodeData with new QPath
+// //TODO check it
+// QPath newPath = QPath.makeChildPath(data.getQPath(), nodeData.getQPath().getName());
+// TransientNodeData newNodeData =
+// new TransientNodeData(newPath, nodeData.getIdentifier(), nodeData.getPersistedVersion(), nodeData
+// .getPrimaryTypeName(), nodeData.getMixinTypeNames(), nodeData.getOrderNumber(), nodeData
+// .getParentIdentifier(), nodeData.getACL());
+// childnode.put(ITEM_DATA, newNodeData);
+// }
}
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-20 09:48:12 UTC (rev 784)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-20 09:50:37 UTC (rev 785)
@@ -125,7 +125,6 @@
this.cache.addInterceptor(indexInterceptor, CacheStoreInterceptor.class);
Node<Serializable, Object> cacheRoot = cache.getRoot();
- //Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
// prepare cache structures
cache.startBatch();
@@ -138,25 +137,13 @@
public void start()
{
-
- // TODO started on init, due to RepositoryContainer logic
- // if (persistentContainer instanceof Startable)
- // {
- // ((Startable)persistentContainer).start();
- // }
- //
- // this.cache.start();
- //
- // Node<Serializable, Object> cacheRoot = cache.getRoot();
- // //Node<Serializable, Object> wsRoot = cacheRoot.addChild(Fqn.fromElements(repositoryName, containerName));
- //
- // // prepare cache structures
- // this.nodes = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.NODES));
- // this.properties = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.PROPS));
}
public void stop()
{
+ this.cache.stop();
+ this.cache.destroy();
+
if (persistentContainer instanceof Startable)
{
((Startable)persistentContainer).stop();
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-20 09:48:12 UTC (rev 784)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java 2009-11-20 09:50:37 UTC (rev 785)
@@ -113,7 +113,6 @@
LOG.warn("PUT_DATA_ERASE modification");
break;
case PUT_KEY_VALUE :
-
if (m.getFqn().size() == 2)
{
if (isUpdate(m, (JDBCStorageConnection)conn))
16 years, 8 months
exo-jcr SVN: r784 - in jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage: jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-20 04:48:12 -0500 (Fri, 20 Nov 2009)
New Revision: 784
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-203 : The test JDBCCacheLoaderTest was fixed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java 2009-11-20 08:28:44 UTC (rev 783)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/JDBCWorkspaceDataContainerTestBase.java 2009-11-20 09:48:12 UTC (rev 784)
@@ -72,7 +72,7 @@
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.exoplatform.services.naming.SimpleContextFactory");
// Create data source. Will be created new data source to new test.
- String dataSourceName = "jdbcjcr_" + IdGenerator.generate();
+ String dataSourceName = getDataSourceName();
createNewDataSource(dataSourceName);
WorkspaceEntry ws =
@@ -86,6 +86,10 @@
persistentContainer = new JDBCWorkspaceDataContainer(ws, re, null, valueStoragePluginProvider);
}
+
+ protected String getDataSourceName() {
+ return "jdbcjcr_" + IdGenerator.generate();
+ }
protected WorkspaceEntry getNewWs(String wsName, boolean isMultiDb, String dsName, String vsPath, ContainerEntry entry)
throws Exception
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-20 08:28:44 UTC (rev 783)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-20 09:48:12 UTC (rev 784)
@@ -56,8 +56,6 @@
public class JDBCCacheLoaderTest extends AbstractCacheLoaderTest
{
- private JDBCWorkspaceDataContainer persistentContainer;
-
private JDBCCacheLoader loader;
/**
16 years, 8 months
exo-jcr SVN: r783 - in jcr/branches/1.12.0-JBC/component/core/src: main/java/org/exoplatform/services/jcr/impl/core/lock and 1 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-11-20 03:28:44 -0500 (Fri, 20 Nov 2009)
New Revision: 783
Added:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockRemover.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestSessionLockManager.java
Log:
EXOJCR-243: Added lock removing logic on timeout. This added through persistent lock manager, that creates worker thread to remove locks.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2009-11-19 16:19:28 UTC (rev 782)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2009-11-20 08:28:44 UTC (rev 783)
@@ -40,6 +40,7 @@
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.core.WorkspaceInitializer;
import org.exoplatform.services.jcr.impl.core.access.DefaultAccessManagerImpl;
+import org.exoplatform.services.jcr.impl.core.lock.PersistentLockManager;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeDataManagerImpl;
import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
import org.exoplatform.services.jcr.impl.core.nodetype.registration.JcrNodeTypeDataPersister;
@@ -286,6 +287,10 @@
}
}
+ // persistent lock manager
+
+ workspaceContainer.registerComponentImplementation(PersistentLockManager.class);
+
// initializer
Class<?> initilizerType;
if (wsConfig.getInitializer() != null && wsConfig.getInitializer().getType() != null)
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2009-11-19 16:19:28 UTC (rev 782)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockData.java 2009-11-20 08:28:44 UTC (rev 783)
@@ -89,6 +89,7 @@
* @param sessionScoped
* @param owner
* @param timeOut
+ * is seconds!
*/
public LockData(String nodeIdentifier, String lockToken, boolean deep, boolean sessionScoped, String owner,
long timeOut)
Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockRemover.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockRemover.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockRemover.java 2009-11-20 08:28:44 UTC (rev 783)
@@ -0,0 +1,62 @@
+package org.exoplatform.services.jcr.impl.core.lock;
+
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import org.exoplatform.services.jcr.impl.proccess.WorkerThread;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * @author <a href="mailto:Sergey.Kabashnyuk@gmail.com">Sergey Kabashnyuk</a>
+ * @version $Id$
+ */
+public class LockRemover extends WorkerThread
+{
+
+ private final Log log = ExoLogger.getLogger("jcr.lock.LockRemover");
+
+ public static final long DEFAULT_THREAD_TIMEOUT = 30000; // 30
+
+ private final PersistentLockManager persistentLockManager;
+
+ public LockRemover(PersistentLockManager persistentLockManager)
+ {
+ this(persistentLockManager, DEFAULT_THREAD_TIMEOUT);
+ }
+
+ private LockRemover(PersistentLockManager persistentLockManager, long timeout)
+ {
+ super(timeout);
+ this.persistentLockManager = persistentLockManager;
+ setName("LockRemover " + getId());
+ setDaemon(true);
+ start();
+ if (log.isDebugEnabled())
+ log.debug("LockRemover instantiated name= " + getName() + " timeout= " + timeout);
+ }
+
+ @Override
+ protected void callPeriodically() throws Exception
+ {
+ persistentLockManager.removeExpired();
+ }
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/LockRemover.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java 2009-11-20 08:28:44 UTC (rev 783)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.lock;
+
+import org.exoplatform.services.jcr.access.SystemIdentity;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
+import org.exoplatform.services.jcr.observation.ExtendedEvent;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.picocontainer.Startable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * This is a persistent lock manager, that currently is responsible for removing expired locks
+ *
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id$
+ *
+ */
+public class PersistentLockManager implements Startable
+{
+ private final Log log = ExoLogger.getLogger(this.getClass().getName());
+
+ /**
+ * Lock remover thread.
+ */
+ private LockRemover lockRemover;
+
+ /**
+ * Workspace data manager
+ */
+ WorkspacePersistentDataManager dataManager;
+
+ /**
+ * creates persistent lock manager
+ */
+ public PersistentLockManager(WorkspacePersistentDataManager dataManager)
+ {
+ this.dataManager = dataManager;
+ }
+
+ /**
+ * @see org.picocontainer.Startable#start()
+ */
+ public void start()
+ {
+ lockRemover = new LockRemover(this);
+ }
+
+ /**
+ * @see org.picocontainer.Startable#stop()
+ */
+ public void stop()
+ {
+ lockRemover.halt();
+ lockRemover.interrupt();
+ }
+
+ /**
+ * Removes all expired locks
+ */
+ protected void removeExpired()
+ {
+ List<LockData> lockDatas;
+ try
+ {
+ lockDatas = dataManager.getLocksData();
+ }
+ catch (RepositoryException e)
+ {
+ // exception getting list of locks, return
+ log.error(e.getMessage(), e);
+ return;
+ }
+
+ if (lockDatas != null)
+ {
+ for (LockData lockData : lockDatas)
+ {
+ System.out.println(" found sucg lock: " + lockData.getNodeIdentifier());
+ System.out.println(" it's expir time: " + lockData.getTimeToDeath());
+ if (lockData.getTimeToDeath() < 0)
+ {
+ // try to remove node, if unsuccessful then, at least, try to remove other expired locks
+ try
+ {
+ NodeData node = (NodeData)dataManager.getItemData(lockData.getNodeIdentifier());
+
+ PlainChangesLog changesLog =
+ new PlainChangesLogImpl(new ArrayList<ItemState>(), SystemIdentity.SYSTEM, ExtendedEvent.UNLOCK);
+ ItemData lockOwner = dataManager.getItemData(node, new QPathEntry(Constants.JCR_LOCKOWNER, 0));
+ changesLog.add(ItemState.createDeletedState(lockOwner));
+ ItemData lockIsDeep = dataManager.getItemData(node, new QPathEntry(Constants.JCR_LOCKISDEEP, 0));
+ changesLog.add(ItemState.createDeletedState(lockIsDeep));
+
+ dataManager.save(changesLog);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error removing expired lock from node : " + lockData.getNodeIdentifier());
+ }
+ }
+ }
+ }
+ }
+}
Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/PersistentLockManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2009-11-19 16:19:28 UTC (rev 782)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/SessionLockManager.java 2009-11-20 08:28:44 UTC (rev 783)
@@ -61,7 +61,7 @@
/**
* Default lock time out. 30min
*/
- public static final long DEFAULT_LOCK_TIMEOUT = 1000 * 60 * 30;
+ public static final long DEFAULT_LOCK_TIMEOUT = 60 * 30;
/**
* Search lockData for given node
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestSessionLockManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestSessionLockManager.java 2009-11-19 16:19:28 UTC (rev 782)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/lock/TestSessionLockManager.java 2009-11-20 08:28:44 UTC (rev 783)
@@ -173,8 +173,7 @@
public void testRemoveByTimeOut() throws RepositoryException
{
- int REMOVER_SCHEDULE_TIME = 10000; // 10s?! need to place correct value
- int lockTimeOut = 2000;
+ int lockTimeOut = 2;
NodeImpl node1 = (NodeImpl)testRoot.addNode("testRemoveByTimeOut");
node1.addMixin("mix:lockable");
session.save();
@@ -183,7 +182,7 @@
try
{
// sleep for Remover period time + lockTimeOut + 1s for stability
- Thread.sleep(REMOVER_SCHEDULE_TIME + lockTimeOut + 1000);
+ Thread.sleep(LockRemover.DEFAULT_THREAD_TIMEOUT + lockTimeOut * 1000 + 5000);
}
catch (InterruptedException e)
{
16 years, 8 months
exo-jcr SVN: r782 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2009-11-19 11:19:28 -0500 (Thu, 19 Nov 2009)
New Revision: 782
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-246: reference support added
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-19 15:56:16 UTC (rev 781)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorage.java 2009-11-19 16:19:28 UTC (rev 782)
@@ -44,6 +44,8 @@
public static final String LOCKS = "$LOCKS".intern();
+ public static final String REFS = "$REFS".intern();
+
public static final String ITEM_DATA = "$data".intern();
public static final String ITEM_ID = "$id".intern();
@@ -62,14 +64,18 @@
protected final Node<Serializable, Object> locksRoot;
+ protected final Node<Serializable, Object> refsRoot;
+
protected JBossCacheStorage(Node<Serializable, Object> nodesRoot, Node<Serializable, Object> propsRoot,
- Node<Serializable, Object> locksRoot)
+ Node<Serializable, Object> locksRoot, Node<Serializable, Object> refsRoot)
{
this.nodesRoot = nodesRoot;
this.propsRoot = propsRoot;
this.locksRoot = locksRoot;
+
+ this.refsRoot = refsRoot;
}
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-19 15:56:16 UTC (rev 781)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-19 16:19:28 UTC (rev 782)
@@ -18,13 +18,17 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.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.core.lock.LockData;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.ValueDataConvertor;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -32,13 +36,17 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import java.io.IOException;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
+import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
@@ -75,11 +83,12 @@
* JBossCacheStorageConnection constructor.
*
* @param cache Cache<Serializable, Object>
+ * @param refs
*/
public JBossCacheStorageConnection(Cache<Serializable, Object> cache, Node<Serializable, Object> nodesRoot,
- Node<Serializable, Object> propsRoot, Node<Serializable, Object> locksRoot)
+ Node<Serializable, Object> propsRoot, Node<Serializable, Object> locksRoot, Node<Serializable, Object> refsRoot)
{
- super(nodesRoot, propsRoot, locksRoot);
+ super(nodesRoot, propsRoot, locksRoot, refsRoot);
this.cache = cache;
}
@@ -138,6 +147,43 @@
throw new RepositoryException("Property's parent doesn't exist " + data.getQPath().getAsString());
}
+ if (data.getType() == PropertyType.REFERENCE)
+ {
+ Fqn propUUID = makeNodeFqn(data.getIdentifier());
+
+ for (ValueData value : data.getValues())
+ {
+
+ String refNodeUUID;
+ try
+ {
+ refNodeUUID = ValueDataConvertor.readString(value);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+
+ Fqn refNode = makeNodeFqn(refNodeUUID);
+
+ // add to $REFS map
+ Node<Serializable, Object> refParent = refsRoot.getChild(refNode);
+ if (refParent == null)
+ {
+ refParent = refsRoot.addChild(refNode);
+ }
+
+ refParent.addChild(propUUID);
+ }
+
+ }
+
// add to parent's properties attr
String propName = data.getQPath().getName().getAsString();
if (parent.get(propName) == null)
@@ -162,6 +208,23 @@
{
startBatch();
+ for (InternalQName mixin : data.getMixinTypeNames())
+ {
+ if (mixin.equals(Constants.MIX_REFERENCEABLE))
+ {
+ // check and release references
+ Node<Serializable, Object> node = refsRoot.addChild(Fqn.fromElements(data.getIdentifier()));
+ if (node != null)
+ {
+ if (node.getChildrenNames().size() != 0)
+ {
+ throw new RepositoryException("Referenceable node removed but still have live references.");
+ }
+ }
+ break;
+ }
+ }
+
if (data.getParentIdentifier() != null)
{
// check if parent is cached
@@ -199,6 +262,46 @@
throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
}
+ if (data.getType() == PropertyType.REFERENCE)
+ {
+ Fqn propUUID = makeNodeFqn(data.getIdentifier());
+
+ for (ValueData value : data.getValues())
+ {
+
+ String refNodeUUID;
+ try
+ {
+ refNodeUUID = ValueDataConvertor.readString(value);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+
+ // remove property from referencedNode in $REFS map
+
+ Node<Serializable, Object> refParent = refsRoot.getChild(makeNodeFqn(refNodeUUID));
+ if (refParent != null)
+ {
+ refParent.removeChild(propUUID);
+ }
+ // check is there is no more references
+ if (refParent.getChildrenNames().size() == 0)
+ {
+ //TODO remove children
+ refsRoot.removeChild(makeNodeFqn(refNodeUUID));
+ }
+ }
+
+ }
+
// remove from parent's properties attr
// TODO validate does deleted
if (parent.remove(data.getQPath().getName().getAsString()) == null)
@@ -474,8 +577,33 @@
public List<PropertyData> getReferencesData(String nodeIdentifier) throws RepositoryException,
IllegalStateException, UnsupportedOperationException
{
- // TODO refs impl
- return new ArrayList<PropertyData>();
+ ArrayList<PropertyData> references = new ArrayList<PropertyData>();
+
+ Node<Serializable, Object> node = this.refsRoot.getChild(Fqn.fromElements(nodeIdentifier));
+ if (node != null)
+ {
+ Set<Object> props = node.getChildrenNames();
+
+ for (Object o : props)
+ {
+ String propUUID = (String)o;
+ Node<Serializable, Object> prop = propsRoot.getChild(Fqn.fromElements(propUUID));
+ if (prop == null)
+ {
+ throw new RepositoryException("FATAL Property record not found(" + propUUID
+ + "), but listed in reference properties of node " + nodeIdentifier);
+ }
+
+ PropertyData propData = (PropertyData)prop.get(ITEM_DATA);
+ if (propData == null)
+ {
+ throw new RepositoryException("FATAL Property data is null. Property UUID " + propUUID);
+ }
+
+ references.add(propData);
+ }
+ }
+ return references;
}
/**
@@ -625,13 +753,107 @@
{
startBatch();
+ Fqn propFqn = Fqn.fromElements(data.getIdentifier());
+
// update in PROPERTIES
- Node<Serializable, Object> prop = propsRoot.getChild(makePropFqn(data.getIdentifier()));
+ Node<Serializable, Object> prop = propsRoot.getChild(propFqn);
if (prop == null)
{
throw new IllegalStateException("Property was deleted " + data.getQPath().getAsString());
}
+ if (data.getType() == PropertyType.REFERENCE)
+ {
+ PropertyData propData = (PropertyData)prop.get(ITEM_DATA);
+ if (propData == null)
+ {
+ throw new RepositoryException("FATAL Property data is null. Parent " + data.getQPath().getAsString());
+ }
+
+ //get Set of old values
+ Set<String> removeSet = new HashSet<String>();
+ for (ValueData value : propData.getValues())
+ {
+ try
+ {
+ removeSet.add(ValueDataConvertor.readString(value));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ }
+
+ Set<String> addSet = new HashSet<String>();
+ // check new
+ for (ValueData value : data.getValues())
+ {
+ try
+ {
+ addSet.add(ValueDataConvertor.readString(value));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ throw new RepositoryException(e.getMessage(), e);
+ }
+ }
+
+ String[] added = new String[addSet.size()];
+ addSet.toArray(added);
+
+ for (String id : added)
+ {
+ if (removeSet.contains(id))
+ {
+ removeSet.remove(id);
+ addSet.remove(id);
+ }
+ }
+
+ // remove references to nodes
+ for (String id : removeSet)
+ {
+ Node<Serializable, Object> node = refsRoot.getChild(Fqn.fromElements(id));
+ if (!node.removeChild(propFqn))
+ {
+ throw new RepositoryException("FATAL Reference property was not removed from REFS table of node " + id);
+ }
+
+ // check node
+ if (node.getChildrenNames().size() == 0)
+ {
+ //TODO remove children
+ refsRoot.removeChild(Fqn.fromElements(id));
+ }
+ }
+
+ // add references to nodes
+ for (String id : addSet)
+ {
+ Fqn nodeFqn = Fqn.fromElements(id);
+ Node<Serializable, Object> node = refsRoot.getChild(nodeFqn);
+
+ if (node == null)
+ {
+ node = refsRoot.addChild(nodeFqn);
+ }
+ node.addChild(propFqn);
+ }
+ }
+
+ // remove
prop.put(ITEM_DATA, data);
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-19 15:56:16 UTC (rev 781)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheWorkspaceDataContainer.java 2009-11-19 16:19:28 UTC (rev 782)
@@ -74,6 +74,8 @@
private Node<Serializable, Object> locks;
+ private Node<Serializable, Object> refs;
+
/**
* JBossWorkspaceDataContainer constructor.
*
@@ -130,6 +132,7 @@
this.nodes = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.NODES));
this.properties = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.PROPS));
this.locks = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.LOCKS));
+ this.refs = cacheRoot.addChild(Fqn.fromElements(JBossCacheStorage.REFS));
cache.endBatch(true);
}
@@ -179,7 +182,7 @@
// throw new RepositoryException("Container is not started");
// }
- return new JBossCacheStorageConnection(cache, nodes, properties, locks);
+ return new JBossCacheStorageConnection(cache, nodes, properties, locks, refs);
}
/**
@@ -193,7 +196,7 @@
// throw new RepositoryException("Container is not started");
// }
- return new JBossCacheStorageConnection(cache, nodes, properties, locks);
+ return new JBossCacheStorageConnection(cache, nodes, properties, locks, refs);
}
/**
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java 2009-11-19 15:56:16 UTC (rev 781)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/AbstractJBossCacheStorageConnectionTest.java 2009-11-19 16:19:28 UTC (rev 782)
@@ -24,7 +24,6 @@
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.storage.JDBCWorkspaceDataContainerTestBase;
-import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
@@ -57,6 +56,8 @@
protected Node<Serializable, Object> locks;
+ protected Node<Serializable, Object> refs;
+
protected String jbcConfig;
/**
@@ -84,9 +85,10 @@
nodes = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.NODES));
props = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.PROPS));
locks = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.LOCKS));
+ refs = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.REFS));
cache.endBatch(true);
// JCR connection
- conn = new JBossCacheStorageConnection(cache, nodes, props, locks);
+ conn = new JBossCacheStorageConnection(cache, nodes, props, locks, refs);
}
protected void initJBCConfig()
@@ -157,8 +159,8 @@
Constants.DEFAULT_ENCODING));
}
- protected void checkChildProp(Node<Serializable, Object> node, InternalQName propName, String propId, QPath propPath,
- Object propValue) throws UnsupportedEncodingException, IllegalStateException, IOException
+ protected void checkChildProp(Node<Serializable, Object> node, InternalQName propName, String propId,
+ QPath propPath, Object propValue) throws UnsupportedEncodingException, IllegalStateException, IOException
{
String pid = (String)node.get(propName.getAsString());
@@ -201,5 +203,5 @@
assertEquals("Node persisted version wrong", version, childNodeData.getPersistedVersion());
}
}
-
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 15:56:16 UTC (rev 781)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 16:19:28 UTC (rev 782)
@@ -24,8 +24,8 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.core.lock.LockData;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
@@ -33,11 +33,14 @@
import org.jboss.cache.Node;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.List;
import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
import javax.jcr.lock.LockException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
/**
* Created by The eXo Platform SAS.
@@ -635,13 +638,13 @@
// add /jcr:system
conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
-
-
- try {
+
+ try
+ {
// add /jcr:system twice
conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
-
+ new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
conn.commit();
fail("The node jcr:system should not be save");
@@ -738,4 +741,98 @@
//ok
}
}
+
+ public void testGetReferences() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, null, new AccessControlList()));
+
+ // add refernceable node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]firstParent:1");
+
+ NodeData node1 =
+ new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[]{Constants.MIX_REFERENCEABLE}, 0, Constants.ROOT_UUID, new AccessControlList());
+ conn.add(node1);
+
+ // add node2 with reference on node
+ String node2id = "2";
+ QPath node2path = QPath.parse("[]:1[]secondParent:1");
+ conn.add(new TransientNodeData(node2path, node2id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ String refpropid = "21";
+ TransientPropertyData prop =
+ new TransientPropertyData(QPath.makeChildPath(node2path, "[]refprop:1"), refpropid, 0, PropertyType.REFERENCE,
+ node2id, false);
+
+ prop.setValue(new TransientValueData(node1id));
+ conn.add(prop);
+
+ String node3id = "3";
+ QPath node3path = QPath.parse("[]:1[]node3:1");
+
+ NodeData node3 =
+ new TransientNodeData(node3path, node3id, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[]{Constants.MIX_REFERENCEABLE}, 0, Constants.ROOT_UUID, new AccessControlList());
+ conn.add(node3);
+
+ // check in nodes
+ treePrint(nodes);
+
+ // get root node ([]:1)
+ Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+ assertNotNull("Node expected", rootNode);
+
+ // check root Node
+ checkNode(rootNode, Constants.ROOT_UUID, Constants.ROOT_PATH);
+
+ // cechk childs
+ assertEquals("Childs expected", 3, rootNode.getChildren().size());
+ checkChildNode(rootNode, node1id, node1path);
+ checkChildNode(rootNode, node2id, node2path);
+ checkChildNode(rootNode, node3id, node3path);
+
+ List<PropertyData> props = conn.getReferencesData(node1id);
+ assertEquals("References expected", 1, props.size());
+ props = conn.getReferencesData(node3id);
+ assertEquals("References expected", 0, props.size());
+
+ // try remove referenced node
+ try
+ {
+ conn.delete(node1);
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ //ok
+ }
+
+ // update reference property
+
+ TransientPropertyData updateProp =
+ new TransientPropertyData(prop.getQPath(), prop.getIdentifier(), 0, PropertyType.REFERENCE, prop
+ .getParentIdentifier(), false);
+
+ List<ValueData> list = new ArrayList<ValueData>();
+ list.add(new TransientValueData(node1id));
+ list.add(new TransientValueData(node3id));
+
+ // ValueData[]{new TransientValueData(node1id)}
+ updateProp.setValues(list);
+ conn.update(updateProp);
+
+ // check
+ props = conn.getReferencesData(node1id);
+ assertEquals("References expected", 1, props.size());
+ props = conn.getReferencesData(node3id);
+ assertEquals("References expected", 1, props.size());
+
+ conn.delete(updateProp);
+ conn.delete(node1);
+ conn.delete(node3);
+ }
}
16 years, 8 months
exo-jcr SVN: r781 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-19 10:56:16 -0500 (Thu, 19 Nov 2009)
New Revision: 781
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-203 : The test JBossCacheStorageConnectionTest was changed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 15:32:09 UTC (rev 780)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 15:56:16 UTC (rev 781)
@@ -35,6 +35,7 @@
import java.io.Serializable;
import java.util.List;
+import javax.jcr.InvalidItemStateException;
import javax.jcr.ItemExistsException;
import javax.jcr.lock.LockException;
@@ -643,7 +644,7 @@
conn.commit();
- fail("The node jcr:system shouldnot be save");
+ fail("The node jcr:system should not be save");
} catch (ItemExistsException e) {
//ok
}
@@ -671,9 +672,70 @@
conn.commit();
- fail("The property (/jcr:primaryType) shouldnot be save");
+ fail("The property (/jcr:primaryType) should not be save");
} catch (ItemExistsException e) {
//ok
}
}
+
+ public void testDeleteNodeFail() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, null, new AccessControlList()));
+
+ // add node (/node)
+ String node1id = "1";
+ QPath node1path = QPath.parse("[]:1[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // add /jcr:system
+ conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+
+ // delete /node
+ conn.delete(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ try {
+ // delete node /node twice
+ conn.delete(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ conn.commit();
+
+ fail("The node (/node) should not be delete");
+ } catch (InvalidItemStateException e) {
+ //ok
+ }
+ }
+
+ public void testDeletePropertyFail() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, null, new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ String propId1 = "1";
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE), propId1,
+ 1, 1, Constants.ROOT_UUID, false));
+
+ // delete /jcr:primaryType
+ conn.delete(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE),
+ propId1, 1, 1, Constants.ROOT_UUID, false));
+
+ try {
+ // delete /jcr:primaryType twice
+ conn.delete(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE),
+ propId1, 1, 1, Constants.ROOT_UUID, false));
+
+ conn.commit();
+
+ fail("The property (/jcr:primaryType) should not be delete");
+ } catch (InvalidItemStateException e) {
+ //ok
+ }
+ }
}
16 years, 8 months
exo-jcr SVN: r780 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-19 10:32:09 -0500 (Thu, 19 Nov 2009)
New Revision: 780
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-203 : The test JBossCacheStorageConnectionTest was changed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 15:15:17 UTC (rev 779)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 15:32:09 UTC (rev 780)
@@ -35,6 +35,7 @@
import java.io.Serializable;
import java.util.List;
+import javax.jcr.ItemExistsException;
import javax.jcr.lock.LockException;
/**
@@ -643,8 +644,36 @@
conn.commit();
fail("The node jcr:system shouldnot be save");
- } catch (Exception e) {
+ } catch (ItemExistsException e) {
//ok
}
}
+
+ public void testAddPropertyFail() throws Exception
+ {
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, null, new AccessControlList()));
+
+ // add property (/jcr:primaryType)
+ String propId1 = "1";
+ QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+ TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+ String propValue1 = "Property value #1";
+ propData1.setValue(new TransientValueData(propValue1));
+ conn.add(propData1);
+
+
+
+ try {
+ // add property (/jcr:primaryType) twice
+ conn.add(propData1);
+
+ conn.commit();
+
+ fail("The property (/jcr:primaryType) shouldnot be save");
+ } catch (ItemExistsException e) {
+ //ok
+ }
+ }
}
16 years, 8 months
exo-jcr SVN: r779 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-19 10:15:17 -0500 (Thu, 19 Nov 2009)
New Revision: 779
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-203: Item existence detecting in add/delete
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-19 14:55:06 UTC (rev 778)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-19 15:15:17 UTC (rev 779)
@@ -29,6 +29,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import java.io.Serializable;
@@ -37,6 +38,7 @@
import java.util.Set;
import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemExistsException;
import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
@@ -99,12 +101,21 @@
throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
}
- // add child to Parent
- Node<Serializable, Object> childNode =
- parent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+ final Fqn<String> name =
+ makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]);
- // set child id attr
- childNode.put(ITEM_ID, data.getIdentifier());
+ if (parent.hasChild(name))
+ {
+ throw new ItemExistsException("Node already exists " + data.getQPath().getAsString());
+ }
+ else
+ {
+ // add child to Parent
+ Node<Serializable, Object> childNode = parent.addChild(name);
+
+ // set child id attr
+ childNode.put(ITEM_ID, data.getIdentifier());
+ }
}
// add in NODES
@@ -124,11 +135,19 @@
Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
if (parent == null)
{
- throw new RepositoryException("Property parent doesn't exist " + data.getQPath().getAsString());
+ throw new RepositoryException("Property's parent doesn't exist " + data.getQPath().getAsString());
}
// add to parent's properties attr
- parent.put(data.getQPath().getName().getAsString(), data.getIdentifier());
+ String propName = data.getQPath().getName().getAsString();
+ if (parent.get(propName) == null)
+ {
+ parent.put(propName, data.getIdentifier());
+ }
+ else
+ {
+ throw new ItemExistsException("Property already exists " + data.getQPath().getAsString());
+ }
// add in PROPERTIES
Node<Serializable, Object> prop = propsRoot.addChild(makePropFqn(data.getIdentifier()));
@@ -153,9 +172,12 @@
}
// remove child on Parent
- // TODO validate does deleted
- boolean removed =
- parent.removeChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+ if (!parent
+ .removeChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1])))
+ {
+ throw new InvalidItemStateException("Node's doesn't exist or deleted by another Session "
+ + data.getQPath().getAsString());
+ }
}
// remove from NODES
@@ -179,7 +201,11 @@
// remove from parent's properties attr
// TODO validate does deleted
- Object prev = parent.remove(data.getQPath().getName().getAsString());
+ if (parent.remove(data.getQPath().getName().getAsString()) == null)
+ {
+ throw new InvalidItemStateException("Property doesn't exist or deleted by another Session "
+ + data.getQPath().getAsString());
+ }
// remove from PROPERTIES
boolean removed = propsRoot.removeChild(makePropFqn(data.getIdentifier()));
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 14:55:06 UTC (rev 778)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-19 15:15:17 UTC (rev 779)
@@ -640,6 +640,8 @@
conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+ conn.commit();
+
fail("The node jcr:system shouldnot be save");
} catch (Exception e) {
//ok
16 years, 8 months