mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fix AR-649.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3121 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -105,11 +105,16 @@
|
||||
<ref bean="sessionFactory" />
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="dbNodeDaoServiceTxnRegistration" class="org.alfresco.repo.transaction.NodeDaoServiceTransactionInterceptor" >
|
||||
<property name="nodeDaoService">
|
||||
<bean id="dbNodeDaoServiceTxnRegistration" class="org.alfresco.repo.transaction.TransactionalDaoInterceptor" >
|
||||
<property name="daoService">
|
||||
<ref bean="nodeDaoServiceImpl" />
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="persmissionDaoServiceTxnRegistration" class="org.alfresco.repo.transaction.TransactionalDaoInterceptor" >
|
||||
<property name="daoService">
|
||||
<ref bean="permissionsDaoComponent" />
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="nodeDaoService" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="proxyInterfaces">
|
||||
<value>org.alfresco.repo.node.db.NodeDaoService</value>
|
||||
|
@@ -35,10 +35,12 @@ import org.alfresco.repo.security.permissions.impl.PermissionsDaoComponent;
|
||||
import org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry;
|
||||
import org.alfresco.repo.security.permissions.impl.SimplePermissionEntry;
|
||||
import org.alfresco.repo.security.permissions.impl.SimplePermissionReference;
|
||||
import org.alfresco.repo.transaction.TransactionalDao;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.orm.hibernate3.HibernateCallback;
|
||||
@@ -52,7 +54,7 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
*
|
||||
* @author andyh
|
||||
*/
|
||||
public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements PermissionsDaoComponent
|
||||
public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements PermissionsDaoComponent, TransactionalDao
|
||||
{
|
||||
private static final boolean INHERIT_PERMISSIONS_DEFAULT = true;
|
||||
public static final String QUERY_GET_PERMISSION = "permission.GetPermission";
|
||||
@@ -61,9 +63,68 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
|
||||
|
||||
private NodeDaoService nodeDaoService;
|
||||
|
||||
/** a uuid identifying this unique instance */
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PermissionsDaoComponentImpl()
|
||||
{
|
||||
super();
|
||||
this.uuid = GUID.generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks equality by type and uuid
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!(obj instanceof PermissionsDaoComponentImpl))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
PermissionsDaoComponentImpl that = (PermissionsDaoComponentImpl) obj;
|
||||
return this.uuid.equals(that.uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #uuid
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return uuid.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this <tt>Session</tt> contain any changes which must be
|
||||
* synchronized with the store?
|
||||
*
|
||||
* @return true => changes are pending
|
||||
*/
|
||||
public boolean isDirty()
|
||||
{
|
||||
// create a callback for the task
|
||||
HibernateCallback callback = new HibernateCallback()
|
||||
{
|
||||
public Object doInHibernate(Session session)
|
||||
{
|
||||
return session.isDirty();
|
||||
}
|
||||
};
|
||||
// execute the callback
|
||||
return ((Boolean)getHibernateTemplate().execute(callback)).booleanValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just flushes the session
|
||||
*/
|
||||
public void flush()
|
||||
{
|
||||
getSession().flush();
|
||||
}
|
||||
|
||||
public void setNodeDaoService(NodeDaoService nodeDaoService)
|
||||
|
@@ -35,6 +35,7 @@ import org.alfresco.repo.domain.hibernate.NodeStatusImpl;
|
||||
import org.alfresco.repo.domain.hibernate.StoreImpl;
|
||||
import org.alfresco.repo.node.db.NodeDaoService;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.TransactionalDao;
|
||||
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
@@ -54,7 +55,7 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements NodeDaoService
|
||||
public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements NodeDaoService, TransactionalDao
|
||||
{
|
||||
private static final String QUERY_GET_ALL_STORES = "store.GetAllStores";
|
||||
private static final String QUERY_GET_CONTENT_DATA_STRINGS = "node.GetContentDataStrings";
|
||||
|
@@ -24,10 +24,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.node.db.NodeDaoService;
|
||||
import org.alfresco.repo.node.integrity.IntegrityChecker;
|
||||
import org.alfresco.repo.search.impl.lucene.LuceneIndexerAndSearcher;
|
||||
import org.alfresco.repo.search.impl.lucene.LuceneIndexerAndSearcherFactory;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -107,8 +105,8 @@ public abstract class AlfrescoTransactionSupport
|
||||
{
|
||||
TransactionSynchronizationImpl synch = getSynchronization();
|
||||
|
||||
Set<NodeDaoService> services = synch.getNodeDaoServices();
|
||||
for (NodeDaoService service : services)
|
||||
Set<TransactionalDao> services = synch.getDaoServices();
|
||||
for (TransactionalDao service : services)
|
||||
{
|
||||
if (service.isDirty())
|
||||
{
|
||||
@@ -196,20 +194,20 @@ public abstract class AlfrescoTransactionSupport
|
||||
* This method can be called repeatedly as long as the service being bound
|
||||
* implements <tt>equals</tt> and <tt>hashCode</tt>.
|
||||
*
|
||||
* @param nodeDaoService
|
||||
* @param daoService
|
||||
*/
|
||||
public static void bindNodeDaoService(NodeDaoService nodeDaoService)
|
||||
public static void bindDaoService(TransactionalDao daoService)
|
||||
{
|
||||
// get transaction-local synchronization
|
||||
TransactionSynchronizationImpl synch = getSynchronization();
|
||||
|
||||
// bind the service in
|
||||
boolean bound = synch.getNodeDaoServices().add(nodeDaoService);
|
||||
boolean bound = synch.getDaoServices().add(daoService);
|
||||
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logBoundService(nodeDaoService, bound);
|
||||
logBoundService(daoService, bound);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +319,7 @@ public abstract class AlfrescoTransactionSupport
|
||||
* <p>
|
||||
* The flush may include:
|
||||
* <ul>
|
||||
* <li>{@link NodeDaoService#flush()}</li>
|
||||
* <li>{@link TransactionalDao#flush()}</li>
|
||||
* <li>{@link RuleService#executePendingRules()}</li>
|
||||
* <li>{@link IntegrityChecker#checkIntegrity()}</li>
|
||||
* </ul>
|
||||
@@ -425,7 +423,7 @@ public abstract class AlfrescoTransactionSupport
|
||||
private static class TransactionSynchronizationImpl extends TransactionSynchronizationAdapter
|
||||
{
|
||||
private final String txnId;
|
||||
private final Set<NodeDaoService> nodeDaoServices;
|
||||
private final Set<TransactionalDao> daoServices;
|
||||
private final Set<IntegrityChecker> integrityCheckers;
|
||||
private final Set<LuceneIndexerAndSearcher> lucenes;
|
||||
private final Set<TransactionListener> listeners;
|
||||
@@ -439,7 +437,7 @@ public abstract class AlfrescoTransactionSupport
|
||||
public TransactionSynchronizationImpl(String txnId)
|
||||
{
|
||||
this.txnId = txnId;
|
||||
nodeDaoServices = new HashSet<NodeDaoService>(3);
|
||||
daoServices = new HashSet<TransactionalDao>(3);
|
||||
integrityCheckers = new HashSet<IntegrityChecker>(3);
|
||||
lucenes = new HashSet<LuceneIndexerAndSearcher>(3);
|
||||
listeners = new HashSet<TransactionListener>(5);
|
||||
@@ -452,12 +450,12 @@ public abstract class AlfrescoTransactionSupport
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns a set of <tt>NodeDaoService</tt> instances that will be called
|
||||
* @return Returns a set of <tt>TransactionalDao</tt> instances that will be called
|
||||
* during end-of-transaction processing
|
||||
*/
|
||||
public Set<NodeDaoService> getNodeDaoServices()
|
||||
public Set<TransactionalDao> getDaoServices()
|
||||
{
|
||||
return nodeDaoServices;
|
||||
return daoServices;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -500,7 +498,7 @@ public abstract class AlfrescoTransactionSupport
|
||||
StringBuilder sb = new StringBuilder(50);
|
||||
sb.append("TransactionSychronizationImpl")
|
||||
.append("[ txnId=").append(txnId)
|
||||
.append(", node service=").append(nodeDaoServices.size())
|
||||
.append(", daos=").append(daoServices.size())
|
||||
.append(", integrity=").append(integrityCheckers.size())
|
||||
.append(", indexers=").append(lucenes.size())
|
||||
.append(", resources=").append(resources)
|
||||
@@ -525,9 +523,9 @@ public abstract class AlfrescoTransactionSupport
|
||||
listener.flush();
|
||||
}
|
||||
// flush changes
|
||||
for (NodeDaoService nodeDaoServices : getNodeDaoServices())
|
||||
for (TransactionalDao daoService : getDaoServices())
|
||||
{
|
||||
nodeDaoServices.flush();
|
||||
daoService.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package org.alfresco.repo.transaction;
|
||||
|
||||
|
||||
/**
|
||||
* Contract for a DAO to interact with a transaction.
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public interface TransactionalDao
|
||||
{
|
||||
/**
|
||||
* Allows the dao to flush any consuming resources. This mechanism is
|
||||
* used primarily during long-lived transactions to ensure that system resources
|
||||
* are not used up.
|
||||
* <p>
|
||||
* This method must not be used for implementing business logic.
|
||||
*/
|
||||
void flush();
|
||||
|
||||
/**
|
||||
* Are there any pending changes which must be synchronized with the store?
|
||||
*
|
||||
* @return true => changes are pending
|
||||
*/
|
||||
public boolean isDirty();
|
||||
}
|
@@ -17,7 +17,6 @@
|
||||
package org.alfresco.repo.transaction;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.node.db.NodeDaoService;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -31,16 +30,16 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class NodeDaoServiceTransactionInterceptor implements MethodInterceptor, InitializingBean
|
||||
public class TransactionalDaoInterceptor implements MethodInterceptor, InitializingBean
|
||||
{
|
||||
private NodeDaoService nodeDaoService;
|
||||
private TransactionalDao daoService;
|
||||
|
||||
/**
|
||||
* @param nodeDaoService the <tt>NodeDaoService</tt> to register
|
||||
* @param daoService the <tt>NodeDaoService</tt> to register
|
||||
*/
|
||||
public void setNodeDaoService(NodeDaoService nodeDaoService)
|
||||
public void setDaoService(TransactionalDao daoService)
|
||||
{
|
||||
this.nodeDaoService = nodeDaoService;
|
||||
this.daoService = daoService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,15 +47,15 @@ public class NodeDaoServiceTransactionInterceptor implements MethodInterceptor,
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception
|
||||
{
|
||||
if (nodeDaoService == null)
|
||||
if (daoService == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("NodeDaoService is required: " + this);
|
||||
throw new AlfrescoRuntimeException("TransactionalDao is required: " + this);
|
||||
}
|
||||
}
|
||||
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable
|
||||
{
|
||||
AlfrescoTransactionSupport.bindNodeDaoService(nodeDaoService);
|
||||
AlfrescoTransactionSupport.bindDaoService(daoService);
|
||||
// propogate the call
|
||||
return invocation.proceed();
|
||||
}
|
Reference in New Issue
Block a user