AVM DAO - add rollover for avm_store/avm_node "vers" col

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16992 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2009-10-16 16:26:54 +00:00
parent 0e9e98d6cd
commit 3731cb9b42
8 changed files with 299 additions and 233 deletions

View File

@@ -312,10 +312,12 @@
name = #name#, name = #name#,
current_root_id = #rootNodeId#, current_root_id = #rootNodeId#,
acl_id = #aclId#, acl_id = #aclId#,
vers = (#vers# + 1)
where
id = #id# and
vers = #vers# vers = #vers#
where
id = #id#
<isGreaterThan property="vers" compareValue="1">
and vers = (#vers#-1)
</isGreaterThan>
</update> </update>
<!-- Delete AVMStore --> <!-- Delete AVMStore -->
@@ -525,10 +527,12 @@
encoding = #encoding#, encoding = #encoding#,
length = #length#, length = #length#,
guid = #guid#, guid = #guid#,
vers = (#vers# + 1)
where
id = #id# and
vers = #vers# vers = #vers#
where
id = #id#
<isGreaterThan property="vers" compareValue="1">
and vers = (#vers#-1)
</isGreaterThan>
</update> </update>
<update id="update_AVMNode_modTimeAndGuid" parameterClass="AVMNode"> <update id="update_AVMNode_modTimeAndGuid" parameterClass="AVMNode">
@@ -537,10 +541,12 @@
set set
modDate = #modifiedDate#, modDate = #modifiedDate#,
guid = #guid#, guid = #guid#,
vers = (#vers# + 1)
where
id = #id# and
vers = #vers# vers = #vers#
where
id = #id#
<isGreaterThan property="vers" compareValue="1">
and vers = (#vers#-1)
</isGreaterThan>
</update> </update>
<update id="update_AVMNode_modTimeAndContentData" parameterClass="AVMNode"> <update id="update_AVMNode_modTimeAndContentData" parameterClass="AVMNode">
@@ -552,10 +558,12 @@
mime_type = #mimetype#, mime_type = #mimetype#,
encoding = #encoding#, encoding = #encoding#,
length = #length#, length = #length#,
vers = (#vers# + 1)
where
id = #id# and
vers = #vers# vers = #vers#
where
id = #id#
<isGreaterThan property="vers" compareValue="1">
and vers = (#vers#-1)
</isGreaterThan>
</update> </update>
<delete id="delete_AVMNode" parameterMap="parameter_IdMap"> <delete id="delete_AVMNode" parameterMap="parameter_IdMap">

View File

@@ -64,8 +64,8 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID; import org.alfresco.util.GUID;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
* A Repository contains a current root directory and a list of * A Repository contains a current root directory and a list of
@@ -75,7 +75,7 @@ import org.apache.commons.logging.LogFactory;
*/ */
public class AVMStoreImpl implements AVMStore public class AVMStoreImpl implements AVMStore
{ {
private static Log fgLogger = LogFactory.getLog(AVMStoreImpl.class); private static Log logger = LogFactory.getLog(AVMStoreImpl.class);
/** /**
* The primary key. * The primary key.
*/ */
@@ -198,6 +198,8 @@ public class AVMStoreImpl implements AVMStore
*/ */
public Map<String, Integer> createSnapshot(String tag, String description, Map<String, Integer> snapShotMap) public Map<String, Integer> createSnapshot(String tag, String description, Map<String, Integer> snapShotMap)
{ {
long start = System.currentTimeMillis();
long rootID = getRoot().getId(); long rootID = getRoot().getId();
AVMStoreImpl me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(getId()); AVMStoreImpl me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(getId());
VersionRoot lastVersion = AVMDAOs.Instance().fVersionRootDAO.getMaxVersion(me); VersionRoot lastVersion = AVMDAOs.Instance().fVersionRootDAO.getMaxVersion(me);
@@ -207,6 +209,11 @@ public class AVMStoreImpl implements AVMStore
DirectoryNode root = (DirectoryNode)AVMDAOs.Instance().fAVMNodeDAO.getByID(rootID); DirectoryNode root = (DirectoryNode)AVMDAOs.Instance().fAVMNodeDAO.getByID(rootID);
if (!root.getIsNew() && layeredEntries.size() == 0) if (!root.getIsNew() && layeredEntries.size() == 0)
{ {
if (logger.isTraceEnabled())
{
logger.trace("createSnapshot: no snapshot required: "+me.getName()+" ["+me.getId()+"] - lastVersion = "+lastVersion.getVersionID() + "("+tag+", "+description+")");
}
// So, we set the tag and description fields of the latest version. // So, we set the tag and description fields of the latest version.
if (tag != null || description != null) if (tag != null || description != null)
{ {
@@ -218,6 +225,12 @@ public class AVMStoreImpl implements AVMStore
snapShotMap.put(getName(), lastVersion.getVersionID()); snapShotMap.put(getName(), lastVersion.getVersionID());
return snapShotMap; return snapShotMap;
} }
if (logger.isTraceEnabled())
{
logger.trace("createSnapshot: snapshot: "+me.getName()+" ["+me.getId()+"] - lastVersion="+lastVersion.getVersionID()+", layeredEntries="+layeredEntries.size());
}
snapShotMap.put(getName(), me.getNextVersionID()); snapShotMap.put(getName(), me.getNextVersionID());
// Force copies on all the layered nodes from last snapshot. // Force copies on all the layered nodes from last snapshot.
for (VersionLayeredNodeEntry entry : layeredEntries) for (VersionLayeredNodeEntry entry : layeredEntries)
@@ -241,13 +254,14 @@ public class AVMStoreImpl implements AVMStore
if (lookup.getCurrentNode().getType() == AVMNodeType.LAYERED_DIRECTORY) if (lookup.getCurrentNode().getType() == AVMNodeType.LAYERED_DIRECTORY)
{ {
fAVMRepository.forceCopy(entry.getPath()); fAVMRepository.forceCopy(entry.getPath());
me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(getId());
} }
else if (lookup.getCurrentNode().getType() == AVMNodeType.LAYERED_FILE) else if (lookup.getCurrentNode().getType() == AVMNodeType.LAYERED_FILE)
{ {
String parentName[] = AVMUtil.splitBase(entry.getPath()); String parentName[] = AVMUtil.splitBase(entry.getPath());
parentName[0] = parentName[0].substring(parentName[0].indexOf(':') + 1); parentName[0] = parentName[0].substring(parentName[0].indexOf(':') + 1);
lookup = lookupDirectory(-1, parentName[0], true); lookup = me.lookupDirectory(-1, parentName[0], true);
DirectoryNode parent = (DirectoryNode)lookup.getCurrentNode(); DirectoryNode parent = (DirectoryNode)lookup.getCurrentNode();
Pair<AVMNode, Boolean> temp = parent.lookupChild(lookup, parentName[1], false); Pair<AVMNode, Boolean> temp = parent.lookupChild(lookup, parentName[1], false);
@@ -337,6 +351,7 @@ public class AVMStoreImpl implements AVMStore
{ {
user = RawServices.Instance().getAuthenticationContext().getSystemUserName(); user = RawServices.Instance().getAuthenticationContext().getSystemUserName();
} }
me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(getId()); me = (AVMStoreImpl)AVMDAOs.Instance().fAVMStoreDAO.getByID(getId());
VersionRoot versionRoot = new VersionRootImpl(me, VersionRoot versionRoot = new VersionRootImpl(me,
me.getRoot(), me.getRoot(),
@@ -350,6 +365,8 @@ public class AVMStoreImpl implements AVMStore
AVMDAOs.Instance().fAVMStoreDAO.update(me); AVMDAOs.Instance().fAVMStoreDAO.update(me);
int vlneCnt = 0;
AVMDAOs.Instance().fVersionRootDAO.save(versionRoot); AVMDAOs.Instance().fVersionRootDAO.save(versionRoot);
for (Long nodeID : layeredNodeIDs) for (Long nodeID : layeredNodeIDs)
{ {
@@ -361,7 +378,20 @@ public class AVMStoreImpl implements AVMStore
new VersionLayeredNodeEntryImpl(versionRoot, path); new VersionLayeredNodeEntryImpl(versionRoot, path);
AVMDAOs.Instance().fVersionLayeredNodeEntryDAO.save(entry); AVMDAOs.Instance().fVersionLayeredNodeEntryDAO.save(entry);
} }
vlneCnt = vlneCnt+paths.size();
} }
if (logger.isTraceEnabled())
{
logger.trace("createSnapshot: snapshot: "+me.getName()+" ["+me.getId()+"] - created new version root ["+versionRoot.getId()+"] - layeredNodeIDs="+layeredNodeIDs.size()+", versionLayeredNodeEntries="+vlneCnt);
}
if (logger.isDebugEnabled())
{
logger.debug("createSnapshot: snapshot: "+me.getName()+" ["+me.getId()+"] in "+(System.currentTimeMillis()-start)+" msecs");
}
return snapShotMap; return snapShotMap;
} }
@@ -589,38 +619,38 @@ public class AVMStoreImpl implements AVMStore
{ {
throw new AVMExistsException("Child exists: " + name); throw new AVMExistsException("Child exists: " + name);
} }
// TODO Reexamine decision to not check validity of srcPath. Warning for now. // TODO Reexamine decision to not check validity of srcPath. Warning for now.
String[] srcPathParts = srcPath.split(":"); String[] srcPathParts = srcPath.split(":");
String[] dstPathParts = dstPath.split(":"); String[] dstPathParts = dstPath.split(":");
Lookup lPathSrc = null; Lookup lPathSrc = null;
if (srcPathParts[0].equals(dstPathParts[0])) if (srcPathParts[0].equals(dstPathParts[0]))
{ {
lPathSrc = lookup(-1, srcPathParts[1], false, false); lPathSrc = lookup(-1, srcPathParts[1], false, false);
} }
else else
{ {
AVMStore srcStore = AVMDAOs.Instance().fAVMStoreDAO.getByName(srcPathParts[0]); AVMStore srcStore = AVMDAOs.Instance().fAVMStoreDAO.getByName(srcPathParts[0]);
if (srcStore != null) if (srcStore != null)
{ {
lPathSrc = srcStore.lookup(-1, srcPathParts[1], false, false); lPathSrc = srcStore.lookup(-1, srcPathParts[1], false, false);
} }
} }
AVMNode srcNode = null; AVMNode srcNode = null;
if (lPathSrc == null) if (lPathSrc == null)
{ {
fgLogger.warn("CreateLayeredFile: srcPath not found: "+srcPath); logger.warn("CreateLayeredFile: srcPath not found: "+srcPath);
} }
else else
{ {
srcNode = (AVMNode)lPathSrc.getCurrentNode(); srcNode = (AVMNode)lPathSrc.getCurrentNode();
if (! (srcNode instanceof FileNode)) if (! (srcNode instanceof FileNode))
{ {
fgLogger.warn("CreateLayeredFile: srcPath is not a file: "+srcPath); logger.warn("CreateLayeredFile: srcPath is not a file: "+srcPath);
} }
} }
LayeredFileNodeImpl newFile = LayeredFileNodeImpl newFile =
new LayeredFileNodeImpl(srcPath, this, null); new LayeredFileNodeImpl(srcPath, this, null);
@@ -633,12 +663,12 @@ public class AVMStoreImpl implements AVMStore
{ {
newFile.setAncestor(child); newFile.setAncestor(child);
} }
else else
{ {
if ((srcNode != null) && (srcNode instanceof FileNode)) if ((srcNode != null) && (srcNode instanceof FileNode))
{ {
newFile.setAncestor((FileNode)srcNode); newFile.setAncestor((FileNode)srcNode);
} }
} }
// newFile.setVersionID(getNextVersionID()); // newFile.setVersionID(getNextVersionID());
@@ -805,24 +835,24 @@ public class AVMStoreImpl implements AVMStore
{ {
throw new AVMNotFoundException("Path " + path + " not found."); throw new AVMNotFoundException("Path " + path + " not found.");
} }
DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode(); DirectoryNode dir = (DirectoryNode)lPath.getCurrentNode();
Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, false); Pair<AVMNode, Boolean> temp = dir.lookupChild(lPath, name, false);
AVMNode child = (temp == null) ? null : temp.getFirst(); AVMNode child = (temp == null) ? null : temp.getFirst();
if (child == null) if (child == null)
{ {
Lookup lPathToChild = lookup(-1, path+"/"+name, true, false); Lookup lPathToChild = lookup(-1, path+"/"+name, true, false);
if (lPathToChild != null) if (lPathToChild != null)
{ {
// ETHREEOH-2297 // ETHREEOH-2297
child = lPathToChild.getCurrentNode(); child = lPathToChild.getCurrentNode();
} }
if (child == null) if (child == null)
{ {
throw new AVMNotFoundException("Does not exist: " + name); throw new AVMNotFoundException("Does not exist: " + name);
} }
dir = lPathToChild.getCurrentNodeDirectory(); dir = lPathToChild.getCurrentNodeDirectory();
} }
if (!fAVMRepository.can(this, child, PermissionService.DELETE_NODE, false)) if (!fAVMRepository.can(this, child, PermissionService.DELETE_NODE, false))
@@ -1772,14 +1802,14 @@ public class AVMStoreImpl implements AVMStore
Lookup cPath = new Lookup(lPath, AVMDAOs.Instance().fAVMNodeDAO, AVMDAOs.Instance().fAVMStoreDAO); Lookup cPath = new Lookup(lPath, AVMDAOs.Instance().fAVMNodeDAO, AVMDAOs.Instance().fAVMStoreDAO);
Pair<AVMNode, Boolean> result = dir.lookupChild(cPath, name, true); Pair<AVMNode, Boolean> result = dir.lookupChild(cPath, name, true);
if (result != null) if (result != null)
{ {
AVMNode child = result.getFirst(); AVMNode child = result.getFirst();
if (!fAVMRepository.can(null, child, PermissionService.WRITE, cPath.getDirectlyContained())) if (!fAVMRepository.can(null, child, PermissionService.WRITE, cPath.getDirectlyContained()))
{ {
throw new AccessDeniedException("Not allowed to update node: " + parentPath + "/" +name ); throw new AccessDeniedException("Not allowed to update node: " + parentPath + "/" +name );
} }
dir.removeChild(lPath, name); dir.removeChild(lPath, name);
} }
dir.link(lPath, name, toLink); dir.link(lPath, name, toLink);
} }

View File

@@ -373,6 +373,18 @@ public class AVMNodeEntity
this.vers = vers; this.vers = vers;
} }
public void incrementVers()
{
if (this.vers >= Long.MAX_VALUE)
{
this.vers = 0L;
}
else
{
this.vers++;
}
}
@Override @Override
public int hashCode() public int hashCode()
{ {

View File

@@ -103,6 +103,18 @@ public class AVMStoreEntity
this.vers = vers; this.vers = vers;
} }
public void incrementVers()
{
if (this.vers >= Long.MAX_VALUE)
{
this.vers = 0L;
}
else
{
this.vers++;
}
}
@Override @Override
public int hashCode() public int hashCode()
{ {

View File

@@ -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"); 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"); throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently");
} }
nodeEntity.setVers(nodeEntity.getVers()+1);
// update cache // update cache
avmNodeCache.removeByKey(nodeEntity.getId()); 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"); throw new ConcurrencyFailureException("AVMNode with ID (" + nodeEntity.getId() + ") no longer exists or has been updated concurrently");
} }
nodeEntity.setVers(nodeEntity.getVers()+1);
// update cache // update cache
avmNodeCache.removeByKey(nodeEntity.getId()); avmNodeCache.removeByKey(nodeEntity.getId());

View File

@@ -1,34 +1,34 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.domain.avm; package org.alfresco.repo.domain.avm;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.cache.SimpleCache; import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.cache.lookup.EntityLookupCache; 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.repo.domain.QNameDAO;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.ConcurrencyFailureException;
/** /**
* Abstract implementation for AVMStore DAO. * Abstract implementation for AVMStore DAO.
* <p> * <p>
* This provides basic services such as caching but defers to the underlying implementation * This provides basic services such as caching but defers to the underlying implementation
* for CRUD operations. * for CRUD operations.
* *
* @author janv * @author janv
* @since 3.2 * @since 3.2
*/ */
public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
{ {
private static final String CACHE_REGION_AVM_STORE = "AVMStore"; private static final String CACHE_REGION_AVM_STORE = "AVMStore";
private static final String CACHE_REGION_AVM_STORE_PROP = "AVMStoreProp"; private static final String CACHE_REGION_AVM_STORE_PROP = "AVMStoreProp";
@@ -59,7 +59,7 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
private QNameDAO qnameDAO; private QNameDAO qnameDAO;
/** /**
* Cache for the AVM store entity:<br/> * Cache for the AVM store entity:<br/>
* KEY: ID<br/> * KEY: ID<br/>
* VALUE: AVMStoreEntity<br/> * VALUE: AVMStoreEntity<br/>
@@ -123,8 +123,8 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public AVMStoreEntity createStore(String name) public AVMStoreEntity createStore(String name)
{ {
ParameterCheck.mandatory("name", name); ParameterCheck.mandatory("name", name);
@@ -143,31 +143,31 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
* {@inheritDoc} * {@inheritDoc}
*/ */
public AVMStoreEntity getStore(long storeId) public AVMStoreEntity getStore(long storeId)
{ {
Pair<Long, AVMStoreEntity> entityPair = avmStoreCache.getByKey(storeId); Pair<Long, AVMStoreEntity> entityPair = avmStoreCache.getByKey(storeId);
if (entityPair == null) if (entityPair == null)
{ {
return null; return null;
} }
return entityPair.getSecond(); return entityPair.getSecond();
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public AVMStoreEntity getStoreByRoot(long rootNodeId) public AVMStoreEntity getStoreByRoot(long rootNodeId)
{ {
// TODO review - not via cache // TODO review - not via cache
return getStoreEntityByRoot(rootNodeId); return getStoreEntityByRoot(rootNodeId);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public AVMStoreEntity getStore(String name) public AVMStoreEntity getStore(String name)
{ {
ParameterCheck.mandatory("name", name); ParameterCheck.mandatory("name", name);
AVMStoreEntity storeEntity = new AVMStoreEntity(); AVMStoreEntity storeEntity = new AVMStoreEntity();
storeEntity.setName(name); storeEntity.setName(name);
@@ -177,52 +177,51 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
return null; return null;
} }
return entityPair.getSecond(); return entityPair.getSecond();
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public List<AVMStoreEntity> getAllStores() public List<AVMStoreEntity> getAllStores()
{ {
// not via cache // not via cache
return getAllStoreEntities(); return getAllStoreEntities();
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void updateStore(AVMStoreEntity storeEntity) public void updateStore(AVMStoreEntity storeEntity)
{ {
ParameterCheck.mandatory("storeEntity", storeEntity); ParameterCheck.mandatory("storeEntity", storeEntity);
ParameterCheck.mandatory("storeEntity.getId()", storeEntity.getId()); ParameterCheck.mandatory("storeEntity.getId()", storeEntity.getId());
ParameterCheck.mandatory("storeEntity.getVers()", storeEntity.getVers()); ParameterCheck.mandatory("storeEntity.getVers()", storeEntity.getVers());
int updated = avmStoreCache.updateValue(storeEntity.getId(), storeEntity); int updated = avmStoreCache.updateValue(storeEntity.getId(), storeEntity);
if (updated < 1) if (updated < 1)
{ {
throw new ConcurrencyFailureException("AVMStore with ID (" + storeEntity.getId() + ") no longer exists or has been updated concurrently"); throw new ConcurrencyFailureException("AVMStore with ID (" + storeEntity.getId() + ") no longer exists or has been updated concurrently");
} }
storeEntity.setVers(storeEntity.getVers()+1); }
}
/**
/** * {@inheritDoc}
* {@inheritDoc} */
*/ public void deleteStore(long storeId)
public void deleteStore(long storeId) {
{
Pair<Long, AVMStoreEntity> entityPair = avmStoreCache.getByKey(storeId); Pair<Long, AVMStoreEntity> entityPair = avmStoreCache.getByKey(storeId);
if (entityPair == null) if (entityPair == null)
{ {
return; return;
} }
int deleted = avmStoreCache.deleteByKey(storeId); int deleted = avmStoreCache.deleteByKey(storeId);
if (deleted < 1) if (deleted < 1)
{ {
throw new ConcurrencyFailureException("AVMStore with ID " + storeId + " no longer exists"); throw new ConcurrencyFailureException("AVMStore with ID " + storeId + " no longer exists");
} }
} }
/** /**
* Callback for <b>avm_stores</b> DAO * Callback for <b>avm_stores</b> DAO
*/ */
@@ -291,22 +290,22 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
avmStoreCache.clear(); avmStoreCache.clear();
} }
protected abstract AVMStoreEntity getStoreEntity(long id); protected abstract AVMStoreEntity getStoreEntity(long id);
protected abstract AVMStoreEntity getStoreEntity(String name); protected abstract AVMStoreEntity getStoreEntity(String name);
protected abstract AVMStoreEntity getStoreEntityByRoot(long rootNodeId); protected abstract AVMStoreEntity getStoreEntityByRoot(long rootNodeId);
protected abstract List<AVMStoreEntity> getAllStoreEntities(); protected abstract List<AVMStoreEntity> getAllStoreEntities();
protected abstract AVMStoreEntity createStoreEntity(AVMStoreEntity storeEntity); protected abstract AVMStoreEntity createStoreEntity(AVMStoreEntity storeEntity);
protected abstract int deleteStoreEntity(long id); protected abstract int deleteStoreEntity(long id);
protected abstract int updateStoreEntity(AVMStoreEntity storeEntity); protected abstract int updateStoreEntity(AVMStoreEntity storeEntity);
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void createOrUpdateStoreProperty(long storeId, QName qname, PropertyValue value) public void createOrUpdateStoreProperty(long storeId, QName qname, PropertyValue value)
{ {
ParameterCheck.mandatory("qname", qname); ParameterCheck.mandatory("qname", qname);
ParameterCheck.mandatory("value", value); ParameterCheck.mandatory("value", value);
// Get the persistent ID for the QName // Get the persistent ID for the QName
Pair<Long, QName> qnamePair = qnameDAO.getOrCreateQName(qname); Pair<Long, QName> qnamePair = qnameDAO.getOrCreateQName(qname);
Long qnameId = qnamePair.getFirst(); Long qnameId = qnamePair.getFirst();
@@ -317,24 +316,24 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
Pair<Pair<Long, Long>, AVMStorePropertyEntity> entityPair = avmStorePropCache.getByKey(key); Pair<Pair<Long, Long>, AVMStorePropertyEntity> entityPair = avmStorePropCache.getByKey(key);
if (entityPair != null) if (entityPair != null)
{ {
int updated = avmStorePropCache.updateValue(key, propEntity); int updated = avmStorePropCache.updateValue(key, propEntity);
if (updated < 1) if (updated < 1)
{ {
throw new ConcurrencyFailureException("AVMStorePropertyEntity with IDs (" + propEntity.getAvmStoreId() + ", " + propEntity.getQnameId() + ") no longer exists"); throw new ConcurrencyFailureException("AVMStorePropertyEntity with IDs (" + propEntity.getAvmStoreId() + ", " + propEntity.getQnameId() + ") no longer exists");
} }
} }
else else
{ {
avmStorePropCache.getOrCreateByValue(propEntity); avmStorePropCache.getOrCreateByValue(propEntity);
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public PropertyValue getStoreProperty(long storeId, QName qname) public PropertyValue getStoreProperty(long storeId, QName qname)
{ {
// Get the persistent ID for the QName // Get the persistent ID for the QName
Pair<Long, QName> qnamePair = qnameDAO.getQName(qname); Pair<Long, QName> qnamePair = qnameDAO.getQName(qname);
if (qnamePair != null) if (qnamePair != null)
@@ -350,13 +349,13 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
return entityPair.getSecond(); return entityPair.getSecond();
} }
return null; return null;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public Map<QName, PropertyValue> getStoreProperties(long storeId) public Map<QName, PropertyValue> getStoreProperties(long storeId)
{ {
// not via cache // not via cache
List<AVMStorePropertyEntity> propEntities = getStorePropertyEntities(storeId); List<AVMStorePropertyEntity> propEntities = getStorePropertyEntities(storeId);
@@ -370,16 +369,16 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
} }
} }
return props; return props;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public Map<String, Map<QName, PropertyValue>> getStorePropertiesByKeyPattern(String uriPattern, String localNamePattern) public Map<String, Map<QName, PropertyValue>> getStorePropertiesByKeyPattern(String uriPattern, String localNamePattern)
{ {
ParameterCheck.mandatoryString("uriPattern", uriPattern); ParameterCheck.mandatoryString("uriPattern", uriPattern);
ParameterCheck.mandatoryString("localNamePattern", localNamePattern); ParameterCheck.mandatoryString("localNamePattern", localNamePattern);
// not via cache // not via cache
List<AVMStorePropertyEntity> spEntities = getStorePropertyEntitiesByKeyPattern(uriPattern, localNamePattern); List<AVMStorePropertyEntity> spEntities = getStorePropertyEntitiesByKeyPattern(uriPattern, localNamePattern);
@@ -405,16 +404,16 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
} }
return results; return results;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public Map<QName, PropertyValue> getStorePropertiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern) public Map<QName, PropertyValue> getStorePropertiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern)
{ {
ParameterCheck.mandatoryString("uriPattern", uriPattern); ParameterCheck.mandatoryString("uriPattern", uriPattern);
ParameterCheck.mandatoryString("localNamePattern", localNamePattern); ParameterCheck.mandatoryString("localNamePattern", localNamePattern);
// not via cache // not via cache
List<AVMStorePropertyEntity> propEntities = getStorePropertyEntitiesByStoreAndKeyPattern(storeId, uriPattern, localNamePattern); List<AVMStorePropertyEntity> propEntities = getStorePropertyEntitiesByStoreAndKeyPattern(storeId, uriPattern, localNamePattern);
@@ -428,17 +427,17 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
} }
} }
return props; return props;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void deleteStoreProperty(long storeId, QName qname) public void deleteStoreProperty(long storeId, QName qname)
{ {
// Get the persistent ID for the QName // Get the persistent ID for the QName
Pair<Long, QName> qnamePair = qnameDAO.getQName(qname); Pair<Long, QName> qnamePair = qnameDAO.getQName(qname);
if (qnamePair != null) if (qnamePair != null)
{ {
Long qnameId = qnamePair.getFirst(); Long qnameId = qnamePair.getFirst();
Pair<Long, Long> key = new Pair<Long, Long>(storeId, qnameId); Pair<Long, Long> key = new Pair<Long, Long>(storeId, qnameId);
@@ -453,20 +452,20 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
{ {
throw new ConcurrencyFailureException("AVMStoreProperty with key (" + storeId + ", " + qnameId + ") no longer exists"); throw new ConcurrencyFailureException("AVMStoreProperty with key (" + storeId + ", " + qnameId + ") no longer exists");
} }
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void deleteStoreProperties(long storeId) public void deleteStoreProperties(long storeId)
{ {
Map<QName, PropertyValue> props = getStoreProperties(storeId); Map<QName, PropertyValue> props = getStoreProperties(storeId);
if (props.size() == 0) if (props.size() == 0)
{ {
return; return;
} }
for (QName qname : props.keySet()) for (QName qname : props.keySet())
{ {
deleteStoreProperty(storeId, qname); deleteStoreProperty(storeId, qname);
@@ -475,16 +474,16 @@ public abstract class AbstractAVMStoreDAOImpl implements AVMStoreDAO
// TODO single delete + cache(s) // TODO single delete + cache(s)
/* /*
int deleted = deleteStorePropertyEntities(storeId); int deleted = deleteStorePropertyEntities(storeId);
if (deleted < 1) if (deleted < 1)
{ {
throw new ConcurrencyFailureException("AVMStoreProperties for store ID " + storeId + " no longer exist"); throw new ConcurrencyFailureException("AVMStoreProperties for store ID " + storeId + " no longer exist");
} }
// TODO clear store property cache for this store id // TODO clear store property cache for this store id
*/ */
} }
/** /**
* Callback for <b>avm_store_properties</b> DAO * Callback for <b>avm_store_properties</b> 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 int updateStorePropertyEntity(AVMStorePropertyEntity propEntity);
protected abstract AVMStorePropertyEntity getStorePropertyEntity(long storeId, long qnameId); protected abstract AVMStorePropertyEntity getStorePropertyEntity(long storeId, long qnameId);
protected abstract List<AVMStorePropertyEntity> getStorePropertyEntities(long storeId); protected abstract List<AVMStorePropertyEntity> getStorePropertyEntities(long storeId);
protected abstract List<AVMStorePropertyEntity> getStorePropertyEntitiesByKeyPattern(String uriPattern, String localNamePattern); protected abstract List<AVMStorePropertyEntity> getStorePropertyEntitiesByKeyPattern(String uriPattern, String localNamePattern);
protected abstract List<AVMStorePropertyEntity> getStorePropertyEntitiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern); protected abstract List<AVMStorePropertyEntity> getStorePropertyEntitiesByStoreAndKeyPattern(long storeId, String uriPattern, String localNamePattern);
protected abstract int deleteStorePropertyEntity(long storeId, long qnameId); protected abstract int deleteStorePropertyEntity(long storeId, long qnameId);
protected abstract int deleteStorePropertyEntities(long storeId); protected abstract int deleteStorePropertyEntities(long storeId);
} }

View File

@@ -104,12 +104,16 @@ public class AVMNodeDAOImpl extends AbstractAVMNodeDAOImpl
@Override @Override
protected int updateNodeEntity(AVMNodeEntity updateNodeEntity) protected int updateNodeEntity(AVMNodeEntity updateNodeEntity)
{ {
updateNodeEntity.incrementVers();
return template.update(UPDATE_AVM_NODE, updateNodeEntity); return template.update(UPDATE_AVM_NODE, updateNodeEntity);
} }
@Override @Override
protected int updateNodeEntityModTimeAndGuid(AVMNodeEntity updateNodeEntity) protected int updateNodeEntityModTimeAndGuid(AVMNodeEntity updateNodeEntity)
{ {
updateNodeEntity.incrementVers();
// partial update // partial update
return template.update(UPDATE_AVM_NODE_MODTIME_AND_GUID, updateNodeEntity); return template.update(UPDATE_AVM_NODE_MODTIME_AND_GUID, updateNodeEntity);
} }
@@ -117,6 +121,8 @@ public class AVMNodeDAOImpl extends AbstractAVMNodeDAOImpl
@Override @Override
protected int updateNodeEntityModTimeAndContentData(AVMNodeEntity updateNodeEntity) protected int updateNodeEntityModTimeAndContentData(AVMNodeEntity updateNodeEntity)
{ {
updateNodeEntity.incrementVers();
// partial update // partial update
return template.update(UPDATE_AVM_NODE_MODTIME_AND_CDATA, updateNodeEntity); return template.update(UPDATE_AVM_NODE_MODTIME_AND_CDATA, updateNodeEntity);
} }

View File

@@ -109,6 +109,8 @@ public class AVMStoreDAOImpl extends AbstractAVMStoreDAOImpl
@Override @Override
protected int updateStoreEntity(AVMStoreEntity updateStoreEntity) protected int updateStoreEntity(AVMStoreEntity updateStoreEntity)
{ {
updateStoreEntity.incrementVers();
return template.update(UPDATE_AVM_STORE, updateStoreEntity); return template.update(UPDATE_AVM_STORE, updateStoreEntity);
} }