From 231cfc3fa1ba753b9f7c57451681ee9f974d2e72 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Wed, 3 May 2006 19:04:55 +0000 Subject: [PATCH] Fixed issue where node with specific UUID is recreated in the same transaction as it is deleted in git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2747 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../HibernateNodeDaoServiceImpl.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java b/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java index d751315530..e747bcb958 100644 --- a/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java +++ b/source/java/org/alfresco/repo/node/db/hibernate/HibernateNodeDaoServiceImpl.java @@ -216,6 +216,27 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements public Node newNode(Store store, String uuid, QName nodeTypeQName) throws InvalidTypeException { NodeKey key = new NodeKey(store.getKey(), uuid); + + // create (or reuse) the mandatory node status + NodeStatus status = (NodeStatus) getHibernateTemplate().get(NodeStatusImpl.class, key); + if (status == null) + { + status = new NodeStatusImpl(); + status.setKey(key); + } + else + { + // The node existed at some point. + // Although unlikely, it is possible that the node was deleted in this transaction. + // If that is the case, then the session has to be flushed so that the database + // constraints aren't violated as the node creation will write to the database to + // get an ID + if (status.getChangeTxnId().equals(AlfrescoTransactionSupport.getTransactionId())) + { + // flush + getHibernateTemplate().flush(); + } + } // build a concrete node based on a bootstrap type Node node = new NodeImpl(); @@ -225,14 +246,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements node.setTypeQName(nodeTypeQName); // persist the node getHibernateTemplate().save(node); - - // create (or reuse) the mandatory node status - NodeStatus status = (NodeStatus) getHibernateTemplate().get(NodeStatusImpl.class, key); - if (status == null) - { - status = new NodeStatusImpl(); - status.setKey(key); - } + // set required status properties status.setNode(node); status.setChangeTxnId(AlfrescoTransactionSupport.getTransactionId()); @@ -322,6 +336,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements assoc.setTypeQName(assocTypeQName); assoc.setIsPrimary(isPrimary); assoc.setQname(qname); +// assoc.setIsArchived(false); assoc.buildAssociation(parentNode, childNode); // persist getHibernateTemplate().save(assoc); @@ -434,6 +449,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements { NodeAssoc assoc = new NodeAssocImpl(); assoc.setTypeQName(assocTypeQName); +// assoc.setIsArchived(false); assoc.buildAssociation(sourceNode, targetNode); // persist getHibernateTemplate().save(assoc);