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:
@@ -36,7 +36,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="nodeDAO" class="org.alfresco.repo.avm.AVMNodeDAOHibernate">
|
<bean id="avmNodeDAO" class="org.alfresco.repo.avm.AVMNodeDAOHibernate">
|
||||||
<property name="sessionFactory">
|
<property name="sessionFactory">
|
||||||
<ref bean="sessionFactory"/>
|
<ref bean="sessionFactory"/>
|
||||||
</property>
|
</property>
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
<ref bean="issuerDAO"/>
|
<ref bean="issuerDAO"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="nodeDAO">
|
<property name="nodeDAO">
|
||||||
<ref bean="nodeDAO"/>
|
<ref bean="avmNodeDAO"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="avmStoreDAO">
|
<property name="avmStoreDAO">
|
||||||
<ref bean="avmStoreDAO"/>
|
<ref bean="avmStoreDAO"/>
|
||||||
|
@@ -29,6 +29,9 @@
|
|||||||
<property name="nodeDaoService" >
|
<property name="nodeDaoService" >
|
||||||
<ref bean="nodeDaoService" />
|
<ref bean="nodeDaoService" />
|
||||||
</property>
|
</property>
|
||||||
|
<property name="avmNodeDAO">
|
||||||
|
<ref bean="avmNodeDAO"/>
|
||||||
|
</property>
|
||||||
<property name="transactionService" >
|
<property name="transactionService" >
|
||||||
<ref bean="transactionComponent" />
|
<ref bean="transactionComponent" />
|
||||||
</property>
|
</property>
|
||||||
|
@@ -22,7 +22,7 @@ import java.util.List;
|
|||||||
* DAO for AVMNodes interface.
|
* DAO for AVMNodes interface.
|
||||||
* @author britt
|
* @author britt
|
||||||
*/
|
*/
|
||||||
interface AVMNodeDAO
|
public interface AVMNodeDAO
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Save the given node, having never been saved before.
|
* Save the given node, having never been saved before.
|
||||||
@@ -76,6 +76,12 @@ interface AVMNodeDAO
|
|||||||
*/
|
*/
|
||||||
public List<AVMNode> getOrphans(int batchSize);
|
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.
|
* Inappropriate hack to get Hibernate to play nice.
|
||||||
*/
|
*/
|
||||||
|
@@ -129,6 +129,17 @@ class AVMNodeDAOHibernate extends HibernateDaoSupport implements
|
|||||||
return (List<AVMNode>)query.list();
|
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.
|
* Inappropriate hack to get Hibernate to play nice.
|
||||||
*/
|
*/
|
||||||
|
@@ -309,4 +309,14 @@
|
|||||||
and an.isRoot = false
|
and an.isRoot = false
|
||||||
]]>
|
]]>
|
||||||
</query>
|
</query>
|
||||||
|
<query name="PlainFileNode.GetContentUrls">
|
||||||
|
<![CDATA[
|
||||||
|
select
|
||||||
|
pfn.contentURL
|
||||||
|
from
|
||||||
|
PlainFileNodeImpl pfn
|
||||||
|
where pfn.contentURL is not null
|
||||||
|
]]>
|
||||||
|
</query>
|
||||||
|
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
||||||
|
@@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.repo.avm.AVMNodeDAO;
|
||||||
import org.alfresco.repo.content.ContentStore;
|
import org.alfresco.repo.content.ContentStore;
|
||||||
import org.alfresco.repo.node.db.NodeDaoService;
|
import org.alfresco.repo.node.db.NodeDaoService;
|
||||||
import org.alfresco.repo.transaction.TransactionUtil;
|
import org.alfresco.repo.transaction.TransactionUtil;
|
||||||
@@ -49,6 +50,7 @@ public class ContentStoreCleaner
|
|||||||
private DictionaryService dictionaryService;
|
private DictionaryService dictionaryService;
|
||||||
private NodeDaoService nodeDaoService;
|
private NodeDaoService nodeDaoService;
|
||||||
private TransactionService transactionService;
|
private TransactionService transactionService;
|
||||||
|
private AVMNodeDAO avmNodeDAO;
|
||||||
private List<ContentStore> stores;
|
private List<ContentStore> stores;
|
||||||
private List<ContentStoreCleanerListener> listeners;
|
private List<ContentStoreCleanerListener> listeners;
|
||||||
private int protectDays;
|
private int protectDays;
|
||||||
@@ -76,6 +78,15 @@ public class ContentStoreCleaner
|
|||||||
this.nodeDaoService = nodeDaoService;
|
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
|
* @param transactionService the component to ensure proper transactional wrapping
|
||||||
*/
|
*/
|
||||||
@@ -152,6 +163,7 @@ public class ContentStoreCleaner
|
|||||||
|
|
||||||
private Set<String> getValidUrls()
|
private Set<String> getValidUrls()
|
||||||
{
|
{
|
||||||
|
// This does the work for the regular Alfresco repository.
|
||||||
// wrap to make the request in a transaction
|
// wrap to make the request in a transaction
|
||||||
TransactionWork<List<String>> getUrlsWork = new TransactionWork<List<String>>()
|
TransactionWork<List<String>> getUrlsWork = new TransactionWork<List<String>>()
|
||||||
{
|
{
|
||||||
@@ -166,6 +178,20 @@ public class ContentStoreCleaner
|
|||||||
getUrlsWork,
|
getUrlsWork,
|
||||||
true);
|
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
|
// get all valid URLs
|
||||||
Set<String> validUrls = new HashSet<String>(contentDataStrings.size());
|
Set<String> validUrls = new HashSet<String>(contentDataStrings.size());
|
||||||
// convert the strings to objects and extract the URL
|
// convert the strings to objects and extract the URL
|
||||||
@@ -178,6 +204,12 @@ public class ContentStoreCleaner
|
|||||||
validUrls.add(contentData.getContentUrl());
|
validUrls.add(contentData.getContentUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// put all the avm urls into validUrls.
|
||||||
|
for (String url : avmContentUrls)
|
||||||
|
{
|
||||||
|
validUrls.add(url);
|
||||||
|
}
|
||||||
|
|
||||||
// done
|
// done
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
|
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.repo.avm.AVMNodeDAO;
|
||||||
import org.alfresco.repo.content.ContentStore;
|
import org.alfresco.repo.content.ContentStore;
|
||||||
import org.alfresco.repo.content.filestore.FileContentStore;
|
import org.alfresco.repo.content.filestore.FileContentStore;
|
||||||
import org.alfresco.repo.node.db.NodeDaoService;
|
import org.alfresco.repo.node.db.NodeDaoService;
|
||||||
@@ -56,6 +57,7 @@ public class ContentStoreCleanerTest extends TestCase
|
|||||||
TransactionService transactionService = serviceRegistry.getTransactionService();
|
TransactionService transactionService = serviceRegistry.getTransactionService();
|
||||||
DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
|
DictionaryService dictionaryService = serviceRegistry.getDictionaryService();
|
||||||
NodeDaoService nodeDaoService = (NodeDaoService) ctx.getBean("nodeDaoService");
|
NodeDaoService nodeDaoService = (NodeDaoService) ctx.getBean("nodeDaoService");
|
||||||
|
AVMNodeDAO avmNodeDAO = (AVMNodeDAO) ctx.getBean("avmNodeDAO");
|
||||||
|
|
||||||
// we need a store
|
// we need a store
|
||||||
store = new FileContentStore(TempFileProvider.getTempDir().getAbsolutePath());
|
store = new FileContentStore(TempFileProvider.getTempDir().getAbsolutePath());
|
||||||
@@ -69,6 +71,7 @@ public class ContentStoreCleanerTest extends TestCase
|
|||||||
cleaner.setTransactionService(transactionService);
|
cleaner.setTransactionService(transactionService);
|
||||||
cleaner.setDictionaryService(dictionaryService);
|
cleaner.setDictionaryService(dictionaryService);
|
||||||
cleaner.setNodeDaoService(nodeDaoService);
|
cleaner.setNodeDaoService(nodeDaoService);
|
||||||
|
cleaner.setAvmNodeDAO(avmNodeDAO);
|
||||||
cleaner.setStores(Collections.singletonList(store));
|
cleaner.setStores(Collections.singletonList(store));
|
||||||
cleaner.setListeners(Collections.singletonList(listener));
|
cleaner.setListeners(Collections.singletonList(listener));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user