()
+ {
+ public QNameEntity execute() throws Throwable
+ {
+ String threadName = Thread.currentThread().getName();
+ // We use a common namespace and assign one of a limited set of random numbers
+ // as the localname. The transaction waits a bit before going for the commit
+ // so as to ensure a good few others are trying the same thing.
+ String localName = "" + random.nextInt(10);
+ QName qname = QName.createQName(namespaceUri, localName);
+ QNameEntity qnameEntity = dao.getQNameEntity(qname);
+ if (qnameEntity == null)
+ {
+ // Notify that we are ready
+ logger.debug("Thread " + threadName + " is READY");
+ readyLatch.countDown();
+ // Wait for start signal
+ startLatch.await();
+ logger.debug("Thread " + threadName + " is GO");
+ // Go
+ try
+ {
+ // This could fail with concurrency, but that's what we're testing
+ logger.debug("Thread " + threadName + " is CREATING " + qname);
+ qnameEntity = dao.newQNameEntity(qname);
+ }
+ catch (Throwable e)
+ {
+ logger.debug("Failed to create QNameEntity. Might retry.", e);
+ throw e;
+ }
+ finally
+ {
+ // Notify the counter that this thread is done
+ logger.debug("Thread " + threadName + " is DONE");
+ doneLatch.countDown();
+ }
+ }
+ else
+ {
+ throw new RuntimeException("QName entity should not exist");
+ }
+ assertNotNull("QName should now exist", qnameEntity);
+ // Done
+ return qnameEntity;
+ }
+ };
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ retryingTransactionHelper.doInTransaction(callback);
+ }
+ catch (Throwable e)
+ {
+ logger.error("Error escaped from retry", e);
+ errors.add(e);
+ }
+ }
+ };
+ // Fire a bunch of threads off
+ for (int i = 0; i < threadCount; i++)
+ {
+ Thread thread = new Thread(runnable, getName() + "-" + i);
+ thread.setDaemon(true); // Just in case there are complications
+ thread.start();
+ }
+ // Wait for threads to be ready
+ readyLatch.await(5, TimeUnit.SECONDS);
+ // Let the threads go
+ startLatch.countDown();
+ // Wait for them all to be done (within limits)
+ doneLatch.await(threadCount, TimeUnit.SECONDS);
+ if (doneLatch.getCount() > 0)
+ {
+ fail("Still waiting for threads to finish");
+ }
+ // Check if there are errors
+ if (errors.size() > 0)
+ {
+ throw errors.get(0);
+ }
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/QNameEntity.java b/source/java/org/alfresco/repo/domain/QNameEntity.java
new file mode 100644
index 0000000000..e7ce61ce4c
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/QNameEntity.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.domain;
+
+import org.alfresco.service.namespace.QName;
+
+/**
+ * Represents a persistable QName entity.
+ *
+ * @author Derek Hulley
+ * @since 2.2
+ */
+public interface QNameEntity
+{
+ Long getId();
+
+ NamespaceEntity getNamespace();
+
+ void setNamespace(NamespaceEntity namespace);
+
+ String getLocalName();
+
+ void setLocalName(String localName);
+
+ QName getQName();
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java b/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java
index 389092da64..ec1095342d 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java
+++ b/source/java/org/alfresco/repo/domain/hibernate/ChildAssocImpl.java
@@ -30,7 +30,9 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import org.alfresco.repo.domain.ChildAssoc;
+import org.alfresco.repo.domain.NamespaceEntity;
import org.alfresco.repo.domain.Node;
+import org.alfresco.repo.domain.QNameEntity;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
@@ -46,16 +48,18 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
private Long version;
private Node parent;
private Node child;
- private QName typeQName;
+ private QNameEntity typeQName;
+ private NamespaceEntity qnameNamespace;
+ private String qnameLocalName;
private String childNodeName;
private long childNodeNameCrc;
- private QName qName;
private boolean isPrimary;
private int index;
private transient ReadLock refReadLock;
private transient WriteLock refWriteLock;
private transient ChildAssociationRef childAssocRef;
+ private transient QName qname;
public ChildAssocImpl()
{
@@ -71,15 +75,17 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
// add the forward associations
this.setParent(parentNode);
this.setChild(childNode);
-// childNode.getParentAssocs().add(this);
}
public void removeAssociation()
{
-// // maintain inverse assoc from child node to this instance
-// this.getChild().getParentAssocs().remove(this);
}
+ /**
+ * {@inheritDoc}
+ *
+ * This method is thread-safe and lazily creates the required references, if required.
+ */
public ChildAssociationRef getChildAssocRef()
{
boolean trashReference = false;
@@ -114,9 +120,9 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
if (childAssocRef == null || trashReference)
{
childAssocRef = new ChildAssociationRef(
- this.typeQName,
+ this.typeQName.getQName(),
parent.getNodeRef(),
- this.qName,
+ this.getQname(),
child.getNodeRef(),
this.isPrimary,
index);
@@ -129,6 +135,43 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
}
}
+ /**
+ * {@inheritDoc}
+ *
+ * This method is thread-safe and lazily creates the required references, if required.
+ */
+ public QName getQname()
+ {
+ // first check if it is available
+ refReadLock.lock();
+ try
+ {
+ if (qname != null)
+ {
+ return qname;
+ }
+ }
+ finally
+ {
+ refReadLock.unlock();
+ }
+ // get write lock
+ refWriteLock.lock();
+ try
+ {
+ // double check
+ if (qname == null )
+ {
+ qname = QName.createQName(qnameNamespace.getUri(), qnameLocalName);
+ }
+ return qname;
+ }
+ finally
+ {
+ refWriteLock.unlock();
+ }
+ }
+
public boolean equals(Object obj)
{
if (obj == null)
@@ -164,7 +207,7 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
.append(", child=").append(child.getId())
.append(", child name=").append(childNodeName)
.append(", child name crc=").append(childNodeNameCrc)
- .append(", assoc type=").append(getTypeQName())
+ .append(", assoc type=").append(getTypeQName().getQName())
.append(", assoc name=").append(getQname())
.append(", isPrimary=").append(isPrimary)
.append("]");
@@ -278,12 +321,12 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
}
}
- public QName getTypeQName()
+ public QNameEntity getTypeQName()
{
return typeQName;
}
-
- public void setTypeQName(QName typeQName)
+
+ public void setTypeQName(QNameEntity typeQName)
{
refWriteLock.lock();
try
@@ -297,6 +340,46 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
}
}
+ public NamespaceEntity getQnameNamespace()
+ {
+ return qnameNamespace;
+ }
+
+ public void setQnameNamespace(NamespaceEntity qnameNamespace)
+ {
+ refWriteLock.lock();
+ try
+ {
+ this.qnameNamespace = qnameNamespace;
+ this.childAssocRef = null;
+ this.qname = null;
+ }
+ finally
+ {
+ refWriteLock.unlock();
+ }
+ }
+
+ public String getQnameLocalName()
+ {
+ return qnameLocalName;
+ }
+
+ public void setQnameLocalName(String qnameLocalName)
+ {
+ refWriteLock.lock();
+ try
+ {
+ this.qnameLocalName = qnameLocalName;
+ this.childAssocRef = null;
+ this.qname = null;
+ }
+ finally
+ {
+ refWriteLock.unlock();
+ }
+ }
+
public String getChildNodeName()
{
return childNodeName;
@@ -317,25 +400,6 @@ public class ChildAssocImpl implements ChildAssoc, Serializable
this.childNodeNameCrc = crc;
}
- public QName getQname()
- {
- return qName;
- }
-
- public void setQname(QName qname)
- {
- refWriteLock.lock();
- try
- {
- this.qName = qname;
- this.childAssocRef = null;
- }
- finally
- {
- refWriteLock.unlock();
- }
- }
-
public boolean getIsPrimary()
{
return isPrimary;
diff --git a/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java b/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java
index 34a694d38f..26d5d75a78 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java
+++ b/source/java/org/alfresco/repo/domain/hibernate/HibernateNodeTest.java
@@ -37,15 +37,17 @@ import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.ChildAssoc;
+import org.alfresco.repo.domain.NamespaceEntity;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeKey;
import org.alfresco.repo.domain.NodeStatus;
import org.alfresco.repo.domain.PropertyValue;
+import org.alfresco.repo.domain.QNameDAO;
+import org.alfresco.repo.domain.QNameEntity;
import org.alfresco.repo.domain.Server;
import org.alfresco.repo.domain.Store;
import org.alfresco.repo.domain.StoreKey;
import org.alfresco.repo.domain.Transaction;
-import org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionListenerAdapter;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -60,7 +62,6 @@ import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.GenericJDBCException;
-import org.springframework.orm.hibernate3.HibernateCallback;
/**
* Test persistence and retrieval of Hibernate-specific implementations of the
@@ -76,6 +77,23 @@ public class HibernateNodeTest extends BaseSpringTest
private Store store;
private Server server;
private Transaction transaction;
+ private NamespaceEntity cmNamespaceEntity;
+ private NamespaceEntity emptyNamespaceEntity;
+ private QNameEntity cmObjectQNameEntity;
+ private QNameEntity containerQNameEntity;
+ private QNameEntity contentQNameEntity;
+ private QNameEntity type1QNameEntity;
+ private QNameEntity type2QNameEntity;
+ private QNameEntity type3QNameEntity;
+ private QNameEntity aspect1QNameEntity;
+ private QNameEntity aspect2QNameEntity;
+ private QNameEntity aspect3QNameEntity;
+ private QNameEntity aspect4QNameEntity;
+ private QNameEntity prop1QNameEntity;
+ private QNameEntity propNameQNameEntity;
+ private QNameEntity propAuthorQNameEntity;
+ private QNameEntity propArchivedByQNameEntity;
+ private QNameEntity aspectAuditableQNameEntity;
public HibernateNodeTest()
{
@@ -101,6 +119,27 @@ public class HibernateNodeTest extends BaseSpringTest
transaction.setServer(server);
transaction.setChangeTxnId(AlfrescoTransactionSupport.getTransactionId());
getSession().save(transaction);
+
+ // Create a QName for node type
+ QNameDAO qnameDAO = (QNameDAO) applicationContext.getBean("qnameDAO");
+
+ cmNamespaceEntity = qnameDAO.getOrCreateNamespaceEntity(NamespaceService.CONTENT_MODEL_1_0_URI);
+ emptyNamespaceEntity = qnameDAO.getOrCreateNamespaceEntity("");
+ cmObjectQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.TYPE_CMOBJECT);
+ containerQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.TYPE_CONTAINER);
+ contentQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.TYPE_CONTENT);
+ type1QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "type1"));
+ type2QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "type2"));
+ type3QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "type3"));
+ aspect1QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "aspect1"));
+ aspect2QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "aspect2"));
+ aspect3QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "aspect3"));
+ aspect4QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "aspect4"));
+ prop1QNameEntity = qnameDAO.getOrCreateQNameEntity(QName.createQName(TEST_NAMESPACE, "prop1"));
+ propNameQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_NAME);
+ propAuthorQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_AUTHOR);
+ propArchivedByQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_BY);
+ aspectAuditableQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_AUDITABLE);
}
protected void onTearDownInTransaction()
@@ -121,7 +160,7 @@ public class HibernateNodeTest extends BaseSpringTest
Node node = new NodeImpl();
node.setStore(store);
node.setUuid(GUID.generate());
- node.setTypeQName(ContentModel.TYPE_CONTAINER);
+ node.setTypeQName(containerQNameEntity);
// now it should work
Serializable id = getSession().save(node);
@@ -148,7 +187,7 @@ public class HibernateNodeTest extends BaseSpringTest
Node node = new NodeImpl();
node.setStore(store);
node.setUuid(GUID.generate());
- node.setTypeQName(ContentModel.TYPE_CONTAINER);
+ node.setTypeQName(containerQNameEntity);
Serializable nodeId = getSession().save(node);
// This should all be fine. The node does not HAVE to have a status.
@@ -195,12 +234,12 @@ public class HibernateNodeTest extends BaseSpringTest
Node node = new NodeImpl();
node.setStore(store);
node.setUuid(GUID.generate());
- node.setTypeQName(ContentModel.TYPE_CONTAINER);
+ node.setTypeQName(containerQNameEntity);
// give it a property map
- Map propertyMap = new HashMap(5);
+ Map propertyMap = new HashMap(5);
QName propertyQName = QName.createQName("{}A");
PropertyValue propertyValue = new PropertyValue(DataTypeDefinition.TEXT, "AAA");
- propertyMap.put(propertyQName, propertyValue);
+ propertyMap.put(prop1QNameEntity.getId(), propertyValue);
node.getProperties().putAll(propertyMap);
// persist it
Serializable id = getSession().save(node);
@@ -212,7 +251,7 @@ public class HibernateNodeTest extends BaseSpringTest
propertyMap = node.getProperties();
assertNotNull("Map not persisted", propertyMap);
// ensure that the value is present
- assertNotNull("Property value not present in map", QName.createQName("{}A"));
+ assertNotNull("Property value not present in map", propertyMap.get(prop1QNameEntity.getId()));
}
/**
@@ -225,19 +264,15 @@ public class HibernateNodeTest extends BaseSpringTest
Node node = new NodeImpl();
node.setStore(store);
node.setUuid(GUID.generate());
- node.setTypeQName(ContentModel.TYPE_CMOBJECT);
+ node.setTypeQName(cmObjectQNameEntity);
// add some aspects
- QName aspect1 = QName.createQName(TEST_NAMESPACE, "1");
- QName aspect2 = QName.createQName(TEST_NAMESPACE, "2");
- QName aspect3 = QName.createQName(TEST_NAMESPACE, "3");
- QName aspect4 = QName.createQName(TEST_NAMESPACE, "4");
- Set aspects = node.getAspects();
- aspects.add(aspect1);
- aspects.add(aspect2);
- aspects.add(aspect3);
- aspects.add(aspect4);
- assertFalse("Set did not eliminate duplicate aspect qname", aspects.add(aspect4));
+ Set aspects = node.getAspects();
+ aspects.add(aspect1QNameEntity.getId());
+ aspects.add(aspect2QNameEntity.getId());
+ aspects.add(aspect3QNameEntity.getId());
+ aspects.add(aspect4QNameEntity.getId());
+ assertFalse("Set did not eliminate duplicate aspect qname", aspects.add(aspect4QNameEntity.getId()));
// persist
Serializable id = getSession().save(node);
@@ -258,20 +293,21 @@ public class HibernateNodeTest extends BaseSpringTest
Node contentNode = new NodeImpl();
contentNode.setStore(store);
contentNode.setUuid(GUID.generate());
- contentNode.setTypeQName(ContentModel.TYPE_CONTENT);
+ contentNode.setTypeQName(contentQNameEntity);
Serializable contentNodeId = getSession().save(contentNode);
// make a container node
Node containerNode = new NodeImpl();
containerNode.setStore(store);
containerNode.setUuid(GUID.generate());
- containerNode.setTypeQName(ContentModel.TYPE_CONTAINER);
+ containerNode.setTypeQName(containerQNameEntity);
Serializable containerNodeId = getSession().save(containerNode);
// create an association to the content
ChildAssoc assoc1 = new ChildAssocImpl();
assoc1.setIsPrimary(true);
- assoc1.setTypeQName(QName.createQName(null, "type1"));
- assoc1.setQname(QName.createQName(null, "number1"));
+ assoc1.setTypeQName(type1QNameEntity);
+ assoc1.setQnameNamespace(emptyNamespaceEntity);
+ assoc1.setQnameLocalName("number1");
assoc1.setChildNodeName("number1");
assoc1.setChildNodeNameCrc(1);
assoc1.buildAssociation(containerNode, contentNode);
@@ -280,8 +316,9 @@ public class HibernateNodeTest extends BaseSpringTest
// make another association between the same two parent and child nodes
ChildAssoc assoc2 = new ChildAssocImpl();
assoc2.setIsPrimary(true);
- assoc2.setTypeQName(QName.createQName(null, "type2"));
- assoc2.setQname(QName.createQName(null, "number2"));
+ assoc2.setTypeQName(type2QNameEntity);
+ assoc2.setQnameNamespace(emptyNamespaceEntity);
+ assoc2.setQnameLocalName("number2");
assoc2.setChildNodeName("number2");
assoc2.setChildNodeNameCrc(2);
assoc2.buildAssociation(containerNode, contentNode);
@@ -335,31 +372,31 @@ public class HibernateNodeTest extends BaseSpringTest
Node node = new NodeImpl();
node.setStore(store);
node.setUuid(GUID.generate());
- node.setTypeQName(ContentModel.TYPE_CONTENT);
+ node.setTypeQName(contentQNameEntity);
Serializable nodeId = getSession().save(node);
// add some aspects to the node
- Set aspects = node.getAspects();
- aspects.add(ContentModel.ASPECT_AUDITABLE);
+ Set aspects = node.getAspects();
+ aspects.add(aspectAuditableQNameEntity.getId());
// add some properties
- Map properties = node.getProperties();
- properties.put(ContentModel.PROP_NAME, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ Map properties = node.getProperties();
+ properties.put(propNameQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
// check that the session hands back the same instance
Node checkNode = (Node) getSession().get(NodeImpl.class, nodeId);
assertNotNull(checkNode);
assertTrue("Node retrieved was not same instance", checkNode == node);
- Set checkAspects = checkNode.getAspects();
+ Set checkAspects = checkNode.getAspects();
assertTrue("Aspect set retrieved was not the same instance", checkAspects == aspects);
assertEquals("Incorrect number of aspects", 1, checkAspects.size());
- QName checkQName = (QName) checkAspects.toArray()[0];
- assertTrue("QName retrieved was not the same instance", checkQName == ContentModel.ASPECT_AUDITABLE);
+ Long checkQNameId = (Long) checkAspects.toArray()[0];
+ assertEquals("QName retrieved was not the same instance", aspectAuditableQNameEntity.getId(), checkQNameId);
- Map checkProperties = checkNode.getProperties();
+ Map checkProperties = checkNode.getProperties();
assertTrue("Propery map retrieved was not the same instance", checkProperties == properties);
- assertTrue("Property not found", checkProperties.containsKey(ContentModel.PROP_NAME));
+ assertTrue("Property not found", checkProperties.containsKey(propNameQNameEntity.getId()));
flushAndClear();
// commit the transaction
@@ -423,7 +460,7 @@ public class HibernateNodeTest extends BaseSpringTest
Node node = new NodeImpl();
node.setStore(store);
node.setUuid(GUID.generate());
- node.setTypeQName(ContentModel.TYPE_CONTENT);
+ node.setTypeQName(contentQNameEntity);
Long nodeId = (Long) getSession().save(node);
// Record the ID
@@ -434,12 +471,12 @@ public class HibernateNodeTest extends BaseSpringTest
/* flushAndClear(); */
// add some aspects to the node
- Set aspects = node.getAspects();
- aspects.add(ContentModel.ASPECT_AUDITABLE);
+ Set aspects = node.getAspects();
+ aspects.add(aspectAuditableQNameEntity.getId());
// add some properties
- Map properties = node.getProperties();
- properties.put(ContentModel.PROP_NAME, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ Map properties = node.getProperties();
+ properties.put(propNameQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
}
// Commit the transaction
txn.commit();
@@ -472,14 +509,14 @@ public class HibernateNodeTest extends BaseSpringTest
for (Long nodeId : nodeIds)
{
Node node = (Node) session.get(NodeImpl.class, nodeId);
- Set aspects = node.getAspects();
- Map properties = node.getProperties();
- if (!aspects.contains(ContentModel.ASPECT_AUDITABLE))
+ Set aspects = node.getAspects();
+ Map properties = node.getProperties();
+ if (!aspects.contains(aspectAuditableQNameEntity.getId()))
{
// Missing the aspect
incorrectAspectCount++;
}
- if (!properties.containsKey(ContentModel.PROP_NAME))
+ if (!properties.containsKey(propNameQNameEntity.getId()))
{
// Missing property
incorrectPropertyCount++;
@@ -511,10 +548,10 @@ public class HibernateNodeTest extends BaseSpringTest
Node containerNode = new NodeImpl();
containerNode.setStore(store);
containerNode.setUuid(GUID.generate());
- containerNode.setTypeQName(ContentModel.TYPE_CONTAINER);
- containerNode.getProperties().put(ContentModel.PROP_AUTHOR, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
- containerNode.getProperties().put(ContentModel.PROP_ARCHIVED_BY, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
- containerNode.getAspects().add(ContentModel.ASPECT_AUDITABLE);
+ containerNode.setTypeQName(containerQNameEntity);
+ containerNode.getProperties().put(propAuthorQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ containerNode.getProperties().put(propArchivedByQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ containerNode.getAspects().add(aspectAuditableQNameEntity.getId());
Serializable containerNodeId = getSession().save(containerNode);
NodeKey containerNodeKey = new NodeKey(containerNode.getNodeRef());
NodeStatus containerNodeStatus = new NodeStatusImpl();
@@ -526,10 +563,10 @@ public class HibernateNodeTest extends BaseSpringTest
Node contentNode1 = new NodeImpl();
contentNode1.setStore(store);
contentNode1.setUuid(GUID.generate());
- contentNode1.setTypeQName(ContentModel.TYPE_CONTENT);
- contentNode1.getProperties().put(ContentModel.PROP_AUTHOR, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
- contentNode1.getProperties().put(ContentModel.PROP_ARCHIVED_BY, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
- contentNode1.getAspects().add(ContentModel.ASPECT_AUDITABLE);
+ contentNode1.setTypeQName(contentQNameEntity);
+ contentNode1.getProperties().put(propAuthorQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ contentNode1.getProperties().put(propArchivedByQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ contentNode1.getAspects().add(aspectAuditableQNameEntity.getId());
Serializable contentNode1Id = getSession().save(contentNode1);
NodeKey contentNodeKey1 = new NodeKey(contentNode1.getNodeRef());
NodeStatus contentNodeStatus1 = new NodeStatusImpl();
@@ -541,11 +578,11 @@ public class HibernateNodeTest extends BaseSpringTest
Node contentNode2 = new NodeImpl();
contentNode2.setStore(store);
contentNode2.setUuid(GUID.generate());
- contentNode2.setTypeQName(ContentModel.TYPE_CONTENT);
+ contentNode2.setTypeQName(contentQNameEntity);
Serializable contentNode2Id = getSession().save(contentNode2);
- contentNode2.getProperties().put(ContentModel.PROP_AUTHOR, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
- contentNode2.getProperties().put(ContentModel.PROP_ARCHIVED_BY, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
- contentNode2.getAspects().add(ContentModel.ASPECT_AUDITABLE);
+ contentNode2.getProperties().put(propAuthorQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ contentNode2.getProperties().put(propArchivedByQNameEntity.getId(), new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
+ contentNode2.getAspects().add(aspectAuditableQNameEntity.getId());
NodeKey contentNodeKey2 = new NodeKey(contentNode2.getNodeRef());
NodeStatus contentNodeStatus2 = new NodeStatusImpl();
contentNodeStatus2.setKey(contentNodeKey2);
@@ -555,8 +592,9 @@ public class HibernateNodeTest extends BaseSpringTest
// create an association to content 1
ChildAssoc assoc1 = new ChildAssocImpl();
assoc1.setIsPrimary(true);
- assoc1.setTypeQName(QName.createQName(null, "type1"));
- assoc1.setQname(QName.createQName(null, "number1"));
+ assoc1.setTypeQName(type1QNameEntity);
+ assoc1.setQnameNamespace(emptyNamespaceEntity);
+ assoc1.setQnameLocalName("number1");
assoc1.setChildNodeName("number1");
assoc1.setChildNodeNameCrc(1);
assoc1.buildAssociation(containerNode, contentNode1);
@@ -564,8 +602,9 @@ public class HibernateNodeTest extends BaseSpringTest
// create an association to content 2
ChildAssoc assoc2 = new ChildAssocImpl();
assoc2.setIsPrimary(true);
- assoc2.setTypeQName(QName.createQName(null, "type2"));
- assoc2.setQname(QName.createQName(null, "number2"));
+ assoc2.setTypeQName(type2QNameEntity);
+ assoc2.setQnameNamespace(emptyNamespaceEntity);
+ assoc2.setQnameLocalName("number2");
assoc2.setChildNodeName("number2");
assoc2.setChildNodeNameCrc(2);
assoc2.buildAssociation(containerNode, contentNode2);
@@ -594,8 +633,9 @@ public class HibernateNodeTest extends BaseSpringTest
contentNode2 = contentNodeStatus2.getNode();
ChildAssoc assoc3 = new ChildAssocImpl();
assoc3.setIsPrimary(false);
- assoc3.setTypeQName(QName.createQName(null, "type3"));
- assoc3.setQname(QName.createQName(null, "number3"));
+ assoc3.setTypeQName(type3QNameEntity);
+ assoc3.setQnameNamespace(emptyNamespaceEntity);
+ assoc3.setQnameLocalName("number3");
assoc3.setChildNodeName("number3");
assoc3.setChildNodeNameCrc(2);
assoc3.buildAssociation(containerNode, contentNode2); // check whether the children are pulled in for this
@@ -612,13 +652,13 @@ public class HibernateNodeTest extends BaseSpringTest
Node parentNode = new NodeImpl();
parentNode.setStore(store);
parentNode.setUuid(GUID.generate());
- parentNode.setTypeQName(ContentModel.TYPE_CONTAINER);
+ parentNode.setTypeQName(containerQNameEntity);
Long nodeIdOne = (Long) getSession().save(parentNode);
// Create child node
Node childNode = new NodeImpl();
childNode.setStore(store);
childNode.setUuid(GUID.generate());
- childNode.setTypeQName(ContentModel.TYPE_CONTENT);
+ childNode.setTypeQName(contentQNameEntity);
Long nodeIdTwo = (Long) getSession().save(childNode);
// Get them into the database
getSession().flush();
@@ -631,8 +671,9 @@ public class HibernateNodeTest extends BaseSpringTest
ChildAssoc assoc = new ChildAssocImpl();
assoc.buildAssociation(parentNode, childNode);
assoc.setIsPrimary(false);
- assoc.setTypeQName(QName.createQName(null, "TYPE"));
- assoc.setQname(QName.createQName(null, "" + System.nanoTime()));
+ assoc.setTypeQName(type1QNameEntity);
+ assoc.setQnameNamespace(emptyNamespaceEntity);
+ assoc.setQnameLocalName("" + System.nanoTime());
assoc.setChildNodeName(GUID.generate()); // It must be unique
assoc.setChildNodeNameCrc(-1L);
Long assocId = (Long) getSession().save(assoc);
diff --git a/source/java/org/alfresco/repo/domain/hibernate/HibernateQNameDAOImpl.java b/source/java/org/alfresco/repo/domain/hibernate/HibernateQNameDAOImpl.java
new file mode 100644
index 0000000000..20fb4aa5cd
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/HibernateQNameDAOImpl.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.alfresco.error.AlfrescoRuntimeException;
+import org.alfresco.repo.cache.SimpleCache;
+import org.alfresco.repo.domain.NamespaceEntity;
+import org.alfresco.repo.domain.QNameDAO;
+import org.alfresco.repo.domain.QNameEntity;
+import org.alfresco.service.namespace.QName;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.springframework.orm.hibernate3.HibernateCallback;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
+
+/**
+ * Hibernate-specific implementation of the QName and Namespace DAO interface.
+ *
+ * @author Derek Hulley
+ * @since 2.1
+ */
+public class HibernateQNameDAOImpl extends HibernateDaoSupport implements QNameDAO
+{
+ private static final String QUERY_GET_NS_BY_URI = "qname.GetNamespaceByUri";
+ private static final String QUERY_GET_QNAME_BY_URI_AND_LOCALNAME = "qname.GetQNameByUriAndLocalName";
+
+ private SimpleCache qnameEntityCache;
+
+ public void setQnameEntityCache(SimpleCache qnameEntityCache)
+ {
+ this.qnameEntityCache = qnameEntityCache;
+ }
+
+ public NamespaceEntity getNamespaceEntity(Long id)
+ {
+ NamespaceEntity namespaceEntity = (NamespaceEntity) getSession().get(NamespaceEntityImpl.class, id);
+ if (namespaceEntity == null)
+ {
+ throw new AlfrescoRuntimeException("The NamespaceEntity ID " + id + " doesn't exist.");
+ }
+ return namespaceEntity;
+ }
+
+ public NamespaceEntity getNamespaceEntity(final String namespaceUri)
+ {
+ // TODO: Use a cache if external use becomes common
+ HibernateCallback callback = new HibernateCallback()
+ {
+ public Object doInHibernate(Session session)
+ {
+ Query query = session
+ .getNamedQuery(HibernateQNameDAOImpl.QUERY_GET_NS_BY_URI)
+ .setString("namespaceUri", namespaceUri);
+ return query.uniqueResult();
+ }
+ };
+ NamespaceEntity result = (NamespaceEntity) getHibernateTemplate().execute(callback);
+ // Done
+ return result;
+ }
+
+ public NamespaceEntity getOrCreateNamespaceEntity(String namespaceUri)
+ {
+ NamespaceEntity result = getNamespaceEntity(namespaceUri);
+ if (result == null)
+ {
+ result = newNamespaceEntity(namespaceUri);
+ }
+ return result;
+ }
+
+ public NamespaceEntity newNamespaceEntity(String namespaceUri)
+ {
+ NamespaceEntity namespace = new NamespaceEntityImpl();
+ namespace.setUri(namespaceUri);
+ // Persist
+ getSession().save(namespace);
+ // Done
+ return namespace;
+ }
+
+ public QNameEntity getQNameEntity(Long id)
+ {
+ QNameEntity qnameEntity = (QNameEntity) getSession().get(QNameEntityImpl.class, id);
+ if (qnameEntity == null)
+ {
+ throw new AlfrescoRuntimeException("The QNameEntity ID " + id + " doesn't exist.");
+ }
+ return qnameEntity;
+ }
+
+ public QName getQName(Long id)
+ {
+ // TODO: Explore caching options here
+ QNameEntity qnameEntity = getQNameEntity(id);
+ if (qnameEntity == null)
+ {
+ return null;
+ }
+ else
+ {
+ return qnameEntity.getQName();
+ }
+ }
+
+ public QNameEntity getQNameEntity(final QName qname)
+ {
+ QNameEntity result;
+ // First check the cache
+ Long id = qnameEntityCache.get(qname);
+ if (id == null)
+ {
+ // It's not in the cache, so query
+ HibernateCallback callback = new HibernateCallback()
+ {
+ public Object doInHibernate(Session session)
+ {
+ Query query = session
+ .getNamedQuery(HibernateQNameDAOImpl.QUERY_GET_QNAME_BY_URI_AND_LOCALNAME)
+ .setString("namespaceUri", qname.getNamespaceURI())
+ .setString("localName", qname.getLocalName());
+ return query.uniqueResult();
+ }
+ };
+ result = (QNameEntity) getHibernateTemplate().execute(callback);
+ if (result != null)
+ {
+ id = result.getId();
+ // We found something, so we can add it to the cache
+ qnameEntityCache.put(qname, id);
+ }
+ }
+ else
+ {
+ // Found in the cache. Load using the ID.
+ result = getQNameEntity(id);
+ if (result == null)
+ {
+ // It is not available, so we need to go the query route.
+ // But first remove the cache entry
+ qnameEntityCache.remove(qname);
+ // Recurse, but this time there is no cache entry
+ return getQNameEntity(qname);
+ }
+ }
+ // Done
+ return result;
+ }
+
+ public QNameEntity getOrCreateQNameEntity(QName qname)
+ {
+ QNameEntity result = getQNameEntity(qname);
+ if (result == null)
+ {
+ result = newQNameEntity(qname);
+ }
+ return result;
+ }
+
+ public QNameEntity newQNameEntity(QName qname)
+ {
+ final String namespaceUri = qname.getNamespaceURI();
+ final String localName = qname.getLocalName();
+ NamespaceEntity namespace = getNamespaceEntity(namespaceUri);
+ if (namespace == null)
+ {
+ namespace = newNamespaceEntity(namespaceUri);
+ }
+ QNameEntity qnameEntity = new QNameEntityImpl();
+ qnameEntity.setNamespace(namespace);
+ qnameEntity.setLocalName(localName);
+ // Persist
+ Long id = (Long) getSession().save(qnameEntity);
+ // Update the cache
+ qnameEntityCache.put(qname, id);
+ // Done
+ return qnameEntity;
+ }
+
+ public Set convertIdsToQNames(Set ids)
+ {
+ Set qnames = new HashSet(ids.size() * 2 + 1);
+ for (Long id : ids)
+ {
+ QName qname = getQName(id); // Never null
+ qnames.add(qname);
+ }
+ return qnames;
+ }
+
+ public Map convertIdMapToQNameMap(Map idMap)
+ {
+ Map qnameMap = new HashMap(idMap.size() + 3);
+ for (Map.Entry entry : idMap.entrySet())
+ {
+ QName qname = getQName(entry.getKey());
+ qnameMap.put(qname, entry.getValue());
+ }
+ return qnameMap;
+ }
+}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/NamespaceEntityImpl.java b/source/java/org/alfresco/repo/domain/hibernate/NamespaceEntityImpl.java
new file mode 100644
index 0000000000..76f4278f0c
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/NamespaceEntityImpl.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import java.io.Serializable;
+
+import org.alfresco.repo.domain.NamespaceEntity;
+import org.alfresco.repo.domain.QNameEntity;
+
+/**
+ * Hibernate-specific implementation of the domain entity QnameEntity.
+ *
+ * @author Derek Hulley
+ */
+public class NamespaceEntityImpl implements NamespaceEntity, Serializable
+{
+ private static final long serialVersionUID = -6781559184013949845L;
+
+ private Long id;
+ private Long version;
+ private String uri;
+
+ public NamespaceEntityImpl()
+ {
+ }
+
+ /**
+ * @see #getStoreRef()()
+ */
+ public String toString()
+ {
+ return uri;
+ }
+
+ /**
+ * @see #getKey()
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ else if (obj == this)
+ {
+ return true;
+ }
+ else if (!(obj instanceof QNameEntity))
+ {
+ return false;
+ }
+ NamespaceEntity that = (NamespaceEntity) obj;
+ return (this.getUri().equals(that.getUri()));
+ }
+
+ /**
+ * @see #getKey()
+ */
+ public int hashCode()
+ {
+ return uri.hashCode();
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ /**
+ * For Hibernate use.
+ */
+ @SuppressWarnings("unused")
+ private void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public Long getVersion()
+ {
+ return version;
+ }
+
+ /**
+ * For Hibernate use
+ */
+ @SuppressWarnings("unused")
+ private void setVersion(Long version)
+ {
+ this.version = version;
+ }
+
+ public String getUri()
+ {
+ return uri;
+ }
+
+ public void setUri(String uri)
+ {
+ this.uri = uri;
+ }
+}
\ No newline at end of file
diff --git a/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml b/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml
index a67c6e0cb5..4857ad89d9 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml
+++ b/source/java/org/alfresco/repo/domain/hibernate/Node.hbm.xml
@@ -6,7 +6,6 @@
-
@@ -41,12 +41,23 @@
-
+
+
-
-
+
+
-
+
+
-
-
+
@@ -87,22 +98,9 @@
sort="unsorted"
optimistic-lock="true"
cascade="delete" >
-
-
+
+
-
-
-
-
+
+
+
+
+
@@ -200,6 +224,7 @@
name="source"
class="org.alfresco.repo.domain.hibernate.NodeImpl"
optimistic-lock="false"
+ foreign-key="fk_alf_na_snode"
lazy="false"
fetch="join"
not-null="true" >
@@ -210,12 +235,23 @@
name="target"
class="org.alfresco.repo.domain.hibernate.NodeImpl"
optimistic-lock="false"
+ foreign-key="fk_alf_na_tnode"
lazy="false"
fetch="join"
not-null="true" >
-
+
+
@@ -235,7 +271,7 @@
assoc.childNodeName = :newName,
assoc.childNodeNameCrc = :newNameCrc
where
- assoc.id = :childAssocId
+ assoc = :childAssoc
@@ -244,7 +280,7 @@
from
org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc
where
- assoc.child.id = :childId
+ assoc.child = :child
order by
assoc.index,
assoc.id
@@ -258,9 +294,9 @@
org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc
join assoc.child as child
where
- assoc.parent.id = :parentId and
+ assoc.parent = :parent and
assoc.isPrimary = true and
- status.node.id = child.id
+ status.node = child
@@ -269,10 +305,11 @@
from
org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc
where
- assoc.parent.id = :parentId and
- assoc.child.id = :childId and
+ assoc.parent = :parent and
+ assoc.child = :child and
assoc.typeQName = :typeQName and
- assoc.qname = :qname
+ assoc.qnameNamespace = :qnameNamespace and
+ assoc.qnameLocalName = :qnameLocalName
order by
assoc.index,
assoc.id
@@ -284,7 +321,7 @@
from
org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc
where
- assoc.parent.id = :parentId
+ assoc.parent = :parent
order by
assoc.index,
assoc.id
@@ -296,7 +333,7 @@
from
org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc
where
- assoc.parent.id = :parentId and
+ assoc.parent = :parent and
assoc.childNodeName = :childNodeName and
assoc.childNodeNameCrc = :childNodeNameCrc
@@ -307,7 +344,7 @@
from
org.alfresco.repo.domain.hibernate.ChildAssocImpl as assoc
where
- assoc.parent.id = :parentId and
+ assoc.parent = :parent and
assoc.typeQName = :typeQName and
assoc.childNodeName = :childNodeName and
assoc.childNodeNameCrc = :childNodeNameCrc
@@ -319,7 +356,8 @@
select
assoc.typeQName,
- assoc.qname,
+ assoc.qnameNamespace,
+ assoc.qnameLocalName,
assoc.isPrimary,
assoc.index,
child.id,
@@ -331,7 +369,7 @@
join assoc.parent as parent
join assoc.child as child
where
- assoc.parent.id = :parentId
+ assoc.parent = :parent
order by
assoc.index,
assoc.id
@@ -340,7 +378,8 @@
select
assoc.typeQName,
- assoc.qname,
+ assoc.qnameNamespace,
+ assoc.qnameLocalName,
assoc.isPrimary,
assoc.index,
child.id,
@@ -352,8 +391,9 @@
join assoc.parent as parent
join assoc.child as child
where
- assoc.parent.id = :parentId and
- assoc.qname = :childAssocQName
+ assoc.parent = :parent and
+ assoc.qnameNamespace = :qnameNamespace and
+ assoc.qnameLocalName = :qnameLocalName
order by
assoc.index,
assoc.id
@@ -365,8 +405,8 @@
from
org.alfresco.repo.domain.hibernate.NodeAssocImpl as assoc
where
- assoc.source.id = :sourceId and
- assoc.target.id = :targetId and
+ assoc.source = :source and
+ assoc.target = :target and
assoc.typeQName = :assocTypeQName
@@ -376,8 +416,8 @@
from
org.alfresco.repo.domain.hibernate.NodeAssocImpl as assoc
where
- assoc.source.id = :nodeId or
- assoc.target.id = :nodeId
+ assoc.source = :node or
+ assoc.target = :node
@@ -388,7 +428,7 @@
join assoc.source as source
join assoc.target as target
where
- assoc.source.id = :sourceId
+ assoc.source = :source
@@ -399,7 +439,7 @@
join assoc.source as source
join assoc.target as target
where
- assoc.target.id = :targetId
+ assoc.target = :target
@@ -414,7 +454,7 @@
prop.actualType = :actualTypeString or
prop.actualType = 'SERIALIZABLE'
) and
- prop.persistedType != 'NULL'
+ prop.persistedType != 0
diff --git a/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java b/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java
index a66387d384..c21a7ecad2 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java
+++ b/source/java/org/alfresco/repo/domain/hibernate/NodeAssocImpl.java
@@ -31,8 +31,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeAssoc;
+import org.alfresco.repo.domain.QNameEntity;
import org.alfresco.service.cmr.repository.AssociationRef;
-import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
/**
@@ -48,7 +48,7 @@ public class NodeAssocImpl implements NodeAssoc, Serializable
private Long version;
private Node source;
private Node target;
- private QName typeQName;
+ private QNameEntity typeQName;
private transient ReadLock refReadLock;
private transient WriteLock refWriteLock;
@@ -103,7 +103,7 @@ public class NodeAssocImpl implements NodeAssoc, Serializable
{
nodeAssocRef = new AssociationRef(
getSource().getNodeRef(),
- this.typeQName,
+ this.typeQName.getQName(),
getTarget().getNodeRef());
}
return nodeAssocRef;
@@ -222,12 +222,12 @@ public class NodeAssocImpl implements NodeAssoc, Serializable
}
}
- public QName getTypeQName()
+ public QNameEntity getTypeQName()
{
return typeQName;
}
- public void setTypeQName(QName typeQName)
+ public void setTypeQName(QNameEntity typeQName)
{
refWriteLock.lock();
try
diff --git a/source/java/org/alfresco/repo/domain/hibernate/NodeImpl.java b/source/java/org/alfresco/repo/domain/hibernate/NodeImpl.java
index 655da3ccb1..c651827328 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/NodeImpl.java
+++ b/source/java/org/alfresco/repo/domain/hibernate/NodeImpl.java
@@ -38,9 +38,9 @@ import org.alfresco.repo.domain.ChildAssoc;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.PropertyValue;
+import org.alfresco.repo.domain.QNameEntity;
import org.alfresco.repo.domain.Store;
import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
/**
@@ -59,10 +59,10 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
private Long version;
private Store store;
private String uuid;
- private QName typeQName;
- private Set aspects;
+ private QNameEntity typeQName;
+ private Set aspects;
private Collection parentAssocs;
- private Map properties;
+ private Map properties;
private DbAccessControlList accessControlList;
private transient ReadLock refReadLock;
@@ -71,9 +71,9 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
public NodeImpl()
{
- aspects = new HashSet(5);
+ aspects = new HashSet(5);
parentAssocs = new HashSet(5);
- properties = new HashMap(5);
+ properties = new HashMap(5);
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
refReadLock = lock.readLock();
@@ -219,17 +219,17 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
}
}
- public QName getTypeQName()
+ public QNameEntity getTypeQName()
{
return typeQName;
}
- public void setTypeQName(QName typeQName)
+ public void setTypeQName(QNameEntity typeQName)
{
this.typeQName = typeQName;
}
- public Set getAspects()
+ public Set getAspects()
{
return aspects;
}
@@ -238,7 +238,7 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
* For Hibernate use
*/
@SuppressWarnings("unused")
- private void setAspects(Set aspects)
+ private void setAspects(Set aspects)
{
this.aspects = aspects;
}
@@ -257,7 +257,7 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
this.parentAssocs = parentAssocs;
}
- public Map getProperties()
+ public Map getProperties()
{
return properties;
}
@@ -266,7 +266,7 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
* For Hibernate use
*/
@SuppressWarnings("unused")
- private void setProperties(Map properties)
+ private void setProperties(Map properties)
{
this.properties = properties;
}
diff --git a/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml b/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml
index 9d738ef5e2..58ba8056d4 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml
+++ b/source/java/org/alfresco/repo/domain/hibernate/Permission.hbm.xml
@@ -5,6 +5,9 @@
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
+
+
+
+ column="permission_id"
+ foreign-key="fk_alf_ace_perm"
+ lazy="no-proxy"
+ fetch="select"
+ optimistic-lock="true"
+ not-null="true"/>
-
-
+
+
+ column="context_id"
+ foreign-key="fk_alf_ace_ctx"
+ lazy="no-proxy"
+ fetch="select"
+ optimistic-lock="true"
+ not-null="false"/>
diff --git a/source/java/org/alfresco/repo/domain/hibernate/QName.hbm.xml b/source/java/org/alfresco/repo/domain/hibernate/QName.hbm.xml
new file mode 100644
index 0000000000..f4d9c7974a
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/QName.hbm.xml
@@ -0,0 +1,82 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ select
+ namespace
+ from
+ org.alfresco.repo.domain.hibernate.NamespaceEntityImpl as namespace
+ where
+ namespace.uri = :namespaceUri
+
+
+
+ select
+ qname
+ from
+ org.alfresco.repo.domain.hibernate.QNameEntityImpl as qname
+ join qname.namespace as namespace
+ where
+ namespace.uri = :namespaceUri and
+ qname.localName = :localName
+
+
+
diff --git a/source/java/org/alfresco/repo/domain/hibernate/QNameEntityImpl.java b/source/java/org/alfresco/repo/domain/hibernate/QNameEntityImpl.java
new file mode 100644
index 0000000000..4d1a62fe74
--- /dev/null
+++ b/source/java/org/alfresco/repo/domain/hibernate/QNameEntityImpl.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2005-2007 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+package org.alfresco.repo.domain.hibernate;
+
+import java.io.Serializable;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+
+import org.alfresco.repo.domain.NamespaceEntity;
+import org.alfresco.repo.domain.QNameEntity;
+import org.alfresco.service.namespace.QName;
+
+/**
+ * Hibernate-specific implementation of the domain entity QnameEntity.
+ *
+ * @author Derek Hulley
+ */
+public class QNameEntityImpl implements QNameEntity, Serializable
+{
+ private static final long serialVersionUID = -4211902156023915846L;
+
+ private Long id;
+ private Long version;
+ private NamespaceEntity namespace;
+ private String localName;
+
+ private transient ReadLock refReadLock;
+ private transient WriteLock refWriteLock;
+ private transient QName qname;
+
+ public QNameEntityImpl()
+ {
+ ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ refReadLock = lock.readLock();
+ refWriteLock = lock.writeLock();
+ }
+
+ /**
+ * Lazily constructs a QName
instance referencing this entity
+ */
+ public QName getQName()
+ {
+ // first check if it is available
+ refReadLock.lock();
+ try
+ {
+ if (qname != null)
+ {
+ return qname;
+ }
+ }
+ finally
+ {
+ refReadLock.unlock();
+ }
+ // get write lock
+ refWriteLock.lock();
+ try
+ {
+ // double check
+ if (qname == null )
+ {
+ String namespaceUri = namespace.getUri();
+ qname = QName.createQName(namespaceUri, localName);
+ }
+ return qname;
+ }
+ finally
+ {
+ refWriteLock.unlock();
+ }
+ }
+
+ /**
+ * @see #getStoreRef()()
+ */
+ public String toString()
+ {
+ return getQName().toString();
+ }
+
+ /**
+ * @see #getKey()
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ else if (obj == this)
+ {
+ return true;
+ }
+ else if (!(obj instanceof QNameEntity))
+ {
+ return false;
+ }
+ QNameEntity that = (QNameEntity) obj;
+ return (this.getQName().equals(that.getQName()));
+ }
+
+ /**
+ * @see #getKey()
+ */
+ public int hashCode()
+ {
+ return getQName().hashCode();
+ }
+
+ public Long getId()
+ {
+ return id;
+ }
+
+ /**
+ * For Hibernate use.
+ */
+ @SuppressWarnings("unused")
+ private void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public Long getVersion()
+ {
+ return version;
+ }
+
+ /**
+ * For Hibernate use
+ */
+ @SuppressWarnings("unused")
+ private void setVersion(Long version)
+ {
+ this.version = version;
+ }
+
+ public NamespaceEntity getNamespace()
+ {
+ return namespace;
+ }
+
+ public void setNamespace(NamespaceEntity namespace)
+ {
+ refWriteLock.lock();
+ try
+ {
+ this.namespace = namespace;
+ this.qname = null;
+ }
+ finally
+ {
+ refWriteLock.unlock();
+ }
+ }
+
+ public String getLocalName()
+ {
+ return localName;
+ }
+
+ public void setLocalName(String localName)
+ {
+ refWriteLock.lock();
+ try
+ {
+ this.localName = localName;
+ this.qname = null;
+ }
+ finally
+ {
+ refWriteLock.unlock();
+ }
+ }
+}
\ No newline at end of file
diff --git a/source/java/org/alfresco/repo/domain/hibernate/Store.hbm.xml b/source/java/org/alfresco/repo/domain/hibernate/Store.hbm.xml
index 3904139249..9674f1c5ae 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/Store.hbm.xml
+++ b/source/java/org/alfresco/repo/domain/hibernate/Store.hbm.xml
@@ -25,6 +25,7 @@
diff --git a/source/java/org/alfresco/repo/domain/hibernate/Transaction.hbm.xml b/source/java/org/alfresco/repo/domain/hibernate/Transaction.hbm.xml
index fb6d7d14e4..2e57ec2d15 100644
--- a/source/java/org/alfresco/repo/domain/hibernate/Transaction.hbm.xml
+++ b/source/java/org/alfresco/repo/domain/hibernate/Transaction.hbm.xml
@@ -26,6 +26,7 @@
name="server"
class="org.alfresco.repo.domain.hibernate.ServerImpl"
column="server_id"
+ foreign-key="fk_alf_txn_svr"
lazy="proxy"
fetch="select"
unique="false"
diff --git a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java
index bf227f7415..f30506e07b 100644
--- a/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java
+++ b/source/java/org/alfresco/repo/node/BaseNodeServiceTest.java
@@ -52,6 +52,7 @@ import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
+import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryException;
@@ -1056,6 +1057,43 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
}
}
+ /**
+ * Makes a read-only transaction and then looks for a property using a non-existent QName.
+ * The QName persistence must not lazily create QNameEntity instances for queries.
+ */
+ public void testGetUnknownProperty() throws Exception
+ {
+ // commit to keep the root node
+ setComplete();
+ endTransaction();
+
+ RetryingTransactionCallback createCallback = new RetryingTransactionCallback()
+ {
+ public NodeRef execute() throws Throwable
+ {
+ NodeRef nodeRef = nodeService.createNode(
+ rootNodeRef,
+ ASSOC_TYPE_QNAME_TEST_CHILDREN,
+ QName.createQName("pathA"),
+ ContentModel.TYPE_CONTAINER).getChildRef();
+ return nodeRef;
+ }
+ };
+ final NodeRef nodeRef = retryingTransactionHelper.doInTransaction(createCallback, false, true);
+
+ RetryingTransactionCallback