Merged V2.2 to HEAD (QNames)

7624: QName Refactor Merge 1 of 9
   7625: QName Refactor Merge 2 of 9
   7626: QName Refactor Merge 3 of 9
   7627: QName Refactor Merge 4 of 9
   7628: QName Refactor Merge 5 of 9


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8436 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2008-03-06 18:12:25 +00:00
parent a49bfd311d
commit 00e81c0d66
52 changed files with 2851 additions and 698 deletions

View File

@@ -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}
* <p>
* 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}
* <p>
* 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;

View File

@@ -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<QName, PropertyValue> propertyMap = new HashMap<QName, PropertyValue>(5);
Map<Long, PropertyValue> propertyMap = new HashMap<Long, PropertyValue>(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<QName> 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<Long> 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<QName> aspects = node.getAspects();
aspects.add(ContentModel.ASPECT_AUDITABLE);
Set<Long> aspects = node.getAspects();
aspects.add(aspectAuditableQNameEntity.getId());
// add some properties
Map<QName, PropertyValue> properties = node.getProperties();
properties.put(ContentModel.PROP_NAME, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
Map<Long, PropertyValue> 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<QName> checkAspects = checkNode.getAspects();
Set<Long> 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<QName, PropertyValue> checkProperties = checkNode.getProperties();
Map<Long, PropertyValue> 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<QName> aspects = node.getAspects();
aspects.add(ContentModel.ASPECT_AUDITABLE);
Set<Long> aspects = node.getAspects();
aspects.add(aspectAuditableQNameEntity.getId());
// add some properties
Map<QName, PropertyValue> properties = node.getProperties();
properties.put(ContentModel.PROP_NAME, new PropertyValue(DataTypeDefinition.TEXT, "ABC"));
Map<Long, PropertyValue> 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<QName> aspects = node.getAspects();
Map<QName, PropertyValue> properties = node.getProperties();
if (!aspects.contains(ContentModel.ASPECT_AUDITABLE))
Set<Long> aspects = node.getAspects();
Map<Long, PropertyValue> 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);

View File

@@ -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<QName, Long> qnameEntityCache;
public void setQnameEntityCache(SimpleCache<QName, Long> 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<QName> convertIdsToQNames(Set<Long> ids)
{
Set<QName> qnames = new HashSet<QName>(ids.size() * 2 + 1);
for (Long id : ids)
{
QName qname = getQName(id); // Never null
qnames.add(qname);
}
return qnames;
}
public Map<QName, ? extends Object> convertIdMapToQNameMap(Map<Long, ? extends Object> idMap)
{
Map<QName, Object> qnameMap = new HashMap<QName, Object>(idMap.size() + 3);
for (Map.Entry<Long, ? extends Object> entry : idMap.entrySet())
{
QName qname = getQName(entry.getKey());
qnameMap.put(qname, entry.getValue());
}
return qnameMap;
}
}

View File

@@ -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 <b>QnameEntity</b>.
*
* @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;
}
}

View File

@@ -6,7 +6,6 @@
<hibernate-mapping>
<typedef class="org.alfresco.repo.domain.hibernate.QNameUserType" name="QName" />
<typedef class="org.alfresco.repo.domain.hibernate.LocaleUserType" name="Locale" />
<class
@@ -29,7 +28,8 @@
name="store"
class="org.alfresco.repo.domain.hibernate.StoreImpl"
not-null="true"
lazy="proxy"
lazy="proxy"
foreign-key="fk_alf_n_store"
optimistic-lock="true"
fetch="join">
<column name="protocol" not-null="true" />
@@ -41,12 +41,23 @@
<!-- Optimistic locking -->
<version column="version" name="version" type="long" />
<property name="typeQName" column="type_qname" type="QName" length="255" not-null="true" />
<!-- forward assoc to node type (mandatory) -->
<many-to-one
name="typeQName"
class="org.alfresco.repo.domain.hibernate.QNameEntityImpl"
column="type_qname_id"
foreign-key="fk_alf_n_tqname"
lazy="proxy"
fetch="select"
unique="false"
not-null="true"
cascade="none" />
<!-- forward assoc to access control list (optional) -->
<many-to-one
name="accessControlList"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"
column="acl_id"
foreign-key="fk_alf_n_acl"
lazy="proxy"
fetch="select"
unique="false"
@@ -62,18 +73,18 @@
inverse="false"
optimistic-lock="true"
cascade="delete" >
<key column="node_id" not-null="true" />
<map-key column="qname" type="QName" length="200" />
<key column="node_id" foreign-key="fk_alf_n_prop" not-null="true" />
<map-key column="qname_id" type="long" />
<composite-element class="org.alfresco.repo.domain.PropertyValue" >
<property name="actualType" column="actual_type" type="string" length="15" not-null="true" />
<property name="actualType" column="actual_type_n" type="integer" not-null="true" />
<property name="persistedType" column="persisted_type_n" type="integer" not-null="true" />
<property name="multiValued" column="multi_valued" type="boolean" not-null="true" />
<property name="persistedType" column="persisted_type" type="string" length="15" not-null="true" />
<property name="booleanValue" column="boolean_value" type="boolean" />
<property name="longValue" column="long_value" type="long" />
<property name="floatValue" column="float_value" type="float" />
<property name="doubleValue" column="double_value" type="double" />
<property name="stringValue" column="string_value" type="string" length="1024"/>
<many-to-one name="attributeValue" column="attribute_value" class="org.alfresco.repo.attributes.AttributeImpl" />
<many-to-one name="attributeValue" column="attribute_value" foreign-key="fk_alf_np_attr" class="org.alfresco.repo.attributes.AttributeImpl" />
<property name="serializableValue" column="serializable_value" type="serializable" length="16384"/>
</composite-element>
</map>
@@ -87,22 +98,9 @@
sort="unsorted"
optimistic-lock="true"
cascade="delete" >
<key column="node_id" not-null="true" />
<element column="qname" type="QName" length="200"/>
<key column="node_id" foreign-key="fk_alf_n_asp" not-null="true" />
<element column="qname_id" type="long" not-null="true" />
</set>
<!-- inverse assoc to parent childassocs -->
<!--
<set
name="parentAssocs"
inverse="true"
lazy="false"
fetch="join"
cascade="none"
optimistic-lock="true" >
<key column="child_node_id" />
<one-to-many class="org.alfresco.repo.domain.hibernate.ChildAssocImpl" />
</set>
-->
</class>
<class
@@ -127,6 +125,7 @@
name="transaction"
class="org.alfresco.repo.domain.hibernate.TransactionImpl"
column="transaction_id"
foreign-key="fk_alf_ns_trans"
lazy="proxy"
fetch="select"
unique="false"
@@ -137,6 +136,7 @@
name="node"
class="org.alfresco.repo.domain.hibernate.NodeImpl"
column="node_id"
foreign-key="fk_alf_ns_node"
lazy="false"
fetch="join"
unique="false"
@@ -162,6 +162,7 @@
name="parent"
class="org.alfresco.repo.domain.hibernate.NodeImpl"
lazy="proxy"
foreign-key="fk_alf_ca_pnode"
fetch="select"
optimistic-lock="false"
not-null="true"
@@ -172,14 +173,37 @@
<many-to-one
name="child"
lazy="proxy"
foreign-key="fk_alf_ca_cnode"
fetch="select"
class="org.alfresco.repo.domain.hibernate.NodeImpl"
optimistic-lock="false"
not-null="true" >
<column name="child_node_id" not-null="true"/>
</many-to-one>
<property name="typeQName" column="type_qname" type="QName" length="255" not-null="true" unique-key="UIDX_CHILD_NAME" />
<property name="qname" column="qname" type="QName" length="255" not-null="true" />
<!-- forward assoc to assoc type (mandatory) -->
<many-to-one
name="typeQName"
class="org.alfresco.repo.domain.hibernate.QNameEntityImpl"
column="type_qname_id"
foreign-key="fk_alf_ca_tqn"
unique-key="UIDX_CHILD_NAME"
lazy="proxy"
fetch="select"
unique="false"
not-null="true"
cascade="none" />
<!-- forward assoc to namespace for local QName (mandatory) -->
<many-to-one
name="qnameNamespace"
class="org.alfresco.repo.domain.hibernate.NamespaceEntityImpl"
column="qname_ns_id"
foreign-key="fk_alf_ca_qn_ns"
lazy="proxy"
fetch="select"
unique="false"
not-null="true"
cascade="none" />
<property name="qnameLocalName" column="qname_localname" type="string" length="200" not-null="true" index="idx_alf_ca_qn_ln" />
<property name="childNodeName" column="child_node_name" type="string" length="50" not-null="true" unique-key="UIDX_CHILD_NAME" />
<property name="childNodeNameCrc" column="child_node_name_crc" type="long" not-null="true" unique-key="UIDX_CHILD_NAME" />
<property name="isPrimary" column="is_primary" />
@@ -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" >
<column name="target_node_id" not-null="true" />
</many-to-one>
<property name="typeQName" column="type_qname" type="QName" length="255" not-null="true" />
<!-- forward assoc to assoc type (mandatory) -->
<many-to-one
name="typeQName"
class="org.alfresco.repo.domain.hibernate.QNameEntityImpl"
column="type_qname_id"
foreign-key="fk_alf_na_tqn"
lazy="proxy"
fetch="select"
unique="false"
not-null="true"
cascade="none" />
</natural-id>
<!-- Optimistic locking -->
<version column="version" name="version" type="long" />
@@ -235,7 +271,7 @@
assoc.childNodeName = :newName,
assoc.childNodeNameCrc = :newNameCrc
where
assoc.id = :childAssocId
assoc = :childAssoc
</query>
<query name="node.GetParentAssocs">
@@ -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
</query>
<query name="node.GetChildAssocsByAll">
@@ -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
</query>
@@ -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 @@
<query name="node.GetChildAssocRefs">
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 @@
<query name="node.GetChildAssocRefsByQName">
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
</query>
@@ -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
</query>
<query name="node.GetTargetAssocs">
@@ -388,7 +428,7 @@
join assoc.source as source
join assoc.target as target
where
assoc.source.id = :sourceId
assoc.source = :source
</query>
<query name="node.GetSourceAssocs">
@@ -399,7 +439,7 @@
join assoc.source as source
join assoc.target as target
where
assoc.target.id = :targetId
assoc.target = :target
</query>
<query name="node.GetNodesWithPropertyValuesByActualType">
@@ -414,7 +454,7 @@
prop.actualType = :actualTypeString or
prop.actualType = 'SERIALIZABLE'
) and
prop.persistedType != 'NULL'
prop.persistedType != 0
</query>
<query name="node.patch.GetNodesWithPersistedSerializableProperties">

View File

@@ -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

View File

@@ -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<QName> aspects;
private QNameEntity typeQName;
private Set<Long> aspects;
private Collection<ChildAssoc> parentAssocs;
private Map<QName, PropertyValue> properties;
private Map<Long, PropertyValue> 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<QName>(5);
aspects = new HashSet<Long>(5);
parentAssocs = new HashSet<ChildAssoc>(5);
properties = new HashMap<QName, PropertyValue>(5);
properties = new HashMap<Long, PropertyValue>(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<QName> getAspects()
public Set<Long> getAspects()
{
return aspects;
}
@@ -238,7 +238,7 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setAspects(Set<QName> aspects)
private void setAspects(Set<Long> aspects)
{
this.aspects = aspects;
}
@@ -257,7 +257,7 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
this.parentAssocs = parentAssocs;
}
public Map<QName, PropertyValue> getProperties()
public Map<Long, PropertyValue> getProperties()
{
return properties;
}
@@ -266,7 +266,7 @@ public class NodeImpl extends LifecycleAdapter implements Node, Serializable
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setProperties(Map<QName, PropertyValue> properties)
private void setProperties(Map<Long, PropertyValue> properties)
{
this.properties = properties;
}

View File

@@ -5,6 +5,9 @@
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
<hibernate-mapping>
<typedef class="org.alfresco.repo.domain.hibernate.QNameUserType" name="QName" />
<class
name="org.alfresco.repo.domain.hibernate.DbAccessControlListChangeSetImpl"
proxy="org.alfresco.repo.domain.DbAccessControlListChangeSet"
@@ -67,6 +70,7 @@
name="aclChangeSet"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListChangeSetImpl"
column="acl_change_set"
foreign-key="fk_alf_acl_acs"
lazy="proxy"
fetch="select"
unique="false"
@@ -115,23 +119,34 @@
<natural-id>
<many-to-one name="permission"
class="org.alfresco.repo.domain.hibernate.DbPermissionImpl"
column="permission_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
column="permission_id"
foreign-key="fk_alf_ace_perm"
lazy="no-proxy"
fetch="select"
optimistic-lock="true"
not-null="true"/>
<many-to-one name="authority"
class="org.alfresco.repo.domain.hibernate.DbAuthorityImpl"
column="authority_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="true"/>
<property name="allowed" column="allowed" type="boolean"
column="authority_id"
foreign-key="fk_alf_ace_auth"
lazy="no-proxy"
fetch="select"
optimistic-lock="true"
not-null="true"/>
<property name="allowed" column="allowed" type="boolean" not-null="true"/>
<property name="applies" column="applies" type="int" not-null="true"/>
<many-to-one name="context"
class="org.alfresco.repo.domain.hibernate.DbAccessControlEntryContextImpl"
column="context_id" lazy="no-proxy" fetch="select"
optimistic-lock="true" not-null="false"/>
column="context_id"
foreign-key="fk_alf_ace_ctx"
lazy="no-proxy"
fetch="select"
optimistic-lock="true"
not-null="false"/>
</natural-id>
<version column="version" name="version" type="long"/>

View File

@@ -0,0 +1,82 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
'-//Hibernate/Hibernate Mapping DTD 3.0//EN'
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
<hibernate-mapping>
<class
name="org.alfresco.repo.domain.hibernate.NamespaceEntityImpl"
proxy="org.alfresco.repo.domain.NamespaceEntity"
table="alf_namespace"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
lazy="true"
optimistic-lock="version" >
<!-- auto-generated ID -->
<id name="id" column="id" type="long" >
<generator class="native" />
</id>
<!-- Namespace URL must be unique -->
<natural-id mutable="true">
<property name="uri" column="uri" type="string" length="100" not-null="true" />
</natural-id>
<!-- Optimistic locking -->
<version column="version" name="version" type="long" />
</class>
<class
name="org.alfresco.repo.domain.hibernate.QNameEntityImpl"
proxy="org.alfresco.repo.domain.QNameEntity"
table="alf_qname"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
lazy="true"
optimistic-lock="version" >
<!-- auto-generated ID -->
<id name="id" column="id" type="long" >
<generator class="native" />
</id>
<!-- Namespace and localname must be unique -->
<natural-id mutable="true">
<!-- forward assoc to namespace -->
<many-to-one
name="namespace"
class="org.alfresco.repo.domain.hibernate.NamespaceEntityImpl"
column="ns_id"
foreign-key="fk_alf_qname_ns"
lazy="proxy"
fetch="join"
unique="false"
not-null="true"
cascade="none" />
<property name="localName" column="local_name" type="string" length="200" not-null="true" />
</natural-id>
<!-- Optimistic locking -->
<version column="version" name="version" type="long" />
</class>
<query name="qname.GetNamespaceByUri" flush-mode="never" cacheable="false">
select
namespace
from
org.alfresco.repo.domain.hibernate.NamespaceEntityImpl as namespace
where
namespace.uri = :namespaceUri
</query>
<query name="qname.GetQNameByUriAndLocalName" flush-mode="never" cacheable="false">
select
qname
from
org.alfresco.repo.domain.hibernate.QNameEntityImpl as qname
join qname.namespace as namespace
where
namespace.uri = :namespaceUri and
qname.localName = :localName
</query>
</hibernate-mapping>

View File

@@ -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 <b>QnameEntity</b>.
*
* @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 <code>QName</code> 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();
}
}
}

View File

@@ -25,6 +25,7 @@
<many-to-one
name="rootNode"
not-null="true"
foreign-key="fk_alf_store_rn"
lazy="proxy"
class="org.alfresco.repo.domain.hibernate.NodeImpl"
fetch="select" >

View File

@@ -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"