ALF-588: MT - delete tenant requires deleteStore

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@22230 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-09-03 13:09:31 +00:00
parent c1068b0b0c
commit 7c79fcea58
7 changed files with 98 additions and 8 deletions

View File

@@ -331,6 +331,14 @@
id = #id#
</update>
<update id="update_Store" parameterClass="Store">
update alf_store set
protocol = #protocol#,
identifier = #identifier#
where
id = #id#
</update>
<update id="update_Node" parameterClass="NodeUpdate">
update alf_node set
version = #version#

View File

@@ -645,6 +645,28 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
return new Pair<Long, NodeRef>(rootNode.getId(), rootNode.getNodeRef());
}
@Override
public void moveStore(StoreRef oldStoreRef, StoreRef newStoreRef)
{
StoreEntity store = getStoreNotNull(oldStoreRef);
store.setProtocol(newStoreRef.getProtocol());
store.setIdentifier(newStoreRef.getIdentifier());
// Update it
int count = updateStore(store);
if (count != 1)
{
throw new ConcurrencyFailureException("Store not updated: " + oldStoreRef);
}
// All the NodeRef-based caches are invalid. ID-based caches are fine.
rootNodesCache.removeByKey(oldStoreRef);
nodesCache.clear();
if (isDebugEnabled)
{
logger.debug("Moved store: " + oldStoreRef + " --> " + newStoreRef);
}
}
/**
* Callback to cache store root nodes by {@link StoreRef}.
*
@@ -3139,6 +3161,7 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
protected abstract NodeEntity selectStoreRootNode(StoreRef storeRef);
protected abstract Long insertStore(StoreEntity store);
protected abstract int updateStoreRoot(StoreEntity store);
protected abstract int updateStore(StoreEntity store);
protected abstract Long insertNode(NodeEntity node);
protected abstract int updateNode(NodeUpdateEntity nodeUpdate);
protected abstract int updateNodePatchAcl(NodeUpdateEntity nodeUpdate);

View File

@@ -103,6 +103,14 @@ public interface NodeDAO extends NodeBulkLoader
*/
public Pair<Long, NodeRef> newStore(StoreRef storeRef);
/**
* Changes the old store reference to the new store reference.
*
* @param oldStoreRef the existing store
* @param newStoreRef the new store
*/
public void moveStore(StoreRef oldStoreRef, StoreRef newStoreRef);
public Pair<Long, NodeRef> getRootNode(StoreRef storeRef);
/*

View File

@@ -80,6 +80,7 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
private static final String DELETE_TRANSACTION_BY_ID = "alfresco.node.delete_TransactionById";
private static final String INSERT_STORE = "alfresco.node.insert_Store";
private static final String UPDATE_STORE_ROOT = "alfresco.node.update_StoreRoot";
private static final String UPDATE_STORE = "alfresco.node.update_Store";
private static final String SELECT_STORE_ALL = "alfresco.node.select_StoreAll";
private static final String SELECT_STORE_ROOT_NODE_BY_ID = "alfresco.node.select_StoreRootNodeById";
private static final String SELECT_STORE_ROOT_NODE_BY_REF = "alfresco.node.select_StoreRootNodeByRef";
@@ -269,6 +270,12 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
return template.update(UPDATE_STORE_ROOT, store);
}
@Override
protected int updateStore(StoreEntity store)
{
return template.update(UPDATE_STORE, store);
}
@Override
protected Long insertNode(NodeEntity node)
{

View File

@@ -463,6 +463,31 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
assertTrue("New store not present is list of stores", storeRefs.contains(storeRef));
}
public void testDeleteStore() throws Exception
{
StoreRef storeRef = createStore();
// get all stores
List<StoreRef> storeRefs = nodeService.getStores();
// check that the store ref is present
assertTrue("New store not present is list of stores", storeRefs.contains(storeRef));
// Delete it
nodeService.deleteStore(storeRef);
storeRefs = nodeService.getStores();
assertFalse("Deleted store should not present is list of stores", storeRefs.contains(storeRef));
// Now make sure that none of the stores have the "deleted" protocol
for (StoreRef retrievedStoreRef : storeRefs)
{
if (retrievedStoreRef.getProtocol().equals(StoreRef.PROTOCOL_DELETED))
{
fail("NodeService should not have returned 'deleted' stores." + storeRefs);
}
}
// Commit to ensure all is well
setComplete();
endTransaction();
}
public void testExists() throws Exception
{
StoreRef storeRef = createStore();

View File

@@ -67,6 +67,7 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.QNamePattern;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.GUID;
import org.alfresco.util.Pair;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.PropertyMap;
@@ -171,7 +172,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
List<StoreRef> storeRefs = new ArrayList<StoreRef>(50);
for (Pair<Long, StoreRef> pair : stores)
{
storeRefs.add(pair.getSecond());
StoreRef storeRef = pair.getSecond();
if (storeRef.getProtocol().equals(StoreRef.PROTOCOL_DELETED))
{
// Ignore
continue;
}
storeRefs.add(storeRef);
}
// Now get the AVMStores.
List<StoreRef> avmStores = avmNodeService.getStores();
@@ -211,7 +218,17 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
*/
public void deleteStore(StoreRef storeRef) throws InvalidStoreRefException
{
throw new UnsupportedOperationException();
// Delete the index
nodeIndexer.indexDeleteStore(storeRef);
// Rename the store
StoreRef deletedStoreRef = new StoreRef(StoreRef.PROTOCOL_DELETED, GUID.generate());
nodeDAO.moveStore(storeRef, deletedStoreRef);
// Done
if (logger.isDebugEnabled())
{
logger.debug("Marked store for deletion: " + storeRef + " --> " + deletedStoreRef);
}
}
public NodeRef getRootNode(StoreRef storeRef) throws InvalidStoreRefException

View File

@@ -24,6 +24,7 @@ import org.alfresco.repo.search.Indexer;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -70,12 +71,13 @@ public class NodeIndexer
this.enabled = enabled;
}
/**
* @deprecated
*/
public void init()
public void indexDeleteStore(StoreRef storeRef)
{
logger.warn("NodeIndexer.init() has been deprecated.");
if (logger.isDebugEnabled())
{
logger.debug("indexDeleteNode", new Exception("Stack Trace"));
}
indexer.deleteIndex(storeRef);
}
public void indexCreateNode(ChildAssociationRef childAssocRef)