mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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
This commit is contained in:
@@ -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<AVMNode> getOrphans(int batchSize);
|
||||
|
||||
/**
|
||||
* Get all content urls in he AVM Repository.
|
||||
* @return A List of URL Strings.
|
||||
*/
|
||||
public List<String> getContentUrls();
|
||||
|
||||
/**
|
||||
* Inappropriate hack to get Hibernate to play nice.
|
||||
*/
|
||||
|
@@ -129,6 +129,17 @@ class AVMNodeDAOHibernate extends HibernateDaoSupport implements
|
||||
return (List<AVMNode>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all content urls in he AVM Repository.
|
||||
* @return A List of URL Strings.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<String> getContentUrls()
|
||||
{
|
||||
Query query = getSession().getNamedQuery("PlainFileNode.GetContentUrls");
|
||||
return (List<String>)query.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inappropriate hack to get Hibernate to play nice.
|
||||
*/
|
||||
|
@@ -309,4 +309,14 @@
|
||||
and an.isRoot = false
|
||||
]]>
|
||||
</query>
|
||||
<query name="PlainFileNode.GetContentUrls">
|
||||
<![CDATA[
|
||||
select
|
||||
pfn.contentURL
|
||||
from
|
||||
PlainFileNodeImpl pfn
|
||||
where pfn.contentURL is not null
|
||||
]]>
|
||||
</query>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
@@ -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<ContentStore> stores;
|
||||
private List<ContentStoreCleanerListener> 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<String> getValidUrls()
|
||||
{
|
||||
// This does the work for the regular Alfresco repository.
|
||||
// wrap to make the request in a transaction
|
||||
TransactionWork<List<String>> getUrlsWork = new TransactionWork<List<String>>()
|
||||
{
|
||||
@@ -166,6 +178,20 @@ public class ContentStoreCleaner
|
||||
getUrlsWork,
|
||||
true);
|
||||
|
||||
// Do the same for the AVM repository.
|
||||
TransactionWork<List<String>> getAVMUrlsWork = new TransactionWork<List<String>>()
|
||||
{
|
||||
public List<String> doWork() throws Exception
|
||||
{
|
||||
return avmNodeDAO.getContentUrls();
|
||||
}
|
||||
};
|
||||
|
||||
List<String> avmContentUrls = TransactionUtil.executeInUserTransaction(
|
||||
transactionService,
|
||||
getAVMUrlsWork,
|
||||
true);
|
||||
|
||||
// get all valid URLs
|
||||
Set<String> validUrls = new HashSet<String>(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())
|
||||
{
|
||||
|
@@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user