result = dir.lookupChild(cPath, name, true);
- if (result != null)
+ if (result != null)
{
- AVMNode child = result.getFirst();
- if (!fAVMRepository.can(null, child, PermissionService.WRITE, cPath.getDirectlyContained()))
- {
- throw new AccessDeniedException("Not allowed to update node: " + parentPath + "/" +name );
- }
- dir.removeChild(lPath, name);
+ AVMNode child = result.getFirst();
+ if (!fAVMRepository.can(null, child, PermissionService.WRITE, cPath.getDirectlyContained()))
+ {
+ throw new AccessDeniedException("Not allowed to update node: " + parentPath + "/" +name );
+ }
+ dir.removeChild(lPath, name);
}
dir.link(lPath, name, toLink);
}
diff --git a/source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java
index b929908989..7bb6faf201 100644
--- a/source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java
+++ b/source/java/org/alfresco/repo/domain/avm/AVMNodeEntity.java
@@ -373,6 +373,18 @@ public class AVMNodeEntity
this.vers = vers;
}
+ public void incrementVers()
+ {
+ if (this.vers >= Long.MAX_VALUE)
+ {
+ this.vers = 0L;
+ }
+ else
+ {
+ this.vers++;
+ }
+ }
+
@Override
public int hashCode()
{
diff --git a/source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java b/source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java
index 69501557a6..c61a2e0a0f 100644
--- a/source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java
+++ b/source/java/org/alfresco/repo/domain/avm/AVMStoreEntity.java
@@ -103,6 +103,18 @@ public class AVMStoreEntity
this.vers = vers;
}
+ public void incrementVers()
+ {
+ if (this.vers >= Long.MAX_VALUE)
+ {
+ this.vers = 0L;
+ }
+ else
+ {
+ this.vers++;
+ }
+ }
+
@Override
public int hashCode()
{
diff --git a/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java
index 634c57d00b..f79adf531b 100644
--- a/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/avm/AbstractAVMNodeDAOImpl.java
@@ -189,7 +189,6 @@ public abstract class AbstractAVMNodeDAOImpl implements AVMNodeDAO
{
throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently");
}
- nodeEntity.setVers(nodeEntity.getVers()+1);
}
/**
@@ -209,7 +208,6 @@ public abstract class AbstractAVMNodeDAOImpl implements AVMNodeDAO
{
throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently");
}
- nodeEntity.setVers(nodeEntity.getVers()+1);
// update cache
avmNodeCache.removeByKey(nodeEntity.getId());
@@ -232,7 +230,6 @@ public abstract class AbstractAVMNodeDAOImpl implements AVMNodeDAO
{
throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently");
}
- nodeEntity.setVers(nodeEntity.getVers()+1);
// update cache
avmNodeCache.removeByKey(nodeEntity.getId());
diff --git a/source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java
index cba0426093..332462681f 100644
--- a/source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/avm/AbstractAVMStoreDAOImpl.java
@@ -1,34 +1,34 @@
-/*
- * Copyright (C) 2005-2009 Alfresco Software Limited.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
- * As a special exception to the terms and conditions of version 2.0 of
- * the GPL, you may redistribute this Program in connection with Free/Libre
- * and Open Source Software ("FLOSS") applications as described in Alfresco's
- * FLOSS exception. You should have recieved a copy of the text describing
- * the FLOSS exception, and it is also available here:
- * http://www.alfresco.com/legal/licensing"
- */
-package org.alfresco.repo.domain.avm;
-
+/*
+ * Copyright (C) 2005-2009 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.domain.avm;
+
import java.io.Serializable;
import java.util.HashMap;
-import java.util.List;
+import java.util.List;
import java.util.Map;
-
+
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.cache.lookup.EntityLookupCache;
@@ -37,20 +37,20 @@ import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
-import org.alfresco.util.ParameterCheck;
-import org.springframework.dao.ConcurrencyFailureException;
-
-/**
- * Abstract implementation for AVMStore DAO.
- *
+import org.alfresco.util.ParameterCheck;
+import org.springframework.dao.ConcurrencyFailureException;
+
+/**
+ * Abstract implementation for AVMStore DAO.
+ *
* This provides basic services such as caching but defers to the underlying implementation
- * for CRUD operations.
- *
- * @author janv
- * @since 3.2
- */
-public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
-{
+ * for CRUD operations.
+ *
+ * @author janv
+ * @since 3.2
+ */
+public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
+{
private static final String CACHE_REGION_AVM_STORE = "AVMStore";
private static final String CACHE_REGION_AVM_STORE_PROP = "AVMStoreProp";
@@ -59,7 +59,7 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
private QNameDAO qnameDAO;
- /**
+ /**
* Cache for the AVM store entity:
* KEY: ID
* VALUE: AVMStoreEntity
@@ -123,8 +123,8 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
}
/**
- * {@inheritDoc}
- */
+ * {@inheritDoc}
+ */
public AVMStoreEntity createStore(String name)
{
ParameterCheck.mandatory("name", name);
@@ -143,31 +143,31 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
* {@inheritDoc}
*/
public AVMStoreEntity getStore(long storeId)
- {
+ {
Pair entityPair = avmStoreCache.getByKey(storeId);
if (entityPair == null)
- {
+ {
return null;
- }
+ }
return entityPair.getSecond();
- }
-
- /**
- * {@inheritDoc}
- */
- public AVMStoreEntity getStoreByRoot(long rootNodeId)
- {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public AVMStoreEntity getStoreByRoot(long rootNodeId)
+ {
// TODO review - not via cache
return getStoreEntityByRoot(rootNodeId);
- }
-
- /**
- * {@inheritDoc}
- */
- public AVMStoreEntity getStore(String name)
- {
- ParameterCheck.mandatory("name", name);
-
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public AVMStoreEntity getStore(String name)
+ {
+ ParameterCheck.mandatory("name", name);
+
AVMStoreEntity storeEntity = new AVMStoreEntity();
storeEntity.setName(name);
@@ -177,52 +177,51 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
return null;
}
return entityPair.getSecond();
- }
-
- /**
- * {@inheritDoc}
- */
- public List getAllStores()
- {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List getAllStores()
+ {
// not via cache
return getAllStoreEntities();
- }
-
- /**
- * {@inheritDoc}
- */
- public void updateStore(AVMStoreEntity storeEntity)
- {
- ParameterCheck.mandatory("storeEntity", storeEntity);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void updateStore(AVMStoreEntity storeEntity)
+ {
+ ParameterCheck.mandatory("storeEntity", storeEntity);
ParameterCheck.mandatory("storeEntity.getId()", storeEntity.getId());
ParameterCheck.mandatory("storeEntity.getVers()", storeEntity.getVers());
-
+
int updated = avmStoreCache.updateValue(storeEntity.getId(), storeEntity);
if (updated < 1)
{
throw new ConcurrencyFailureException("AVMStore with ID (" + storeEntity.getId() + ") no longer exists or has been updated concurrently");
}
- storeEntity.setVers(storeEntity.getVers()+1);
- }
-
- /**
- * {@inheritDoc}
- */
- public void deleteStore(long storeId)
- {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void deleteStore(long storeId)
+ {
Pair entityPair = avmStoreCache.getByKey(storeId);
if (entityPair == null)
- {
- return;
- }
-
+ {
+ return;
+ }
+
int deleted = avmStoreCache.deleteByKey(storeId);
- if (deleted < 1)
- {
- throw new ConcurrencyFailureException("AVMStore with ID " + storeId + " no longer exists");
- }
- }
-
+ if (deleted < 1)
+ {
+ throw new ConcurrencyFailureException("AVMStore with ID " + storeId + " no longer exists");
+ }
+ }
+
/**
* Callback for avm_stores DAO
*/
@@ -291,22 +290,22 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
avmStoreCache.clear();
}
- protected abstract AVMStoreEntity getStoreEntity(long id);
- protected abstract AVMStoreEntity getStoreEntity(String name);
- protected abstract AVMStoreEntity getStoreEntityByRoot(long rootNodeId);
- protected abstract List getAllStoreEntities();
+ protected abstract AVMStoreEntity getStoreEntity(long id);
+ protected abstract AVMStoreEntity getStoreEntity(String name);
+ protected abstract AVMStoreEntity getStoreEntityByRoot(long rootNodeId);
+ protected abstract List getAllStoreEntities();
protected abstract AVMStoreEntity createStoreEntity(AVMStoreEntity storeEntity);
- protected abstract int deleteStoreEntity(long id);
+ protected abstract int deleteStoreEntity(long id);
protected abstract int updateStoreEntity(AVMStoreEntity storeEntity);
-
+
/**
* {@inheritDoc}
*/
public void createOrUpdateStoreProperty(long storeId, QName qname, PropertyValue value)
- {
+ {
ParameterCheck.mandatory("qname", qname);
ParameterCheck.mandatory("value", value);
-
+
// Get the persistent ID for the QName
Pair qnamePair = qnameDAO.getOrCreateQName(qname);
Long qnameId = qnamePair.getFirst();
@@ -317,24 +316,24 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
Pair, AVMStorePropertyEntity> entityPair = avmStorePropCache.getByKey(key);
if (entityPair != null)
- {
+ {
int updated = avmStorePropCache.updateValue(key, propEntity);
if (updated < 1)
{
throw new ConcurrencyFailureException("AVMStorePropertyEntity with IDs (" + propEntity.getAvmStoreId() + ", " + propEntity.getQnameId() + ") no longer exists");
}
- }
- else
- {
+ }
+ else
+ {
avmStorePropCache.getOrCreateByValue(propEntity);
- }
- }
-
+ }
+ }
+
/**
* {@inheritDoc}
*/
public PropertyValue getStoreProperty(long storeId, QName qname)
- {
+ {
// Get the persistent ID for the QName
Pair qnamePair = qnameDAO.getQName(qname);
if (qnamePair != null)
@@ -350,13 +349,13 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
return entityPair.getSecond();
}
return null;
- }
-
+ }
+
/**
* {@inheritDoc}
*/
public Map getStoreProperties(long storeId)
- {
+ {
// not via cache
List propEntities = getStorePropertyEntities(storeId);
@@ -370,16 +369,16 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
}
}
return props;
- }
-
+ }
+
/**
* {@inheritDoc}
*/
public Map> getStorePropertiesByKeyPattern(String uriPattern, String localNamePattern)
- {
- ParameterCheck.mandatoryString("uriPattern", uriPattern);
- ParameterCheck.mandatoryString("localNamePattern", localNamePattern);
-
+ {
+ ParameterCheck.mandatoryString("uriPattern", uriPattern);
+ ParameterCheck.mandatoryString("localNamePattern", localNamePattern);
+
// not via cache
List spEntities = getStorePropertyEntitiesByKeyPattern(uriPattern, localNamePattern);
@@ -405,16 +404,16 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
}
return results;
- }
-
+ }
+
/**
* {@inheritDoc}
*/
public Map getStorePropertiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern)
- {
- ParameterCheck.mandatoryString("uriPattern", uriPattern);
- ParameterCheck.mandatoryString("localNamePattern", localNamePattern);
-
+ {
+ ParameterCheck.mandatoryString("uriPattern", uriPattern);
+ ParameterCheck.mandatoryString("localNamePattern", localNamePattern);
+
// not via cache
List propEntities = getStorePropertyEntitiesByStoreAndKeyPattern(storeId, uriPattern, localNamePattern);
@@ -428,17 +427,17 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
}
}
return props;
- }
-
+ }
+
/**
* {@inheritDoc}
*/
public void deleteStoreProperty(long storeId, QName qname)
- {
+ {
// Get the persistent ID for the QName
Pair qnamePair = qnameDAO.getQName(qname);
if (qnamePair != null)
- {
+ {
Long qnameId = qnamePair.getFirst();
Pair key = new Pair(storeId, qnameId);
@@ -453,20 +452,20 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
{
throw new ConcurrencyFailureException("AVMStoreProperty with key (" + storeId + ", " + qnameId + ") no longer exists");
}
- }
- }
-
+ }
+ }
+
/**
* {@inheritDoc}
*/
- public void deleteStoreProperties(long storeId)
- {
+ public void deleteStoreProperties(long storeId)
+ {
Map props = getStoreProperties(storeId);
if (props.size() == 0)
- {
- return;
- }
-
+ {
+ return;
+ }
+
for (QName qname : props.keySet())
{
deleteStoreProperty(storeId, qname);
@@ -475,16 +474,16 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
// TODO single delete + cache(s)
/*
- int deleted = deleteStorePropertyEntities(storeId);
- if (deleted < 1)
- {
- throw new ConcurrencyFailureException("AVMStoreProperties for store ID " + storeId + " no longer exist");
- }
+ int deleted = deleteStorePropertyEntities(storeId);
+ if (deleted < 1)
+ {
+ throw new ConcurrencyFailureException("AVMStoreProperties for store ID " + storeId + " no longer exist");
+ }
// TODO clear store property cache for this store id
*/
- }
-
+ }
+
/**
* Callback for avm_store_properties DAO
*/
@@ -545,12 +544,12 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
}
}
- protected abstract void insertStorePropertyEntity(AVMStorePropertyEntity propEntity);
+ protected abstract void insertStorePropertyEntity(AVMStorePropertyEntity propEntity);
protected abstract int updateStorePropertyEntity(AVMStorePropertyEntity propEntity);
- protected abstract AVMStorePropertyEntity getStorePropertyEntity(long storeId, long qnameId);
- protected abstract List getStorePropertyEntities(long storeId);
- protected abstract List getStorePropertyEntitiesByKeyPattern(String uriPattern, String localNamePattern);
- protected abstract List getStorePropertyEntitiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern);
- protected abstract int deleteStorePropertyEntity(long storeId, long qnameId);
- protected abstract int deleteStorePropertyEntities(long storeId);
-}
+ protected abstract AVMStorePropertyEntity getStorePropertyEntity(long storeId, long qnameId);
+ protected abstract List getStorePropertyEntities(long storeId);
+ protected abstract List getStorePropertyEntitiesByKeyPattern(String uriPattern, String localNamePattern);
+ protected abstract List getStorePropertyEntitiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern);
+ protected abstract int deleteStorePropertyEntity(long storeId, long qnameId);
+ protected abstract int deleteStorePropertyEntities(long storeId);
+}
diff --git a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java
index 20efa87660..061fb4e4bc 100644
--- a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMNodeDAOImpl.java
@@ -104,12 +104,16 @@ public class AVMNodeDAOImpl extends AbstractAVMNodeDAOImpl
@Override
protected int updateNodeEntity(AVMNodeEntity updateNodeEntity)
{
+ updateNodeEntity.incrementVers();
+
return template.update(UPDATE_AVM_NODE, updateNodeEntity);
}
@Override
protected int updateNodeEntityModTimeAndGuid(AVMNodeEntity updateNodeEntity)
{
+ updateNodeEntity.incrementVers();
+
// partial update
return template.update(UPDATE_AVM_NODE_MODTIME_AND_GUID, updateNodeEntity);
}
@@ -117,6 +121,8 @@ public class AVMNodeDAOImpl extends AbstractAVMNodeDAOImpl
@Override
protected int updateNodeEntityModTimeAndContentData(AVMNodeEntity updateNodeEntity)
{
+ updateNodeEntity.incrementVers();
+
// partial update
return template.update(UPDATE_AVM_NODE_MODTIME_AND_CDATA, updateNodeEntity);
}
diff --git a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java
index 9aa26161aa..f1166ea1bc 100644
--- a/source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/avm/ibatis/AVMStoreDAOImpl.java
@@ -109,6 +109,8 @@ public class AVMStoreDAOImpl extends AbstractAVMStoreDAOImpl
@Override
protected int updateStoreEntity(AVMStoreEntity updateStoreEntity)
{
+ updateStoreEntity.incrementVers();
+
return template.update(UPDATE_AVM_STORE, updateStoreEntity);
}