Fixed ALF-10061: NodeService.getAssoc() throws an exception if the requested association does not exist

- CMIS expects to get null (as per NodeService javadoc) but it was generating a concurrency exception
 - Added a specific call to getNodeAssocOrNull to the DAO


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30162 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2011-09-02 03:23:06 +00:00
parent a33fa7be9f
commit 9e84d86ec5
4 changed files with 40 additions and 7 deletions

View File

@@ -1569,7 +1569,7 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
{ {
// Disable all behaviour. // Disable all behaviour.
// This only affects cm:auditable and is discarded at the end of this txn // This only affects cm:auditable and is discarded at the end of this txn
policyBehaviourFilter.disableAllBehaviours(); policyBehaviourFilter.disableBehaviour();
// Tag the transaction to prevent further propagation // Tag the transaction to prevent further propagation
AlfrescoTransactionSupport.bindResource(KEY_AUDITABLE_PROPAGATION_DISABLE, Boolean.TRUE); AlfrescoTransactionSupport.bindResource(KEY_AUDITABLE_PROPAGATION_DISABLE, Boolean.TRUE);
@@ -2507,16 +2507,33 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
return results; return results;
} }
public Pair<Long, AssociationRef> getNodeAssoc(Long assocId) @Override
public Pair<Long, AssociationRef> getNodeAssocOrNull(Long assocId)
{ {
NodeAssocEntity nodeAssocEntity = selectNodeAssocById(assocId); NodeAssocEntity nodeAssocEntity = selectNodeAssocById(assocId);
if (nodeAssocEntity == null) if (nodeAssocEntity == null)
{ {
throw new ConcurrencyFailureException("Assoc ID does not point to a valid association: " + assocId); return null;
} }
else
{
AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO); AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO);
return new Pair<Long, AssociationRef>(assocId, assocRef); return new Pair<Long, AssociationRef>(assocId, assocRef);
} }
}
public Pair<Long, AssociationRef> getNodeAssoc(Long assocId)
{
Pair<Long, AssociationRef> ret = getNodeAssocOrNull(assocId);
if (ret == null)
{
throw new ConcurrencyFailureException("Assoc ID does not point to a valid association: " + assocId);
}
else
{
return ret;
}
}
/* /*
* Child assocs * Child assocs

View File

@@ -328,6 +328,12 @@ public interface NodeDAO extends NodeBulkLoader
*/ */
public Collection<Pair<Long, AssociationRef>> getTargetNodeAssocs(Long sourceNodeId, QName typeQName); public Collection<Pair<Long, AssociationRef>> getTargetNodeAssocs(Long sourceNodeId, QName typeQName);
/**
* @return Returns a specific node association with the given ID
* or <tt>null</tt> if it doesn't exist
*/
public Pair<Long, AssociationRef> getNodeAssocOrNull(Long assocId);
/** /**
* @return Returns a specific node association with the given ID * @return Returns a specific node association with the given ID
* *

View File

@@ -29,6 +29,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.MLText; import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeRef.Status; import org.alfresco.service.cmr.repository.NodeRef.Status;
@@ -375,4 +376,11 @@ public class NodeServiceTest extends TestCase
txnIdRestore, archivedStatus.getDbTxnId()); txnIdRestore, archivedStatus.getDbTxnId());
} }
} }
public void testGetAssocById()
{
// Get a node association that doesn't exist
AssociationRef assocRef = nodeService.getAssoc(Long.MAX_VALUE);
assertNull("Should get null for missing ID of association. ", assocRef);
}
} }

View File

@@ -37,8 +37,8 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.node.ChildAssocEntity; import org.alfresco.repo.domain.node.ChildAssocEntity;
import org.alfresco.repo.domain.node.Node; import org.alfresco.repo.domain.node.Node;
import org.alfresco.repo.domain.node.NodeDAO; import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.domain.node.NodeExistsException;
import org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback; import org.alfresco.repo.domain.node.NodeDAO.ChildAssocRefQueryCallback;
import org.alfresco.repo.domain.node.NodeExistsException;
import org.alfresco.repo.domain.qname.QNameDAO; import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.repo.node.AbstractNodeServiceImpl; import org.alfresco.repo.node.AbstractNodeServiceImpl;
import org.alfresco.repo.node.StoreArchiveMap; import org.alfresco.repo.node.StoreArchiveMap;
@@ -1980,9 +1980,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
} }
} }
@Override
public AssociationRef getAssoc(Long id) public AssociationRef getAssoc(Long id)
{ {
return nodeDAO.getNodeAssoc(id).getSecond(); Pair<Long, AssociationRef> nodeAssocPair = nodeDAO.getNodeAssocOrNull(id);
return nodeAssocPair == null ? null : nodeAssocPair.getSecond();
} }
public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern) public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern)