From e2c66899cc6427e70dc09b00aac3b7c2c2d3ac19 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Fri, 25 Aug 2006 14:00:32 +0000 Subject: [PATCH] Make sure that ContentStoreCleaner doesn't clean up in-use AVM content. Doh! git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3612 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/avm-services-context.xml | 4 +-- config/alfresco/content-services-context.xml | 3 ++ .../org/alfresco/repo/avm/AVMNodeDAO.java | 8 ++++- .../repo/avm/AVMNodeDAOHibernate.java | 11 +++++++ .../alfresco/repo/avm/hibernate/AVM.hbm.xml | 10 ++++++ .../content/cleanup/ContentStoreCleaner.java | 32 +++++++++++++++++++ .../cleanup/ContentStoreCleanerTest.java | 3 ++ 7 files changed, 68 insertions(+), 3 deletions(-) diff --git a/config/alfresco/avm-services-context.xml b/config/alfresco/avm-services-context.xml index 1001e423a6..45256a3760 100644 --- a/config/alfresco/avm-services-context.xml +++ b/config/alfresco/avm-services-context.xml @@ -36,7 +36,7 @@ - + @@ -107,7 +107,7 @@ - + diff --git a/config/alfresco/content-services-context.xml b/config/alfresco/content-services-context.xml index 9c7a9847fa..e54fc8d729 100644 --- a/config/alfresco/content-services-context.xml +++ b/config/alfresco/content-services-context.xml @@ -29,6 +29,9 @@ + + + diff --git a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java b/source/java/org/alfresco/repo/avm/AVMNodeDAO.java index 1a6e5371dd..ecd0140f64 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeDAO.java @@ -22,7 +22,7 @@ import java.util.List; * DAO for AVMNodes interface. * @author britt */ -interface AVMNodeDAO +public interface AVMNodeDAO { /** * Save the given node, having never been saved before. @@ -76,6 +76,12 @@ interface AVMNodeDAO */ public List getOrphans(int batchSize); + /** + * Get all content urls in he AVM Repository. + * @return A List of URL Strings. + */ + public List getContentUrls(); + /** * Inappropriate hack to get Hibernate to play nice. */ diff --git a/source/java/org/alfresco/repo/avm/AVMNodeDAOHibernate.java b/source/java/org/alfresco/repo/avm/AVMNodeDAOHibernate.java index 4402509473..460d2839c5 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeDAOHibernate.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeDAOHibernate.java @@ -129,6 +129,17 @@ class AVMNodeDAOHibernate extends HibernateDaoSupport implements return (List)query.list(); } + /** + * Get all content urls in he AVM Repository. + * @return A List of URL Strings. + */ + @SuppressWarnings("unchecked") + public List getContentUrls() + { + Query query = getSession().getNamedQuery("PlainFileNode.GetContentUrls"); + return (List)query.list(); + } + /** * Inappropriate hack to get Hibernate to play nice. */ diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml index f2fda110b8..3367766135 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml +++ b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml @@ -309,4 +309,14 @@ and an.isRoot = false ]]> + + + + diff --git a/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java b/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java index adfedf0767..91ec5e9e57 100644 --- a/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java +++ b/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleaner.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.avm.AVMNodeDAO; import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.node.db.NodeDaoService; import org.alfresco.repo.transaction.TransactionUtil; @@ -49,6 +50,7 @@ public class ContentStoreCleaner private DictionaryService dictionaryService; private NodeDaoService nodeDaoService; private TransactionService transactionService; + private AVMNodeDAO avmNodeDAO; private List stores; private List listeners; private int protectDays; @@ -76,6 +78,15 @@ public class ContentStoreCleaner this.nodeDaoService = nodeDaoService; } + /** + * Setter for Spring. + * @param avmNodeDAO The AVM Node DAO to get urls with. + */ + public void setAvmNodeDAO(AVMNodeDAO avmNodeDAO) + { + this.avmNodeDAO = avmNodeDAO; + } + /** * @param transactionService the component to ensure proper transactional wrapping */ @@ -152,6 +163,7 @@ public class ContentStoreCleaner private Set getValidUrls() { + // This does the work for the regular Alfresco repository. // wrap to make the request in a transaction TransactionWork> getUrlsWork = new TransactionWork>() { @@ -166,6 +178,20 @@ public class ContentStoreCleaner getUrlsWork, true); + // Do the same for the AVM repository. + TransactionWork> getAVMUrlsWork = new TransactionWork>() + { + public List doWork() throws Exception + { + return avmNodeDAO.getContentUrls(); + } + }; + + List avmContentUrls = TransactionUtil.executeInUserTransaction( + transactionService, + getAVMUrlsWork, + true); + // get all valid URLs Set validUrls = new HashSet(contentDataStrings.size()); // convert the strings to objects and extract the URL @@ -178,6 +204,12 @@ public class ContentStoreCleaner validUrls.add(contentData.getContentUrl()); } } + // put all the avm urls into validUrls. + for (String url : avmContentUrls) + { + validUrls.add(url); + } + // done if (logger.isDebugEnabled()) { diff --git a/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleanerTest.java b/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleanerTest.java index 34aeeb1cf3..fac70515c1 100644 --- a/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleanerTest.java +++ b/source/java/org/alfresco/repo/content/cleanup/ContentStoreCleanerTest.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.alfresco.repo.avm.AVMNodeDAO; import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.content.filestore.FileContentStore; import org.alfresco.repo.node.db.NodeDaoService; @@ -56,6 +57,7 @@ public class ContentStoreCleanerTest extends TestCase TransactionService transactionService = serviceRegistry.getTransactionService(); DictionaryService dictionaryService = serviceRegistry.getDictionaryService(); NodeDaoService nodeDaoService = (NodeDaoService) ctx.getBean("nodeDaoService"); + AVMNodeDAO avmNodeDAO = (AVMNodeDAO) ctx.getBean("avmNodeDAO"); // we need a store store = new FileContentStore(TempFileProvider.getTempDir().getAbsolutePath()); @@ -69,6 +71,7 @@ public class ContentStoreCleanerTest extends TestCase cleaner.setTransactionService(transactionService); cleaner.setDictionaryService(dictionaryService); cleaner.setNodeDaoService(nodeDaoService); + cleaner.setAvmNodeDAO(avmNodeDAO); cleaner.setStores(Collections.singletonList(store)); cleaner.setListeners(Collections.singletonList(listener)); }