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

@@ -31,6 +31,9 @@ import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.avm.AVMAspectName;
import org.alfresco.repo.avm.AVMAspectNameDAO;
import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.repo.domain.QNameEntity;
import org.alfresco.service.namespace.QName;
/**
* Patches from old style aspect storage for AVM to new style.
@@ -41,12 +44,18 @@ public class AVMAspectsPatch extends AbstractPatch
private static final String MSG_SUCCESS = "patch.AVMAspects.result";
private AVMAspectNameDAO fAVMAspectDAO;
private QNameDAO qnameDAO;
public void setAvmAspectNameDAO(AVMAspectNameDAO dao)
{
fAVMAspectDAO = dao;
}
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
/* (non-Javadoc)
* @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal()
*/
@@ -57,7 +66,9 @@ public class AVMAspectsPatch extends AbstractPatch
while (iter.hasNext())
{
AVMAspectName aspect = iter.next();
aspect.getNode().getAspects().add(aspect.getName());
QName aspectQName = aspect.getName();
QNameEntity aspectQNameEntity = qnameDAO.getOrCreateQNameEntity(aspectQName);
aspect.getNode().getAspects().add(aspectQNameEntity.getId());
fAVMAspectDAO.delete(aspect);
}
return I18NUtil.getMessage(MSG_SUCCESS);

View File

@@ -31,6 +31,8 @@ import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.avm.AVMNodeProperty;
import org.alfresco.repo.avm.AVMNodePropertyDAO;
import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.service.namespace.QName;
/**
* Patch more remapping AVM properties.
@@ -40,8 +42,14 @@ public class AVMPropertiesPatch extends AbstractPatch
{
private static final String MSG_SUCCESS = "patch.AVMProperties.result";
private QNameDAO qnameDAO;
private AVMNodePropertyDAO fAVMNodePropertyDAO;
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
public void setAvmNodePropertyDAO(AVMNodePropertyDAO dao)
{
fAVMNodePropertyDAO = dao;
@@ -57,7 +65,9 @@ public class AVMPropertiesPatch extends AbstractPatch
while (iter.hasNext())
{
AVMNodeProperty prop = iter.next();
prop.getNode().getProperties().put(prop.getName(), prop.getValue());
QName propertyQName = prop.getName();
Long propertyQNameEntityId = qnameDAO.getOrCreateQNameEntity(propertyQName).getId();
prop.getNode().getProperties().put(propertyQNameEntityId, prop.getValue());
fAVMNodePropertyDAO.delete(prop.getNode(), prop.getName());
}
return I18NUtil.getMessage(MSG_SUCCESS);

View File

@@ -33,7 +33,6 @@ import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.namespace.QName;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@@ -104,9 +103,9 @@ public class NodePropertySerializablePatch extends AbstractPatch
{
Node node = iterator.next();
// retrieve the node properties
Map<QName, PropertyValue> properties = node.getProperties();
Map<Long, PropertyValue> properties = node.getProperties();
// check each property
for (Map.Entry<QName, PropertyValue> entry : properties.entrySet())
for (Map.Entry<Long, PropertyValue> entry : properties.entrySet())
{
PropertyValue propertyValue = entry.getValue();
if (propertyValue.getSerializableValue() == null)

View File

@@ -14,7 +14,7 @@
</id>
<discriminator column="type" type="string" length="1"/>
<version column="version" name="version" type="long"/>
<many-to-one name="acl" column="acl_id" foreign-key="fk_attributes_n_acl"
<many-to-one name="acl" column="acl_id" foreign-key="fk_alf_attr_acl"
class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"/>
<!-- A boolean valued attribute -->
<subclass name="BooleanAttributeImpl" proxy="BooleanAttribute" lazy="false"
@@ -75,22 +75,22 @@
<class name="GlobalAttributeEntryImpl" proxy="GlobalAttributeEntry" table="alf_global_attributes" lazy="false">
<cache usage="read-write"/>
<id name="name" type="string" length="160"/>
<many-to-one class="AttributeImpl" name="attribute" unique="true" lazy="false"/>
<many-to-one class="AttributeImpl" foreign-key="fk_alf_gatt_att" name="attribute" unique="true" lazy="false"/>
</class>
<class name="MapEntryImpl" proxy="MapEntry" lazy="false" table="alf_map_attribute_entries">
<cache usage="read-write"/>
<composite-id name="key" class="MapEntryKey">
<key-many-to-one class="MapAttributeImpl" name="map" column="map_id"/>
<key-many-to-one class="MapAttributeImpl" name="map" column="map_id" foreign-key="fk_alf_matt_matt"/>
<key-property name="key" type="string" length="160" column="mkey"/>
</composite-id>
<many-to-one class="AttributeImpl" name="attribute" column="attribute_id" lazy="false"/>
<many-to-one class="AttributeImpl" name="attribute" column="attribute_id" lazy="false" foreign-key="fk_alf_matt_att"/>
</class>
<class name="ListEntryImpl" proxy="ListEntry" lazy="false" table="alf_list_attribute_entries">
<cache usage="read-write"/>
<composite-id name="key" class="ListEntryKey">
<key-many-to-one class="ListAttributeImpl" name="list" column="list_id"/>
<key-many-to-one class="ListAttributeImpl" name="list" column="list_id" foreign-key="fk_alf_lent_latt"/>
<key-property name="index" type="int" column="mindex"/>
</composite-id>
<many-to-one class="AttributeImpl" name="attribute" column="attribute_id" lazy="false"/>
<many-to-one class="AttributeImpl" name="attribute" column="attribute_id" lazy="false" foreign-key="fk_alf_lent_att"/>
</class>
</hibernate-mapping>

View File

@@ -49,9 +49,9 @@
<!-- Links to dimensions -->
<many-to-one name="auditDate" class="org.alfresco.repo.audit.hibernate.AuditDateImpl" not-null="true" lazy="proxy" column="audit_date_id" cascade="none" optimistic-lock="true" fetch="join"/>
<many-to-one name="auditConfig" class="org.alfresco.repo.audit.hibernate.AuditConfigImpl" not-null="true" lazy="proxy" column="audit_conf_id" cascade="none" optimistic-lock="true" fetch="join"/>
<many-to-one name="auditSource" class="org.alfresco.repo.audit.hibernate.AuditSourceImpl" not-null="true" lazy="proxy" column="audit_source_id" cascade="none" optimistic-lock="true" fetch="join"/>
<many-to-one name="auditDate" class="org.alfresco.repo.audit.hibernate.AuditDateImpl" not-null="true" lazy="proxy" column="audit_date_id" foreign-key="fk_alf_adtf_date" cascade="none" optimistic-lock="true" fetch="join"/>
<many-to-one name="auditConfig" class="org.alfresco.repo.audit.hibernate.AuditConfigImpl" not-null="true" lazy="proxy" column="audit_conf_id" foreign-key="fk_alf_adtf_conf" cascade="none" optimistic-lock="true" fetch="join"/>
<many-to-one name="auditSource" class="org.alfresco.repo.audit.hibernate.AuditSourceImpl" not-null="true" lazy="proxy" column="audit_source_id" foreign-key="fk_alf_adtf_src" cascade="none" optimistic-lock="true" fetch="join"/>
</class>

View File

@@ -7,6 +7,7 @@ import org.alfresco.repo.attributes.AttributeDAO;
import org.alfresco.repo.attributes.GlobalAttributeEntryDAO;
import org.alfresco.repo.attributes.ListEntryDAO;
import org.alfresco.repo.attributes.MapEntryDAO;
import org.alfresco.repo.domain.QNameDAO;
/**
* This is the (shudder) global context for AVM. It a rendezvous
@@ -44,6 +45,11 @@ public class AVMDAOs
*/
public AVMNodeDAO fAVMNodeDAO;
/**
* The QName DAO
*/
public QNameDAO fQNameDAO;
/**
* The AVMStore DAO.
*/
@@ -102,6 +108,11 @@ public class AVMDAOs
fAVMNodeDAO = nodeDAO;
}
public void setQnameDAO(QNameDAO qnameDAO)
{
this.fQNameDAO = qnameDAO;
}
/**
* @param childEntryDAO the fChildEntryDAO to set
*/

View File

@@ -28,7 +28,6 @@ import java.util.Set;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.namespace.QName;
/**
* The Interface for versionable objects.
@@ -153,35 +152,35 @@ public interface AVMNode
/**
* Set a property.
* @param name The name of the property.
* @param value The value to set.
* @param qnameEntityId the ID of the QName to set
* @param value The value to set.
*/
public void setProperty(QName name, PropertyValue value);
public void setProperty(Long qnameEntityId, PropertyValue value);
/**
* Set a collection of properties on this node.
* @param properties The Map of QNames to PropertyValues.
* @param properties The Map of QName entity IDs to PropertyValues.
*/
public void setProperties(Map<QName, PropertyValue> properties);
public void setProperties(Map<Long, PropertyValue> properties);
/**
* Get a property by name.
* @param name The name of the property to get.
* @return A PropertyValue
*/
public PropertyValue getProperty(QName name);
public PropertyValue getProperty(Long name);
/**
* Get all the properties associated with this node.
* @return A Map of QNames to PropertyValues.
*/
public Map<QName, PropertyValue> getProperties();
public Map<Long, PropertyValue> getProperties();
/**
* Delete a property from this node.
* @param name The name of the property.
* @param qnameEntityId the ID of the QName to delete
*/
public void deleteProperty(QName name);
public void deleteProperty(Long qnameEntityId);
/**
* Delete all properties from this node.
@@ -232,15 +231,15 @@ public interface AVMNode
/**
* Get the Aspects that this node has.
* @return A Set of Aspects names.
* @return A Set of Aspects IDs.
*/
public Set<QName> getAspects();
public Set<Long> getAspects();
/**
* Add properties to those that already exist.
* @param properties The properties to add.
*/
public void addProperties(Map<QName, PropertyValue> properties);
public void addProperties(Map<Long, PropertyValue> properties);
/**
* Get the Basic Attributes on this node.

View File

@@ -34,7 +34,6 @@ import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.service.cmr.avm.AVMReadOnlyException;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.GUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -47,7 +46,7 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
{
private static Log fgLogger = LogFactory.getLog(AVMNodeImpl.class);
protected static final boolean DEBUG = true;
protected static final boolean DEBUG = fgLogger.isDebugEnabled();
/**
* The Object ID.
@@ -92,17 +91,17 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
/**
* The Aspects that belong to this node.
*/
private Set<QName> fAspects;
private Set<Long> fAspects;
private Map<QName, PropertyValue> fProperties;
private Map<Long, PropertyValue> fProperties;
/**
* Default constructor.
*/
protected AVMNodeImpl()
{
fAspects = new HashSet<QName>();
fProperties = new HashMap<QName, PropertyValue>();
fAspects = new HashSet<Long>();
fProperties = new HashMap<Long, PropertyValue>();
}
/**
@@ -113,8 +112,8 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
protected AVMNodeImpl(long id,
AVMStore store)
{
fAspects = new HashSet<QName>();
fProperties = new HashMap<QName, PropertyValue>();
fAspects = new HashSet<Long>();
fProperties = new HashMap<Long, PropertyValue>();
fID = id;
fVersionID = -1;
fIsRoot = false;
@@ -351,8 +350,8 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
*/
protected void copyProperties(AVMNode other)
{
fProperties = new HashMap<QName, PropertyValue>();
for (Map.Entry<QName, PropertyValue> entry : other.getProperties().entrySet())
fProperties = new HashMap<Long, PropertyValue>();
for (Map.Entry<Long, PropertyValue> entry : other.getProperties().entrySet())
{
fProperties.put(entry.getKey(), entry.getValue());
}
@@ -364,7 +363,7 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
*/
protected void copyAspects(AVMNode other)
{
fAspects = new HashSet<QName>(other.getAspects());
fAspects = new HashSet<Long>(other.getAspects());
}
protected void copyACLs(AVMNode other, Long parentAcl, ACLCopyMode mode)
@@ -392,18 +391,18 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
* @param name The name of the property.
* @param value The value to set.
*/
public void setProperty(QName name, PropertyValue value)
public void setProperty(Long qnameEntityId, PropertyValue value)
{
if (DEBUG)
{
checkReadOnly();
}
fProperties.put(name, value);
fProperties.put(qnameEntityId, value);
}
public void addProperties(Map<QName, PropertyValue> properties)
public void addProperties(Map<Long, PropertyValue> properties)
{
for (Map.Entry<QName, PropertyValue> entry : properties.entrySet())
for (Map.Entry<Long, PropertyValue> entry : properties.entrySet())
{
fProperties.put(entry.getKey(), entry.getValue());
}
@@ -413,7 +412,7 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
* Set a collection of properties on this node.
* @param properties The Map of QNames to PropertyValues.
*/
public void setProperties(Map<QName, PropertyValue> properties)
public void setProperties(Map<Long, PropertyValue> properties)
{
fProperties = properties;
}
@@ -423,16 +422,15 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
* @param name The name of the property.
* @return The PropertyValue or null if non-existent.
*/
public PropertyValue getProperty(QName name)
public PropertyValue getProperty(Long qnameEntityId)
{
return fProperties.get(name);
return fProperties.get(qnameEntityId);
}
/**
* Get all the properties associated with this node.
* @return A Map of QNames to PropertyValues.
* {@inheritDoc}
*/
public Map<QName, PropertyValue> getProperties()
public Map<Long, PropertyValue> getProperties()
{
return fProperties;
}
@@ -441,13 +439,13 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
* Delete a property from this node.
* @param name The name of the property.
*/
public void deleteProperty(QName name)
public void deleteProperty(Long qnameEntityId)
{
if (DEBUG)
{
checkReadOnly();
}
fProperties.remove(name);
fProperties.remove(qnameEntityId);
}
/**
@@ -521,7 +519,7 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
/* (non-Javadoc)
* @see org.alfresco.repo.avm.AVMNode#getAspects()
*/
public Set<QName> getAspects()
public Set<Long> getAspects()
{
return fAspects;
}
@@ -530,7 +528,7 @@ public abstract class AVMNodeImpl implements AVMNode, Serializable
* Set the aspects on this node.
* @param aspects
*/
public void setAspects(Set<QName> aspects)
public void setAspects(Set<Long> aspects)
{
fAspects = aspects;
}

View File

@@ -39,6 +39,7 @@ import org.alfresco.model.WCMModel;
import org.alfresco.repo.content.ContentStore;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
@@ -105,6 +106,8 @@ public class AVMRepository
* The Lookup Cache instance.
*/
private LookupCache fLookupCache;
private QNameDAO qnameDAO;
private AVMStoreDAO fAVMStoreDAO;
@@ -214,6 +217,11 @@ public class AVMRepository
fPurgeVersionTxnListener = listener;
}
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
public void setAvmStoreDAO(AVMStoreDAO dao)
{
fAVMStoreDAO = dao;
@@ -2318,7 +2326,7 @@ public class AVMRepository
Map<QName, PropertyValue> results = new HashMap<QName, PropertyValue>();
for (AVMStoreProperty prop : matches)
{
results.put(prop.getName(), prop.getValue());
results.put(prop.getName().getQName(), prop.getValue());
}
return results;
}
@@ -2346,7 +2354,7 @@ public class AVMRepository
pairs = new HashMap<QName, PropertyValue>();
results.put(storeName, pairs);
}
pairs.put(prop.getName(), prop.getValue());
pairs.put(prop.getName().getQName(), prop.getValue());
}
return results;
}
@@ -3096,7 +3104,10 @@ public class AVMRepository
{
throw new AccessDeniedException("Not allowed to read properties: " + desc);
}
return node.getProperties();
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
@SuppressWarnings("unchecked")
Map<QName, PropertyValue> converted = (Map<QName, PropertyValue>) qnameDAO.convertIdMapToQNameMap(node.getProperties());
return converted;
}
public ContentData getContentDataForRead(AVMNodeDescriptor desc)
@@ -3129,8 +3140,10 @@ public class AVMRepository
{
throw new AccessDeniedException("Not allowed to read properties: " + desc);
}
Set<QName> aspects = node.getAspects();
return aspects;
Set<Long> aspectIds = node.getAspects();
// Convert to QNames
Set<QName> aspectQNames = qnameDAO.convertIdsToQNames(aspectIds);
return aspectQNames;
}
/**
@@ -3163,22 +3176,32 @@ public class AVMRepository
}
PermissionContext context = new PermissionContext(type);
context.addDynamicAuthorityAssignment(node.getBasicAttributes().getOwner(), PermissionService.OWNER_AUTHORITY);
context.getAspects().addAll(node.getAspects());
Map<QName, PropertyValue> props = node.getProperties();
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(5);
for (Map.Entry<QName, PropertyValue> entry : props.entrySet())
// Pass in node aspects
Set<Long> nodeAspectQNameIds = node.getAspects();
Set<QName> contextQNames = context.getAspects();
for (Long nodeAspectQNameId : nodeAspectQNameIds)
{
PropertyDefinition def = fDictionaryService.getProperty(entry.getKey());
QName qname = qnameDAO.getQName(nodeAspectQNameId);
contextQNames.add(qname);
}
// Pass in node properties
Map<Long, PropertyValue> nodeProperties = node.getProperties();
Map<QName, Serializable> contextProperties = new HashMap<QName, Serializable>(5);
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
for (Map.Entry<Long, PropertyValue> entry : nodeProperties.entrySet())
{
QName qname = qnameDAO.getQName(entry.getKey());
PropertyDefinition def = fDictionaryService.getProperty(qname);
if (def == null)
{
properties.put(entry.getKey(), entry.getValue().getValue(DataTypeDefinition.ANY));
contextProperties.put(qname, entry.getValue().getValue(DataTypeDefinition.ANY));
}
else
{
properties.put(entry.getKey(), entry.getValue().getValue(def.getDataType().getName()));
contextProperties.put(qname, entry.getValue().getValue(def.getDataType().getName()));
}
}
context.getProperties().putAll(properties);
context.getProperties().putAll(contextProperties);
Long aclId = null;
if(acl != null)
{

File diff suppressed because it is too large Load Diff

View File

@@ -43,6 +43,8 @@ import org.alfresco.repo.avm.util.SimplePath;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.security.permissions.ACLCopyMode;
import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.repo.domain.QNameEntity;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.avm.AVMBadArgumentException;
import org.alfresco.service.cmr.avm.AVMException;
@@ -367,11 +369,26 @@ public class AVMStoreImpl implements AVMStore, Serializable
dir.putChild(name, newDir);
if (aspects != null)
{
newDir.getAspects().addAll(aspects);
// Convert the aspect QNames to entities
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
Set<Long> aspectQNameEntityIds = newDir.getAspects();
for (QName aspectQName : aspects)
{
Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(aspectQName).getId();
aspectQNameEntityIds.add(qnameEntityId);
}
}
if (properties != null)
{
newDir.getProperties().putAll(properties);
// Convert the property QNames to entities
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
Map<Long, PropertyValue> propertiesByQNameEntityId = new HashMap<Long, PropertyValue>(properties.size() * 2 + 1);
for (Map.Entry<QName, PropertyValue> entry : properties.entrySet())
{
Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(entry.getKey()).getId();
propertiesByQNameEntityId.put(qnameEntityId, entry.getValue());
}
newDir.getProperties().putAll(propertiesByQNameEntityId);
}
DbAccessControlList acl = dir.getAcl();
newDir.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null);
@@ -503,11 +520,26 @@ public class AVMStoreImpl implements AVMStore, Serializable
"UTF-8"));
if (aspects != null)
{
file.getAspects().addAll(aspects);
// Convert the aspect QNames to entities
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
Set<Long> aspectQNameEntityIds = file.getAspects();
for (QName aspectQName : aspects)
{
Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(aspectQName).getId();
aspectQNameEntityIds.add(qnameEntityId);
}
}
if (properties != null)
{
file.getProperties().putAll(properties);
// Convert the property QNames to entities
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
Map<Long, PropertyValue> propertiesByQNameEntityId = new HashMap<Long, PropertyValue>(properties.size() * 2 + 1);
for (Map.Entry<QName, PropertyValue> entry : properties.entrySet())
{
Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(entry.getKey()).getId();
propertiesByQNameEntityId.put(qnameEntityId, entry.getValue());
}
file.getProperties().putAll(propertiesByQNameEntityId);
}
DbAccessControlList acl = dir.getAcl();
file.setAcl(acl != null ? acl.getCopy(acl.getId(), ACLCopyMode.INHERIT) : null);
@@ -1159,7 +1191,9 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to write: " + path);
}
node.setProperty(name, value);
QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getOrCreateQNameEntity(name);
node.setProperty(qnameEntity.getId(), value);
node.setGuid(GUID.generate());
}
@@ -1180,7 +1214,18 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to write: " + path);
}
node.addProperties(properties);
if (properties != null)
{
// Convert the property QNames to entities
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
Map<Long, PropertyValue> propertiesByQNameEntityId = new HashMap<Long, PropertyValue>(properties.size() * 2 + 1);
for (Map.Entry<QName, PropertyValue> entry : properties.entrySet())
{
Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(entry.getKey()).getId();
propertiesByQNameEntityId.put(qnameEntityId, entry.getValue());
}
node.addProperties(propertiesByQNameEntityId);
}
node.setGuid(GUID.generate());
}
@@ -1203,8 +1248,19 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to read: " + path);
}
PropertyValue prop = node.getProperty(name);
return prop;
// Convert the QName
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
QNameEntity qnameEntity = qnameDAO.getOrCreateQNameEntity(name);
if (qnameEntity == null)
{
// No such QName
return null;
}
else
{
PropertyValue prop = node.getProperty(qnameEntity.getId());
return prop;
}
}
/**
@@ -1225,8 +1281,12 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to read: " + path);
}
Map<QName, PropertyValue> props = node.getProperties();
return props;
Map<Long, PropertyValue> props = node.getProperties();
// Convert to QNames
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
@SuppressWarnings("unchecked")
Map<QName, PropertyValue> convertedProps = (Map<QName, PropertyValue>) qnameDAO.convertIdMapToQNameMap(props);
return convertedProps;
}
/**
@@ -1247,7 +1307,17 @@ public class AVMStoreImpl implements AVMStore, Serializable
throw new AccessDeniedException("Not allowed to write: " + path);
}
node.setGuid(GUID.generate());
node.deleteProperty(name);
// convert the QName
QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getQNameEntity(name);
if (qnameEntity == null)
{
// No such property
}
else
{
node.deleteProperty(qnameEntity.getId());
}
}
/**
@@ -1277,9 +1347,10 @@ public class AVMStoreImpl implements AVMStore, Serializable
*/
public void setProperty(QName name, PropertyValue value)
{
QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getOrCreateQNameEntity(name);
AVMStoreProperty prop = new AVMStorePropertyImpl();
prop.setStore(this);
prop.setName(name);
prop.setName(qnameEntity);
prop.setValue(value);
AVMDAOs.Instance().fAVMStorePropertyDAO.save(prop);
}
@@ -1322,7 +1393,7 @@ public class AVMStoreImpl implements AVMStore, Serializable
Map<QName, PropertyValue> retVal = new HashMap<QName, PropertyValue>();
for (AVMStoreProperty prop : props)
{
retVal.put(prop.getName(), prop.getValue());
retVal.put(prop.getName().getQName(), prop.getValue());
}
return retVal;
}
@@ -1454,7 +1525,11 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to write: " + path);
}
node.getAspects().add(aspectName);
// Convert the aspect QNames to entities
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
Long qnameEntityId = qnameDAO.getOrCreateQNameEntity(aspectName).getId();
// Convert the
node.getAspects().add(qnameEntityId);
node.setGuid(GUID.generate());
}
@@ -1476,8 +1551,10 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to read properties: " + path);
}
Set<QName> aspects = node.getAspects();
return aspects;
Set<Long> aspects = node.getAspects();
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
Set<QName> aspectQNames = qnameDAO.convertIdsToQNames(aspects);
return aspectQNames;
}
/**
@@ -1497,13 +1574,20 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to write properties: " + path);
}
node.getAspects().remove(aspectName);
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
// Get the persistent ID for the QName and remove from the set
QNameEntity qnameEntity = qnameDAO.getQNameEntity(aspectName);
if (qnameEntity != null)
{
node.getAspects().remove(qnameEntity.getId());
}
AspectDefinition def = RawServices.Instance().getDictionaryService().getAspect(aspectName);
Map<QName, PropertyDefinition> properties =
def.getProperties();
for (QName name : properties.keySet())
{
node.getProperties().remove(name);
QNameEntity propertyQNameEntity = qnameDAO.getQNameEntity(name);
node.getProperties().remove(propertyQNameEntity.getId());
}
node.setGuid(GUID.generate());
}
@@ -1527,8 +1611,17 @@ public class AVMStoreImpl implements AVMStore, Serializable
{
throw new AccessDeniedException("Not allowed to read properties: " + path);
}
boolean has = node.getAspects().contains(aspectName);
return has;
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
// Get the persistent ID for the QName and remove from the set
QNameEntity qnameEntity = qnameDAO.getQNameEntity(aspectName);
if (qnameEntity != null)
{
return node.getAspects().contains(qnameEntity.getId());
}
else
{
return false;
}
}
/**
@@ -1630,9 +1723,13 @@ public class AVMStoreImpl implements AVMStore, Serializable
toLink.changeAncestor(child);
toLink.setVersionID(child.getVersionID() + 1);
// TODO This really shouldn't be here. Leaking layers.
toLink.getAspects().add(WCMModel.ASPECT_REVERTED);
QNameDAO qnameDAO = AVMDAOs.Instance().fQNameDAO;
QNameEntity revertedQNameEntity = qnameDAO.getOrCreateQNameEntity(WCMModel.ASPECT_REVERTED);
toLink.getAspects().add(revertedQNameEntity.getId());
PropertyValue value = new PropertyValue(null, toRevertTo.getId());
toLink.setProperty(WCMModel.PROP_REVERTED_ID, value);
QNameEntity qnameEntity = AVMDAOs.Instance().fQNameDAO.getOrCreateQNameEntity(WCMModel.PROP_REVERTED_ID);
toLink.setProperty(qnameEntity.getId(), value);
}
/* (non-Javadoc)

View File

@@ -24,7 +24,7 @@
package org.alfresco.repo.avm;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.namespace.QName;
import org.alfresco.repo.domain.QNameEntity;
/**
* Arbitrary properties associated with AVMStores.
@@ -46,15 +46,15 @@ public interface AVMStoreProperty
/**
* Set the name of the property.
* @param name The QName for the property.
* @param qnameEntity The QNameEntity for the property.
*/
public void setName(QName name);
public void setName(QNameEntity qnameEntity);
/**
* Get the name of this property.
* @return The QName of this property.
* @return The QNameEntity of this property.
*/
public QName getName();
public QNameEntity getName();
/**
* Set the actual property value.

View File

@@ -26,7 +26,7 @@ package org.alfresco.repo.avm;
import java.io.Serializable;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.namespace.QName;
import org.alfresco.repo.domain.QNameEntity;
/**
* Simple bean to hold properties attached to AVMStores.
@@ -49,7 +49,7 @@ class AVMStorePropertyImpl implements AVMStoreProperty, Serializable
/**
* The name of the property.
*/
private QName fName;
private QNameEntity name;
/**
* The actual PropertyValue.
@@ -61,21 +61,19 @@ class AVMStorePropertyImpl implements AVMStoreProperty, Serializable
}
/**
* Get the name of the property.
* @return The QName for the property.
* {@inheritDoc}
*/
public QName getName()
public QNameEntity getName()
{
return fName;
return name;
}
/**
* Set the name of the property.
* @param name The QName of the property.
* {@inheritDoc}
*/
public void setName(QName name)
public void setName(QNameEntity name)
{
fName = name;
this.name = name;
}
/**
@@ -144,13 +142,13 @@ class AVMStorePropertyImpl implements AVMStoreProperty, Serializable
return false;
}
AVMStoreProperty o = (AVMStoreProperty)other;
return fStore.equals(o.getStore()) && fName.equals(o.getName());
return fStore.equals(o.getStore()) && name.equals(o.getName());
}
@Override
public int hashCode()
{
return fStore.hashCode() + fName.hashCode();
return fStore.hashCode() + name.hashCode();
}
}

View File

@@ -24,7 +24,6 @@
package org.alfresco.repo.avm;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -36,7 +35,6 @@ import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.QName;
/**
@@ -119,8 +117,8 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
public PlainFileNodeImpl(AVMStore store,
BasicAttributes attrs,
ContentData content,
Map<QName, PropertyValue> props,
Set<QName> aspects,
Map<Long, PropertyValue> props,
Set<Long> aspects,
DbAccessControlList acl,
int versionID, Long parentAcl, ACLCopyMode mode)
{
@@ -131,7 +129,7 @@ class PlainFileNodeImpl extends FileNodeImpl implements PlainFileNode
AVMDAOs.Instance().fAVMNodeDAO.save(this);
AVMDAOs.Instance().fAVMNodeDAO.flush();
addProperties(props);
setAspects(new HashSet<QName>(aspects));
setAspects(new HashSet<Long>(aspects));
if (acl != null)
{
setAcl(acl.getCopy(parentAcl, mode));

View File

@@ -2,7 +2,7 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.alfresco.repo.avm">
<typedef class="org.alfresco.repo.domain.hibernate.QNameUserType" name="QName"/>
<typedef class="org.alfresco.repo.domain.hibernate.QNameUserType" name="QName" />
<!-- AVMNodeBean is the abstract base for filesystem like objects.
We're using the one table per class hierarchy strategy to implement
@@ -48,17 +48,17 @@
class="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl"/>
<set name="aspects" fetch="join" lazy="false" table="avm_aspects_new" cascade="all" optimistic-lock="true">
<cache usage="read-write"/>
<key column="id"/>
<element type="QName" not-null="true" column="name" length="200"/>
<key column="id" not-null="true" foreign-key="fk_avm_asp_n"/>
<element column="qname_id" type="long" not-null="true"/>
</set>
<map name="properties" fetch="join" lazy="false" table="avm_node_properties_new" cascade="all" optimistic-lock="true">
<cache usage="read-write"/>
<key column="node_id" not-null="true"/>
<map-key type="QName" length="200" column="qname"/>
<key column="node_id" not-null="true" foreign-key="fk_avm_np_n"/>
<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" />
@@ -141,6 +141,33 @@
column="current_root_id" cascade="save-update" foreign-key="fk_avm_s_root">
</many-to-one>
</class>
<class name="AVMStorePropertyImpl" proxy="AVMStoreProperty" table="avm_store_properties">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="store" class="AVMStoreImpl" column="avm_store_id" foreign-key="fk_avm_sp_store"/>
<many-to-one
name="name"
class="org.alfresco.repo.domain.hibernate.QNameEntityImpl"
column="qname_id"
foreign-key="fk_avm_sp_qname"
lazy="proxy"
fetch="select"
unique="false"
not-null="true"
cascade="none" />
<component class="org.alfresco.repo.domain.PropertyValue" name="value">
<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="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"/>
<property name="serializableValue" column="serializable_value" type="serializable" length="16384"/>
</component>
</class>
<class name="VersionRootImpl" proxy="VersionRoot" table="avm_version_roots">
<cache usage="read-write"/>
<id name="id" column="id" type="long">
@@ -185,6 +212,20 @@
<key-many-to-one name="mto" class="AVMNodeImpl" column="mto" foreign-key="fk_avm_ml_to"/>
</composite-id>
</class>
<!-- When a snapshot is created we stow away all of the layered
nodes that were frozen by the snapshot so that subsequent
snapshots can find them and force copies. -->
<class name="VersionLayeredNodeEntryImpl" proxy="VersionLayeredNodeEntry"
table="avm_version_layered_node_entry">
<composite-id>
<key-many-to-one name="version" class="VersionRootImpl" column="version_root_id" foreign-key="fk_avm_vlne_vr"/>
<key-property name="md5Sum" type="string" length="32" column="md5sum"/>
</composite-id>
<property name="path" type="string" length="512" column="path"/>
</class>
<!-- DEPRECATED START -->
<!-- These are kept so that the AVMPropertiesPatch and AVMAspectsPatch -->
<class name="AVMNodePropertyImpl" proxy="AVMNodeProperty" table="avm_node_properties">
<id name="id" column="id" type="long">
<generator class="native"/>
@@ -192,27 +233,9 @@
<many-to-one name="node" class="AVMNodeImpl" column="node_id" foreign-key="fk_avm_np_node"/>
<property name="name" column="qname" type="QName" length="200" index="idx_avm_np_name"/>
<component class="org.alfresco.repo.domain.PropertyValue" name="value">
<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"/>
<property name="serializableValue" column="serializable_value" type="serializable" length="16384"/>
</component>
</class>
<class name="AVMStorePropertyImpl" proxy="AVMStoreProperty" table="avm_store_properties">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="store" class="AVMStoreImpl" column="avm_store_id" foreign-key="fk_avm_sp_store"/>
<property name="name" column="qname" type="QName" length="200" index="idx_avm_sp_name"/>
<component class="org.alfresco.repo.domain.PropertyValue" name="value">
<property name="actualType" column="actual_type" type="string" length="15" 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" />
@@ -229,17 +252,8 @@
<many-to-one name="node" class="AVMNodeImpl" column="node_id" foreign-key="fk_avm_asp_node"/>
<property name="name" column="qname" type="QName" length="200"/>
</class>
<!-- When a snapshot is created we stow away all of the layered
nodes that were frozen by the snapshot so that subsequent
snapshots can find them and force copies. -->
<class name="VersionLayeredNodeEntryImpl" proxy="VersionLayeredNodeEntry"
table="avm_version_layered_node_entry">
<composite-id>
<key-many-to-one name="version" class="VersionRootImpl" column="version_root_id"/>
<key-property name="md5Sum" type="string" length="32" column="md5sum"/>
</composite-id>
<property name="path" type="string" length="512" column="path"/>
</class>
<!-- DEPRECATED END -->
<class name="IssuerIDImpl" proxy="IssuerID" table="avm_issuer_ids" optimistic-lock="version" lazy="false">
<id name="issuer" type="string" length="32" column="issuer"/>
<version name="version" column="version" type="long"/>

View File

@@ -28,6 +28,8 @@ import java.util.List;
import org.alfresco.repo.avm.AVMStore;
import org.alfresco.repo.avm.AVMStoreProperty;
import org.alfresco.repo.avm.AVMStorePropertyDAO;
import org.alfresco.repo.domain.QNameDAO;
import org.alfresco.repo.domain.QNameEntity;
import org.alfresco.service.namespace.QName;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
@@ -38,6 +40,16 @@ import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
*/
class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMStorePropertyDAO
{
private QNameDAO qnameDAO;
/**
* Set the DAO for accessing QName entities
*/
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
/**
* Persist a property.
* @param prop The AVMStoreProperty to persist.
@@ -55,11 +67,25 @@ class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMSto
*/
public AVMStoreProperty get(AVMStore store, QName name)
{
Query query =
getSession().createQuery("from AVMStorePropertyImpl asp where asp.store = :store and asp.name = :name");
query.setEntity("store", store);
query.setParameter("name", name);
return (AVMStoreProperty)query.uniqueResult();
QNameEntity qnameEntity = qnameDAO.getQNameEntity(name);
if (qnameEntity == null)
{
// No such QName
return null;
}
else
{
Query query =
getSession().createQuery(
"select asp " +
"from AVMStorePropertyImpl asp " +
"where " +
"asp.store = :store and " +
"asp.name = :name");
query.setEntity("store", store);
query.setParameter("name", qnameEntity);
return (AVMStoreProperty)query.uniqueResult();
}
}
/**
@@ -85,12 +111,30 @@ class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMSto
@SuppressWarnings("unchecked")
public List<AVMStoreProperty> queryByKeyPattern(AVMStore store, QName keyPattern)
{
// Get the URI and LocalName parts
String uri = keyPattern.getNamespaceURI();
if (uri == null || uri.length() == 0)
{
uri = "%";
}
String localName = keyPattern.getLocalName();
if (localName == null || localName.length() == 0)
{
localName = "%";
}
Query query =
getSession().createQuery(
"select asp " +
"from AVMStorePropertyImpl asp " +
"where asp.store = :store and asp.name like :name");
"join asp.name name " +
"join name.namespace namespace " +
"where " +
"asp.store = :store and " +
"namespace.uri like :uri and " +
"name.localName like :localName");
query.setEntity("store", store);
query.setParameter("name", keyPattern);
query.setParameter("uri", uri);
query.setParameter("localName", localName);
return (List<AVMStoreProperty>)query.list();
}
@@ -102,11 +146,28 @@ class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMSto
@SuppressWarnings("unchecked")
public List<AVMStoreProperty> queryByKeyPattern(QName keyPattern)
{
// Get the URI and LocalName parts
String uri = keyPattern.getNamespaceURI();
if (uri == null || uri.length() == 0)
{
uri = "%";
}
String localName = keyPattern.getLocalName();
if (localName == null || localName.length() == 0)
{
localName = "%";
}
Query query =
getSession().createQuery(
"from AVMStorePropertyImpl asp " +
"where asp.name like :name");
query.setParameter("name", keyPattern);
"select asp " +
"from AVMStorePropertyImpl asp " +
"join asp.name name " +
"join name.namespace namespace " +
"where " +
"namespace.uri like :uri and " +
"name.localName like :localName");
query.setParameter("uri", uri);
query.setParameter("localName", localName);
return (List<AVMStoreProperty>)query.list();
}
@@ -126,12 +187,16 @@ class AVMStorePropertyDAOHibernate extends HibernateDaoSupport implements AVMSto
*/
public void delete(AVMStore store, QName name)
{
Query delete =
getSession().createQuery("delete from AVMStorePropertyImpl asp " +
"where asp.store = :store and asp.name = :name");
delete.setEntity("store", store);
delete.setParameter("name", name);
delete.executeUpdate();
QNameEntity qnameEntity = qnameDAO.getQNameEntity(name);
if (qnameEntity != null)
{
Query delete =
getSession().createQuery("delete from AVMStorePropertyImpl asp " +
"where asp.store = :store and asp.name = :name");
delete.setEntity("store", store);
delete.setParameter("name", qnameEntity);
delete.executeUpdate();
}
}
/**

View File

@@ -54,9 +54,22 @@ public interface ChildAssoc extends Comparable<ChildAssoc>
* {@link #getChild() child} nodes to maintain the inverse association sets
*/
public void removeAssociation();
/**
* A convenience method to get a reference to this association.
*
* @return Returns a reference to this association
*/
public ChildAssociationRef getChildAssocRef();
/**
* A convenience method to aggregate the qualified name's namespace and localname
* into a single qualified name.
*
* @return Returns the qualified name of the association
*/
public QName getQname();
public Long getId();
/**
@@ -67,17 +80,16 @@ public interface ChildAssoc extends Comparable<ChildAssoc>
public Node getParent();
public Node getChild();
/**
* @return Returns the type of the association
*/
public QNameEntity getTypeQName();
/**
* @return Returns the qualified name of the association type
* @param typeQName the association's dictionary type
*/
public QName getTypeQName();
/**
* @param assocTypeQName the qualified name of the association type as defined
* in the data dictionary
*/
public void setTypeQName(QName assocTypeQName);
public void setTypeQName(QNameEntity typeQName);
/**
* @return Returns the child node name. This may be truncated, in which case it
@@ -102,15 +114,25 @@ public interface ChildAssoc extends Comparable<ChildAssoc>
public void setChildNodeNameCrc(long crc);
/**
* @return Returns the qualified name of this association
* @return Returns the namespace of the association's local QName
*/
public QName getQname();
public NamespaceEntity getQnameNamespace();
/**
* @param namespace the namespace of the association's local QName
*/
public void setQnameNamespace(NamespaceEntity namespace);
/**
* @return Returns the localname of the association's local QName
*/
public String getQnameLocalName();
/**
* @param qname the qualified name of the association
* @param localName the localname of the association's local QName
*/
public void setQname(QName qname);
public void setQnameLocalName(String localName);
public boolean getIsPrimary();
public void setIsPrimary(boolean isPrimary);

View File

@@ -0,0 +1,40 @@
/*
* 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;
/**
* Represents a persistable Namespace entity.
*
* @author Derek Hulley
* @since 2.2
*/
public interface NamespaceEntity
{
Long getId();
String getUri();
void setUri(String namespaceUrl);
}

View File

@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
/**
* Interface for persistent <b>node</b> objects.
@@ -64,13 +63,13 @@ public interface Node
public void setUuid(String uuid);
public QName getTypeQName();
public QNameEntity getTypeQName();
public void setTypeQName(QName typeQName);
public void setTypeQName(QNameEntity typeQName);
public Set<QName> getAspects();
public Set<Long> getAspects();
public Map<QName, PropertyValue> getProperties();
public Map<Long, PropertyValue> getProperties();
public DbAccessControlList getAccessControlList();

View File

@@ -25,7 +25,6 @@
package org.alfresco.repo.domain;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.namespace.QName;
/**
* Represents a generic association between two nodes. The association is named
@@ -62,12 +61,12 @@ public interface NodeAssoc
public Node getTarget();
/**
* @return Returns the qualified name of this association type
* @return Returns the type of the association
*/
public QName getTypeQName();
public QNameEntity getTypeQName();
/**
* @param qname the qualified name of the association type
* @param typeQName the association's dictionary type
*/
public void setTypeQName(QName qname);
public void setTypeQName(QNameEntity typeQName);
}

View File

@@ -74,6 +74,12 @@ public class PropertyValue implements Cloneable, Serializable
{
NULL
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(0);
}
@Override
Serializable convert(Serializable value)
{
@@ -82,6 +88,12 @@ public class PropertyValue implements Cloneable, Serializable
},
BOOLEAN
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(1);
}
@Override
Serializable convert(Serializable value)
{
@@ -90,6 +102,12 @@ public class PropertyValue implements Cloneable, Serializable
},
INTEGER
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(2);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -104,6 +122,12 @@ public class PropertyValue implements Cloneable, Serializable
},
LONG
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(3);
}
@Override
Serializable convert(Serializable value)
{
@@ -112,6 +136,12 @@ public class PropertyValue implements Cloneable, Serializable
},
FLOAT
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(4);
}
@Override
Serializable convert(Serializable value)
{
@@ -120,6 +150,12 @@ public class PropertyValue implements Cloneable, Serializable
},
DOUBLE
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(5);
}
@Override
Serializable convert(Serializable value)
{
@@ -128,6 +164,12 @@ public class PropertyValue implements Cloneable, Serializable
},
STRING
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(6);
}
/**
* Strings longer than the maximum of 1024 characters will be serialized.
*/
@@ -153,6 +195,12 @@ public class PropertyValue implements Cloneable, Serializable
},
DATE
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(7);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -167,6 +215,12 @@ public class PropertyValue implements Cloneable, Serializable
},
DB_ATTRIBUTE
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(8);
}
/** class that is able to convert from persisted attributes to normal attributes */
private AttributeConverter attributeConverter = new AttributeConverter();
@@ -179,6 +233,12 @@ public class PropertyValue implements Cloneable, Serializable
},
SERIALIZABLE
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(9);
}
@Override
Serializable convert(Serializable value)
{
@@ -187,6 +247,12 @@ public class PropertyValue implements Cloneable, Serializable
},
MLTEXT
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(10);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -201,6 +267,12 @@ public class PropertyValue implements Cloneable, Serializable
},
CONTENT
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(11);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -215,6 +287,12 @@ public class PropertyValue implements Cloneable, Serializable
},
NODEREF
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(12);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -229,6 +307,12 @@ public class PropertyValue implements Cloneable, Serializable
},
CHILD_ASSOC_REF
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(13);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -243,6 +327,12 @@ public class PropertyValue implements Cloneable, Serializable
},
ASSOC_REF
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(14);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -257,6 +347,12 @@ public class PropertyValue implements Cloneable, Serializable
},
QNAME
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(15);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -271,6 +367,12 @@ public class PropertyValue implements Cloneable, Serializable
},
PATH
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(16);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -285,6 +387,12 @@ public class PropertyValue implements Cloneable, Serializable
},
LOCALE
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(17);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -299,6 +407,12 @@ public class PropertyValue implements Cloneable, Serializable
},
VERSION_NUMBER
{
@Override
public Integer getOrdinalNumber()
{
return Integer.valueOf(18);
}
@Override
protected ValueType getPersistedType(Serializable value)
{
@@ -312,6 +426,11 @@ public class PropertyValue implements Cloneable, Serializable
}
};
/**
* @return Returns the manually-maintained ordinal number for the value
*/
public abstract Integer getOrdinalNumber();
/**
* Override if the type gets persisted in a different format.
*
@@ -440,9 +559,14 @@ public class PropertyValue implements Cloneable, Serializable
/** a mapping from a property type <code>QName</code> to the corresponding value type */
private static Map<QName, ValueType> valueTypesByPropertyType;
/**
* a mapping of {@link ValueType} ordinal number to the enum. This is manually maintained
* and <b>MUST NOT BE CHANGED FOR EXISTING VALUES</b>.
*/
private static Map<Integer, ValueType> valueTypesByOrdinalNumber;
static
{
valueTypesByPropertyType = new HashMap<QName, ValueType>(17);
valueTypesByPropertyType = new HashMap<QName, ValueType>(37);
valueTypesByPropertyType.put(DataTypeDefinition.ANY, ValueType.SERIALIZABLE);
valueTypesByPropertyType.put(DataTypeDefinition.BOOLEAN, ValueType.BOOLEAN);
valueTypesByPropertyType.put(DataTypeDefinition.INT, ValueType.INTEGER);
@@ -461,6 +585,21 @@ public class PropertyValue implements Cloneable, Serializable
valueTypesByPropertyType.put(DataTypeDefinition.PATH, ValueType.PATH);
valueTypesByPropertyType.put(DataTypeDefinition.QNAME, ValueType.QNAME);
valueTypesByPropertyType.put(DataTypeDefinition.LOCALE, ValueType.LOCALE);
valueTypesByOrdinalNumber = new HashMap<Integer, ValueType>(37);
for (ValueType valueType : ValueType.values())
{
Integer ordinalNumber = valueType.getOrdinalNumber();
if (valueTypesByOrdinalNumber.containsKey(ordinalNumber))
{
throw new RuntimeException("ValueType has duplicate ordinal number: " + valueType);
}
else if (ordinalNumber.intValue() == -1)
{
throw new RuntimeException("ValueType doesn't have an ordinal number: " + valueType);
}
valueTypesByOrdinalNumber.put(ordinalNumber, valueType);
}
}
/** the type of the property, prior to serialization persistence */
@@ -627,14 +766,19 @@ public class PropertyValue implements Cloneable, Serializable
return sb.toString();
}
public String getActualType()
public Integer getActualType()
{
return actualType.toString();
return actualType == null ? null : actualType.getOrdinalNumber();
}
public void setActualType(String actualType)
public void setActualType(Integer actualType)
{
this.actualType = ValueType.valueOf(actualType);
ValueType type = PropertyValue.valueTypesByOrdinalNumber.get(actualType);
if (type == null)
{
logger.error("Unknown property actual type ordinal number: " + actualType);
}
this.actualType = type;
}
public boolean isMultiValued()
@@ -647,13 +791,18 @@ public class PropertyValue implements Cloneable, Serializable
this.isMultiValued = isMultiValued;
}
public String getPersistedType()
public Integer getPersistedType()
{
return persistedType.toString();
return persistedType == null ? null : persistedType.getOrdinalNumber();
}
public void setPersistedType(String persistedType)
public void setPersistedType(Integer persistedType)
{
this.persistedType = ValueType.valueOf(persistedType);
ValueType type = PropertyValue.valueTypesByOrdinalNumber.get(persistedType);
if (type == null)
{
logger.error("Unknown property persisted type ordinal number: " + persistedType);
}
this.persistedType = type;
}
/**

View File

@@ -0,0 +1,109 @@
/*
* 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 java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.namespace.QName;
/**
* Data abstraction layer for QName and Namespace entities.
*
* @author Derek Hulley
* @since 2.1
*/
public interface QNameDAO
{
/**
* @param id the unique ID of the entity
* @return the namespace entity (never null)
* @throws AlfrescoRuntimeException if the ID provided is invalid
*/
NamespaceEntity getNamespaceEntity(Long id);
/**
* @param namespaceUri the namespace URI to query for
* @return the namespace entity of null if it doesn't exist
*/
NamespaceEntity getNamespaceEntity(String namespaceUri);
/**
* Get an existing instance matching the URI or create one if necessary.
* Note that this method should be treated as a write method and should not
* be used in the context of read-only or query methods.
*
* @param namespaceUri the namespace URI to create
* @return the existing namespace entity if found or a new one
*/
NamespaceEntity getOrCreateNamespaceEntity(String namespaceUri);
/**
* @param namespaceUri the namespace URI to create
* @return Returns the new instance
*/
NamespaceEntity newNamespaceEntity(String namespaceUri);
/**
* @param id the unique ID of the entity
* @return the QName entity (never null)
* @throws AlfrescoRuntimeException if the ID provided is invalid
*/
QNameEntity getQNameEntity(Long id);
/**
* @param id the unique ID of the entity
* @return the QName (never null)
* @throws AlfrescoRuntimeException if the ID provided is invalid
*/
QName getQName(Long id);
/**
* @param qname the QName to query for
* @return the QName entity of null if it doesn't exist
*/
QNameEntity getQNameEntity(QName qname);
/**
* Get an existing instance matching the QName or create one if necessary.
* Note that this method should be treated as a write method and should not
* be used in the context of read-only or query methods.
*
* @param qname the QName to query for
* @return an existing QName entity if found or a new one
*/
QNameEntity getOrCreateQNameEntity(QName qname);
/**
* @param qname the QName to create
* @return the new instance
*/
QNameEntity newQNameEntity(QName qname);
Set<QName> convertIdsToQNames(Set<Long> ids);
Map<QName, ? extends Object> convertIdMapToQNameMap(Map<Long, ? extends Object> idMap);
}

View File

@@ -0,0 +1,215 @@
/*
* 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 java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.GUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
/**
* @see QNameDAO
*
*
* @author Derek Hulley
* @since 2.2
*/
public class QNameDAOTest extends TestCase
{
private static Log logger = LogFactory.getLog(QNameDAOTest.class);
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private RetryingTransactionHelper retryingTransactionHelper;
private QNameDAO dao;
@Override
public void setUp() throws Exception
{
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
retryingTransactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
dao = (QNameDAO) ctx.getBean("qnameDAO");
}
@Override
public void tearDown() throws Exception
{
}
public void testNewNamespace() throws Exception
{
final String namespaceUri = GUID.generate();
RetryingTransactionCallback<NamespaceEntity> callback = new RetryingTransactionCallback<NamespaceEntity>()
{
public NamespaceEntity execute() throws Throwable
{
NamespaceEntity namespace = dao.getNamespaceEntity(namespaceUri);
assertNull("Namespace should not exist yet", namespace);
// Now make it
namespace = dao.newNamespaceEntity(namespaceUri);
assertNotNull("Namespace should now exist", dao.getNamespaceEntity(namespaceUri));
// Done
return namespace;
}
};
retryingTransactionHelper.doInTransaction(callback);
}
public void testNewQName() throws Exception
{
final String namespaceUri = GUID.generate();
final String localName = GUID.generate();
final QName qname = QName.createQName(namespaceUri, localName);
RetryingTransactionCallback<QNameEntity> callback = new RetryingTransactionCallback<QNameEntity>()
{
public QNameEntity execute() throws Throwable
{
QNameEntity qnameEntity = dao.getQNameEntity(qname);
assertNull("QName should not exist yet", qnameEntity);
// Now make it
qnameEntity = dao.newQNameEntity(qname);
assertNotNull("QName should now exist", dao.getQNameEntity(qname));
// Done
return qnameEntity;
}
};
retryingTransactionHelper.doInTransaction(callback);
}
/**
* Forces a bunch of threads to attempt QName creation at exactly the same time
* for their first attempt. The subsequent retries should all succeed by
* finding the QNameEntity.
*/
public void testConcurrentQName() throws Throwable
{
final Random random = new Random();
final String namespaceUri = GUID.generate();
int threadCount = 50;
final CountDownLatch readyLatch = new CountDownLatch(threadCount);
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch doneLatch = new CountDownLatch(threadCount);
final List<Throwable> errors = Collections.synchronizedList(new ArrayList<Throwable>(0));
final RetryingTransactionCallback<QNameEntity> callback = new RetryingTransactionCallback<QNameEntity>()
{
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);
}
}
}

View File

@@ -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();
}

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"

View File

@@ -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<NodeRef> createCallback = new RetryingTransactionCallback<NodeRef>()
{
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<Object> testCallback = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Throwable
{
QName ficticiousQName = QName.createQName(GUID.generate(), GUID.generate());
Serializable value = nodeService.getProperty(nodeRef, ficticiousQName);
assertNull("Didn't expect a value back", value);
return null;
}
};
retryingTransactionHelper.doInTransaction(testCallback, true, true);
}
/**
* Ensures that the type you get out of a <b>d:any</b> property is the type that you
* put in.

View File

@@ -44,6 +44,8 @@ import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeAssoc;
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.Store;
import org.alfresco.repo.node.AbstractNodeServiceImpl;
import org.alfresco.repo.node.StoreArchiveMap;
@@ -91,6 +93,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
private static Log logger = LogFactory.getLog(DbNodeServiceImpl.class);
private static Log loggerPaths = LogFactory.getLog(DbNodeServiceImpl.class.getName() + ".paths");
private QNameDAO qnameDAO;
private NodeDaoService nodeDaoService;
private StoreArchiveMap storeArchiveMap;
private NodeService avmNodeService;
@@ -101,6 +104,14 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
storeArchiveMap = new StoreArchiveMap(); // in case it is not set
}
/**
* Set the component for creating QName entities.
*/
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
public void setNodeDaoService(NodeDaoService nodeDaoService)
{
this.nodeDaoService = nodeDaoService;
@@ -426,14 +437,15 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
List<AspectDefinition> defaultAspectDefs = classDefinition.getDefaultAspects();
// add all the aspects to the node
Set<QName> nodeAspects = node.getAspects();
Set<Long> nodeAspects = node.getAspects();
for (AspectDefinition defaultAspectDef : defaultAspectDefs)
{
QName aspectTypeQName = defaultAspectDef.getName();
invokeBeforeAddAspect(nodeRef, aspectTypeQName);
nodeAspects.add(aspectTypeQName);
QName defaultAspectQName = defaultAspectDef.getName();
QNameEntity defaultAspectQNameEntity = qnameDAO.getOrCreateQNameEntity(defaultAspectDef.getName());
invokeBeforeAddAspect(nodeRef, defaultAspectQName);
nodeAspects.add(defaultAspectQNameEntity.getId());
addDefaultPropertyValues(defaultAspectDef, properties);
invokeOnAddAspect(nodeRef, aspectTypeQName);
invokeOnAddAspect(nodeRef, defaultAspectQName);
// Now add any default aspects for this aspect
addDefaultAspects(defaultAspectDef, node, properties);
@@ -465,8 +477,8 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
boolean movingStore = !nodeToMoveRef.getStoreRef().equals(newParentRef.getStoreRef());
// data needed for policy invocation
QName nodeToMoveTypeQName = nodeToMove.getTypeQName();
Set<QName> nodeToMoveAspects = nodeToMove.getAspects();
QName nodeToMoveTypeQName = nodeToMove.getTypeQName().getQName();
Set<Long> nodeToMoveAspects = nodeToMove.getAspects();
// Invoke policy behaviour
if (movingStore)
@@ -510,9 +522,15 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// invoke policy behaviour
if (movingStore)
{
Set<QName> nodeToMoveAspectQNames = new HashSet<QName>(17);
for (Long qnameEntityId : nodeToMoveAspects)
{
QName nodeToMoveAspectQName = qnameDAO.getQNameEntity(qnameEntityId).getQName();
nodeToMoveAspectQNames.add(nodeToMoveAspectQName);
}
// TODO for now indicate that the node has been archived to prevent the version history from being removed
// in the future a onMove policy could be added and remove the need for onDelete and onCreate to be fired here
invokeOnDeleteNode(oldAssocRef, nodeToMoveTypeQName, nodeToMoveAspects, true);
invokeOnDeleteNode(oldAssocRef, nodeToMoveTypeQName, nodeToMoveAspectQNames, true);
invokeOnCreateNode(newAssoc.getChildAssocRef());
}
else
@@ -556,7 +574,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public QName getType(NodeRef nodeRef) throws InvalidNodeRefException
{
Node node = getNodeNotNull(nodeRef);
return node.getTypeQName();
return node.getTypeQName().getQName();
}
/**
@@ -575,8 +593,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Invoke policies
invokeBeforeUpdateNode(nodeRef);
// Ensure that we have a QName entity to represent the type
QNameEntity typeQNameEntity = qnameDAO.getOrCreateQNameEntity(typeQName);
// Get the node and set the new type
node.setTypeQName(typeQName);
node.setTypeQName(typeQNameEntity);
// Add the default aspects to the node (update the properties with any new default values)
Map<QName, Serializable> properties = this.getPropertiesImpl(node);
@@ -626,8 +646,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Set the property values back on the node
setProperties(nodeRef, nodeProperties);
// Get the persistale QNameEntity for the aspect
QNameEntity aspectTypeQNameEntity = qnameDAO.getOrCreateQNameEntity(aspectTypeQName);
// physically attach the aspect to the node
if (node.getAspects().add(aspectTypeQName) == true)
if (node.getAspects().add(aspectTypeQNameEntity.getId()) == true)
{
// Invoke policy behaviours
invokeOnUpdateNode(nodeRef);
@@ -652,9 +674,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
// get the node
Node node = getNodeNotNull(nodeRef);
Set<QName> nodeAspects = node.getAspects();
Set<Long> nodeAspects = node.getAspects();
if (!nodeAspects.contains(aspectTypeQName))
// Get the persistale QNameEntity for the aspect
QNameEntity aspectTypeQNameEntity = qnameDAO.getOrCreateQNameEntity(aspectTypeQName);
if (!nodeAspects.contains(aspectTypeQNameEntity.getId()))
{
// The aspect isn't present so just leave it
return;
@@ -665,13 +689,14 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
invokeBeforeRemoveAspect(nodeRef, aspectTypeQName);
// remove the aspect, if present
node.getAspects().remove(aspectTypeQName);
nodeAspects.remove(aspectTypeQNameEntity.getId());
Map<QName, PropertyValue> nodeProperties = node.getProperties();
Map<Long, PropertyValue> nodeProperties = node.getProperties();
Map<QName,PropertyDefinition> propertyDefs = aspectDef.getProperties();
for (QName propertyName : propertyDefs.keySet())
for (QName propertyQName : propertyDefs.keySet())
{
nodeProperties.remove(propertyName);
QNameEntity propertyQNameEntity = qnameDAO.getOrCreateQNameEntity(propertyQName);
nodeProperties.remove(propertyQNameEntity.getId());
}
// Remove child associations
@@ -680,7 +705,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
for (ChildAssoc childAssoc : childAssocs)
{
// Ignore if the association type is not defined by the aspect
QName childAssocQName = childAssoc.getTypeQName();
QName childAssocQName = childAssoc.getTypeQName().getQName();
if (!childAssocDefs.containsKey(childAssocQName))
{
continue;
@@ -695,7 +720,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
for (NodeAssoc nodeAssoc : nodeAssocs)
{
// Ignore if the association type is not defined by the aspect
QName nodeAssocQName = nodeAssoc.getTypeQName();
QName nodeAssocQName = nodeAssoc.getTypeQName().getQName();
if (!assocDefs.containsKey(nodeAssocQName))
{
continue;
@@ -717,11 +742,17 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
*
* @see Node#getAspects()
*/
public boolean hasAspect(NodeRef nodeRef, QName aspectRef) throws InvalidNodeRefException, InvalidAspectException
public boolean hasAspect(NodeRef nodeRef, QName aspectQName) throws InvalidNodeRefException, InvalidAspectException
{
QNameEntity aspectQNameEntity = qnameDAO.getQNameEntity(aspectQName);
if (aspectQNameEntity == null)
{
// There is no persisted, fixed QName like this
return false;
}
Node node = getNodeNotNull(nodeRef);
Set<QName> aspectQNames = node.getAspects();
boolean hasAspect = aspectQNames.contains(aspectRef);
Set<Long> aspectQNames = node.getAspects();
boolean hasAspect = aspectQNames.contains(aspectQNameEntity.getId());
// done
return hasAspect;
}
@@ -729,10 +760,14 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public Set<QName> getAspects(NodeRef nodeRef) throws InvalidNodeRefException
{
Node node = getNodeNotNull(nodeRef);
Set<QName> aspectQNames = node.getAspects();
Set<Long> aspectQNameEntities = node.getAspects();
// copy the set to ensure initialization
Set<QName> ret = new HashSet<QName>(aspectQNames.size());
ret.addAll(aspectQNames);
Set<QName> ret = new HashSet<QName>(aspectQNameEntities.size());
for (Long aspectQNameEntityId : aspectQNameEntities)
{
QNameEntity aspectQNameEntity = qnameDAO.getQNameEntity(aspectQNameEntityId);
ret.add(aspectQNameEntity.getQName());
}
// done
return ret;
}
@@ -751,13 +786,17 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
ChildAssociationRef childAssocRef = getPrimaryParent(nodeRef);
// get type and aspect QNames as they will be unavailable after the delete
QName nodeTypeQName = node.getTypeQName();
Set<QName> nodeAspectQNames = node.getAspects();
QName nodeTypeQName = node.getTypeQName().getQName();
Set<Long> nodeAspectQNameEntityIds = node.getAspects();
// Get QNameEntity for subsequent checks
QNameEntity aspectTempQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_TEMPORARY);
QNameEntity aspectWorkingCopyQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_WORKING_COPY);
// check if we need to archive the node
StoreRef archiveStoreRef = null;
if (nodeAspectQNames.contains(ContentModel.ASPECT_TEMPORARY) ||
nodeAspectQNames.contains(ContentModel.ASPECT_WORKING_COPY))
if (nodeAspectQNameEntityIds.contains(aspectTempQNameEntity.getId()) ||
nodeAspectQNameEntityIds.contains(aspectWorkingCopyQNameEntity.getId()))
{
// The node is either temporary or a working copy.
// It can not be archived.
@@ -770,7 +809,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// remove tenant domain - to retrieve archive store from map
archiveStoreRef = storeArchiveMap.getArchiveMap().get(storeRef);
// get the type and check if we need archiving
TypeDefinition typeDef = dictionaryService.getType(node.getTypeQName());
TypeDefinition typeDef = dictionaryService.getType(nodeTypeQName);
if (typeDef == null || !typeDef.isArchive() || archiveStoreRef == null)
{
requiresDelete = true;
@@ -782,7 +821,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// perform a normal deletion
nodeDaoService.deleteNode(node, true);
// Invoke policy behaviours
invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeAspectQNames, false);
Set<QName> nodeToDeleteAspectQNames = new HashSet<QName>(17);
for (Long qnameEntityId : nodeAspectQNameEntityIds)
{
QName nodeToDeleteAspectQName = qnameDAO.getQNameEntity(qnameEntityId).getQName();
nodeToDeleteAspectQNames.add(nodeToDeleteAspectQName);
}
invokeOnDeleteNode(childAssocRef, nodeTypeQName, nodeToDeleteAspectQNames, false);
}
else
{
@@ -971,14 +1016,14 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
private Map<QName, Serializable> getPropertiesImpl(Node node) throws InvalidNodeRefException
{
Map<QName,PropertyDefinition> propDefs = dictionaryService.getPropertyDefs(node.getTypeQName());
Map<QName, PropertyValue> nodeProperties = node.getProperties();
Map<QName,PropertyDefinition> propDefs = dictionaryService.getPropertyDefs(node.getTypeQName().getQName());
Map<Long, PropertyValue> nodeProperties = node.getProperties();
Map<QName, Serializable> ret = new HashMap<QName, Serializable>(nodeProperties.size());
// copy values
for (Map.Entry<QName, PropertyValue> entry: nodeProperties.entrySet())
for (Map.Entry<Long, PropertyValue> entry: nodeProperties.entrySet())
{
QName propertyQName = entry.getKey();
Long propertyQNameId = entry.getKey();
QName propertyQName = qnameDAO.getQNameEntity(propertyQNameId).getQName();
PropertyValue propertyValue = entry.getValue();
// get the property definition
PropertyDefinition propertyDef = propDefs.get(propertyQName);
@@ -1024,28 +1069,37 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return node.getId();
}
Map<QName, PropertyValue> properties = node.getProperties();
PropertyValue propertyValue = properties.get(qname);
// check if we need to provide a spoofed name
if (propertyValue == null && qname.equals(ContentModel.PROP_NAME))
// Get the QName entity
QNameEntity qnameEntity = qnameDAO.getQNameEntity(qname);
if (qnameEntity == null)
{
return nodeRef.getId();
// There is no persisted, fixed QName like this
return null;
}
// get the property definition
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.NODE_REF)) &&
(propertyValue != null) && (propertyValue.getStringValue() != null))
else
{
propertyValue.setStringValue(tenantService.getBaseName(new NodeRef(propertyValue.getStringValue())).toString());
Map<Long, PropertyValue> properties = node.getProperties();
PropertyValue propertyValue = properties.get(qnameEntity.getId());
// check if we need to provide a spoofed name
if (propertyValue == null && qname.equals(ContentModel.PROP_NAME))
{
return nodeRef.getId();
}
// Convert any NodeRefs using multi-tenant translation
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
if ((propertyDef != null) && (propertyDef.getDataType().getName().equals(DataTypeDefinition.NODE_REF)) &&
(propertyValue != null) && (propertyValue.getStringValue() != null))
{
propertyValue.setStringValue(tenantService.getBaseName(new NodeRef(propertyValue.getStringValue())).toString());
}
// convert to the correct type
Serializable value = makeSerializableValue(propertyDef, propertyValue);
// done
return value;
}
// convert to the correct type
Serializable value = makeSerializableValue(propertyDef, propertyValue);
// done
return value;
}
/**
@@ -1095,17 +1149,19 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
extractIntrinsicProperties(node, properties);
// copy properties onto node
Map<QName, PropertyValue> nodeProperties = node.getProperties();
Map<Long, PropertyValue> nodeProperties = node.getProperties();
nodeProperties.clear();
// check the property type and copy the values across
for (QName propertyQName : properties.keySet())
{
QNameEntity propertyQNameEntity = qnameDAO.getOrCreateQNameEntity(propertyQName);
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
// Get the value to persist
Serializable value = properties.get(propertyQName);
// get a persistable value
PropertyValue propertyValue = makePropertyValue(propertyDef, value);
nodeProperties.put(propertyQName, propertyValue);
nodeProperties.put(propertyQNameEntity.getId(), propertyValue);
}
// update the node status
@@ -1160,11 +1216,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{
NodeRef nodeRef = node.getNodeRef();
Map<QName, PropertyValue> properties = node.getProperties();
Map<Long, PropertyValue> properties = node.getProperties();
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
// Get the persistable key
QNameEntity qnameEntity = qnameDAO.getOrCreateQNameEntity(qname);
// get a persistable value
PropertyValue propertyValue = makePropertyValue(propertyDef, value);
properties.put(qname, propertyValue);
properties.put(qnameEntity.getId(), propertyValue);
// update the node status
nodeDaoService.recordChangeId(nodeRef);
@@ -1185,11 +1243,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// Invoke policy behaviours
invokeBeforeUpdateNode(nodeRef);
// Get the persistable QNameEntity
QNameEntity qnameEntity = qnameDAO.getOrCreateQNameEntity(qname);
// Get the values before
Map<QName, Serializable> propertiesBefore = getPropertiesImpl(node);
// Remove the property
Map<QName, PropertyValue> properties = node.getProperties();
properties.remove(qname);
Map<Long, PropertyValue> properties = node.getProperties();
properties.remove(qnameEntity.getId());
// Get the values afterwards
Map<QName, Serializable> propertiesAfter = getPropertiesImpl(node);
@@ -1234,8 +1294,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
List<ChildAssociationRef> results = new ArrayList<ChildAssociationRef>(parentAssocs.size());
for (ChildAssoc assoc : parentAssocs)
{
QName assocTypeQName = assoc.getTypeQName().getQName();
QName assocQName = assoc.getQname();
// does the qname match the pattern?
if (!qnamePattern.isMatch(assoc.getQname()) || !typeQNamePattern.isMatch(assoc.getTypeQName()))
if (!qnamePattern.isMatch(assocQName) || !typeQNamePattern.isMatch(assocTypeQName))
{
// no match - ignore
continue;
@@ -1391,8 +1453,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
List<AssociationRef> nodeAssocRefs = new ArrayList<AssociationRef>(assocs.size());
for (NodeAssoc assoc : assocs)
{
QName assocTypeQName = assoc.getTypeQName().getQName();
// check qname pattern
if (!qnamePattern.isMatch(assoc.getTypeQName()))
if (!qnamePattern.isMatch(assocTypeQName))
{
continue; // the assoc name doesn't match the pattern given
}
@@ -1410,8 +1473,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
List<AssociationRef> nodeAssocRefs = new ArrayList<AssociationRef>(assocs.size());
for (NodeAssoc assoc : assocs)
{
QName assocTypeQName = assoc.getTypeQName().getQName();
// check qname pattern
if (!qnamePattern.isMatch(assoc.getTypeQName()))
if (!qnamePattern.isMatch(assocTypeQName))
{
continue; // the assoc name doesn't match the pattern given
}
@@ -1452,7 +1516,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
boolean hasParents = parentAssocs.size() > 0;
// does the current node have a root aspect?
boolean isRoot = hasAspect(currentNodeRef, ContentModel.ASPECT_ROOT);
boolean isStoreRoot = currentNode.getTypeQName().equals(ContentModel.TYPE_STOREROOT);
boolean isStoreRoot = currentNode.getTypeQName().getQName().equals(ContentModel.TYPE_STOREROOT);
// look for a root. If we only want the primary root, then ignore all but the top-level root.
if (isRoot && !(primaryOnly && hasParents)) // exclude primary search with parents present
@@ -1482,8 +1546,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
if (first != null)
{
// mimic an association that would appear if the current node was below
// the root node
// mimic an association that would appear if the current node was below the root node
// or if first beneath the root node it will make the real thing
ChildAssociationRef updateAssocRef = new ChildAssociationRef(
isStoreRoot ? ContentModel.ASSOC_CHILDREN : first.getRef().getTypeQName(),
@@ -1531,7 +1594,13 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
NodeRef childRef = tenantService.getBaseName(assoc.getChild().getNodeRef());
boolean isPrimary = assoc.getIsPrimary();
// build a real association reference
ChildAssociationRef assocRef = new ChildAssociationRef(assoc.getTypeQName(), parentRef, qname, childRef, isPrimary, -1);
ChildAssociationRef assocRef = new ChildAssociationRef(
assoc.getTypeQName().getQName(),
parentRef,
qname,
childRef,
isPrimary,
-1);
// Ordering is not important here: We are building distinct paths upwards
Path.Element element = new Path.ChildAssocElement(assocRef);
// create a new path that builds on the current path
@@ -1612,41 +1681,51 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
private void archiveNode(NodeRef nodeRef, StoreRef archiveStoreRef)
{
QNameEntity aspectQNameEntityArchived = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_ARCHIVED);
QNameEntity propQNameEntityOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_OWNER);
QNameEntity propQNameEntityCreator = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_CREATOR);
QNameEntity propQNameArchivedBy = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_BY);
QNameEntity propQNameArchivedDate = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_DATE);
QNameEntity propQNameArchivedOriginalParentAssoc = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
NodeStatus nodeStatus = nodeDaoService.getNodeStatus(nodeRef, false);
Node node = nodeStatus.getNode();
ChildAssoc primaryParentAssoc = nodeDaoService.getPrimaryParentAssoc(node);
// add the aspect
Set<QName> aspects = node.getAspects();
aspects.add(ContentModel.ASPECT_ARCHIVED);
Map<QName, PropertyValue> properties = node.getProperties();
Set<Long> aspects = node.getAspects();
aspects.add(aspectQNameEntityArchived.getId());
Map<Long, PropertyValue> properties = node.getProperties();
PropertyValue archivedByProperty = makePropertyValue(
dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_BY),
AuthenticationUtil.getCurrentUserName());
properties.put(ContentModel.PROP_ARCHIVED_BY, archivedByProperty);
properties.put(propQNameArchivedBy.getId(), archivedByProperty);
PropertyValue archivedDateProperty = makePropertyValue(
dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_DATE),
new Date());
properties.put(ContentModel.PROP_ARCHIVED_DATE, archivedDateProperty);
properties.put(propQNameArchivedDate.getId(), archivedDateProperty);
PropertyValue archivedPrimaryParentNodeRefProperty = makePropertyValue(
dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC),
primaryParentAssoc.getChildAssocRef());
properties.put(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC, archivedPrimaryParentNodeRefProperty);
PropertyValue originalOwnerProperty = properties.get(ContentModel.PROP_OWNER);
PropertyValue originalCreatorProperty = properties.get(ContentModel.PROP_CREATOR);
properties.put(propQNameArchivedOriginalParentAssoc.getId(), archivedPrimaryParentNodeRefProperty);
PropertyValue originalOwnerProperty = properties.get(propQNameEntityOwner.getId());
PropertyValue originalCreatorProperty = properties.get(propQNameEntityCreator.getId());
if (originalOwnerProperty != null || originalCreatorProperty != null)
{
QNameEntity propQNameArchivedOriginalOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
properties.put(
ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER,
propQNameArchivedOriginalOwner.getId(),
originalOwnerProperty != null ? originalOwnerProperty : originalCreatorProperty);
}
// change the node ownership
aspects.add(ContentModel.ASPECT_OWNABLE);
QNameEntity ownableAspectQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_OWNABLE);
aspects.add(ownableAspectQNameEntity.getId());
PropertyValue newOwnerProperty = makePropertyValue(
dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER),
AuthenticationUtil.getCurrentUserName());
properties.put(ContentModel.PROP_OWNER, newOwnerProperty);
QNameEntity propQNameOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_OWNER);
properties.put(propQNameOwner.getId(), newOwnerProperty);
// move the node
NodeRef archiveStoreRootNodeRef = getRootNode(archiveStoreRef);
@@ -1853,33 +1932,38 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
}
// add archived aspect
node.getAspects().add(ContentModel.ASPECT_ARCHIVED_ASSOCS);
QNameEntity archivedAssocsAspectQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_ARCHIVED_ASSOCS);
node.getAspects().add(archivedAssocsAspectQNameEntity.getId());
// set properties
Map<QName, PropertyValue> properties = node.getProperties();
Map<Long, PropertyValue> properties = node.getProperties();
if (archivedParentAssocRefs.size() > 0)
{
QNameEntity propQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_PARENT_ASSOCS);
PropertyDefinition propertyDef = dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_PARENT_ASSOCS);
PropertyValue propertyValue = makePropertyValue(propertyDef, archivedParentAssocRefs);
properties.put(ContentModel.PROP_ARCHIVED_PARENT_ASSOCS, propertyValue);
properties.put(propQNameEntity.getId(), propertyValue);
}
if (archivedChildAssocRefs.size() > 0)
{
QNameEntity propQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_CHILD_ASSOCS);
PropertyDefinition propertyDef = dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_CHILD_ASSOCS);
PropertyValue propertyValue = makePropertyValue(propertyDef, archivedChildAssocRefs);
properties.put(ContentModel.PROP_ARCHIVED_CHILD_ASSOCS, propertyValue);
properties.put(propQNameEntity.getId(), propertyValue);
}
if (archivedSourceAssocRefs.size() > 0)
{
QNameEntity propQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
PropertyDefinition propertyDef = dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS);
PropertyValue propertyValue = makePropertyValue(propertyDef, archivedSourceAssocRefs);
properties.put(ContentModel.PROP_ARCHIVED_SOURCE_ASSOCS, propertyValue);
properties.put(propQNameEntity.getId(), propertyValue);
}
if (archivedTargetAssocRefs.size() > 0)
{
QNameEntity propQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);
PropertyDefinition propertyDef = dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS);
PropertyValue propertyValue = makePropertyValue(propertyDef, archivedTargetAssocRefs);
properties.put(ContentModel.PROP_ARCHIVED_TARGET_ASSOCS, propertyValue);
properties.put(propQNameEntity.getId(), propertyValue);
}
}
@@ -1899,33 +1983,41 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public NodeRef restoreNode(NodeRef archivedNodeRef, NodeRef destinationParentNodeRef, QName assocTypeQName, QName assocQName)
{
QNameEntity aspectQNameEntityArchived = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_ARCHIVED);
QNameEntity propQNameEntityOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_OWNER);
QNameEntity propQNameEntityOrigParentAssoc = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
QNameEntity propQNameEntityArchivedBy = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_BY);
QNameEntity propQNameEntityArchivedDate = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_DATE);
QNameEntity propQNameEntityOrigOwner = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
NodeStatus archivedNodeStatus = getNodeStatusNotNull(archivedNodeRef);
Node archivedNode = archivedNodeStatus.getNode();
Set<QName> aspects = archivedNode.getAspects();
Map<QName, PropertyValue> properties = archivedNode.getProperties();
Set<Long> aspects = archivedNode.getAspects();
Map<Long, PropertyValue> properties = archivedNode.getProperties();
// the node must be a top-level archive node
if (!aspects.contains(ContentModel.ASPECT_ARCHIVED))
if (!aspects.contains(aspectQNameEntityArchived.getId()))
{
throw new AlfrescoRuntimeException("The node to archive is not an archive node");
}
ChildAssociationRef originalPrimaryParentAssocRef = (ChildAssociationRef) makeSerializableValue(
dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC),
properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC));
PropertyValue originalOwnerProperty = properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
properties.get(propQNameEntityOrigParentAssoc.getId()));
PropertyValue originalOwnerProperty = properties.get(propQNameEntityOrigOwner.getId());
// remove the archived aspect
removeAspect(archivedNodeRef, ContentModel.ASPECT_ARCHIVED); // allow policy to fire, e.g. for DictionaryModelType
properties.remove(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
properties.remove(ContentModel.PROP_ARCHIVED_BY);
properties.remove(ContentModel.PROP_ARCHIVED_DATE);
properties.remove(ContentModel.PROP_ARCHIVED_ORIGINAL_OWNER);
properties.remove(propQNameEntityOrigParentAssoc.getId());
properties.remove(propQNameEntityArchivedBy.getId());
properties.remove(propQNameEntityArchivedDate.getId());
properties.remove(propQNameEntityOrigOwner.getId());
// restore the original ownership
if (originalOwnerProperty != null)
{
aspects.add(ContentModel.ASPECT_OWNABLE);
properties.put(ContentModel.PROP_OWNER, originalOwnerProperty);
QNameEntity ownableAspectQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.ASPECT_OWNABLE);
aspects.add(ownableAspectQNameEntity.getId());
properties.put(propQNameEntityOwner.getId(), originalOwnerProperty);
}
if (destinationParentNodeRef == null)
@@ -1958,7 +2050,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
for (NodeStatus restoreNodeStatus : restoreNodeStatusesById.values())
{
Node restoreNode = restoreNodeStatus.getNode();
restoreAssocs(restoreNode);
restoreAssocs(restoreNode, propQNameEntityOrigParentAssoc);
}
// the node reference has changed due to the store move
@@ -1975,11 +2067,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
return restoredNodeRef;
}
private void restoreAssocs(Node node)
private void restoreAssocs(Node node, QNameEntity propQNameEntityOrigParentAssoc)
{
NodeRef nodeRef = node.getNodeRef();
// set properties
Map<QName, PropertyValue> properties = node.getProperties();
Map<Long, PropertyValue> properties = node.getProperties();
// restore parent associations
Collection<ChildAssociationRef> parentAssocRefs = (Collection<ChildAssociationRef>) getProperty(
@@ -2004,7 +2096,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
assocTypeQName,
assocRef.getQName());
}
properties.remove(ContentModel.PROP_ARCHIVED_PARENT_ASSOCS);
properties.remove(propQNameEntityOrigParentAssoc.getId());
}
// make sure that the node name uniqueness is enforced
@@ -2087,8 +2179,9 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
private void setChildUniqueName(Node childNode)
{
// get the name property
Map<QName, PropertyValue> properties = childNode.getProperties();
PropertyValue nameValue = properties.get(ContentModel.PROP_NAME);
Map<Long, PropertyValue> properties = childNode.getProperties();
QNameEntity nameQNameEntity = qnameDAO.getOrCreateQNameEntity(ContentModel.PROP_NAME);
PropertyValue nameValue = properties.get(nameQNameEntity.getId());
String useName = null;
if (nameValue == null)
{
@@ -2103,7 +2196,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
Collection<ChildAssoc> parentAssocs = nodeDaoService.getParentAssocs(childNode);
for (ChildAssoc assoc : parentAssocs)
{
QName assocTypeQName = assoc.getTypeQName();
QName assocTypeQName = assoc.getTypeQName().getQName();
AssociationDefinition assocDef = dictionaryService.getAssociation(assocTypeQName);
if (!assocDef.isChild())
{

View File

@@ -29,6 +29,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -39,11 +40,14 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.domain.ChildAssoc;
import org.alfresco.repo.domain.NamespaceEntity;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeAssoc;
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;
@@ -120,6 +124,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
/** Log to trace parent association caching: <b>classname + .ParentAssocsCache</b> */
private static Log loggerParentAssocsCache = LogFactory.getLog(HibernateNodeDaoServiceImpl.class.getName() + ".ParentAssocsCache");
private QNameDAO qnameDAO;
/** A cache for more performant lookups of the parent associations */
private SimpleCache<Long, Set<Long>> parentAssocsCache;
private boolean isDebugEnabled = logger.isDebugEnabled();
@@ -192,6 +197,14 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
return uuid.hashCode();
}
/**
* Set the component for creating QName entities.
*/
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
/**
* Set the transaction-aware cache to store parent associations by child node id
*
@@ -536,12 +549,15 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
}
}
// Get the node's qname
QNameEntity nodeTypeQNameEntity = qnameDAO.getOrCreateQNameEntity(nodeTypeQName);
// build a concrete node based on a bootstrap type
Node node = new NodeImpl();
// set other required properties
node.setStore(store);
node.setUuid(uuid);
node.setTypeQName(nodeTypeQName);
node.setTypeQName(nodeTypeQNameEntity);
// persist the node
getHibernateTemplate().save(node);
@@ -684,12 +700,18 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
// assign a random name to the node
String randomName = GUID.generate();
// Get the association type's qname
QNameEntity assocTypeQNameEntity = qnameDAO.getOrCreateQNameEntity(assocTypeQName);
// Get the qname components
NamespaceEntity assocNamespaceEntity = qnameDAO.getOrCreateNamespaceEntity(qname.getNamespaceURI());
ChildAssoc assoc = new ChildAssocImpl();
assoc.setTypeQName(assocTypeQName);
assoc.setTypeQName(assocTypeQNameEntity);
assoc.setChildNodeName(randomName);
assoc.setChildNodeNameCrc(-1L); // random names compete only with each other
assoc.setQname(qname);
assoc.setQnameNamespace(assocNamespaceEntity);
assoc.setQnameLocalName(qname.getLocalName());
assoc.setIsPrimary(isPrimary);
// maintain inverse sets
assoc.buildAssociation(parentNode, childNode);
@@ -785,7 +807,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOC_ID_BY_NAME)
.setLong("parentId", parentNode.getId())
.setParameter("parent", parentNode)
.setParameter("childNodeName", childNameNewShort)
.setLong("childNodeNameCrc", childNameNewCrc);
return query.uniqueResult();
@@ -804,7 +826,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
}
throw new DuplicateChildNodeNameException(
parentNode.getNodeRef(),
childAssoc.getTypeQName(),
childAssoc.getTypeQName().getQName(),
childName);
}
// We got past that, so we can just update the entity and know that no other transaction
@@ -831,7 +853,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_PRIMARY_CHILD_NODE_STATUSES)
.setLong("parentId", parentNode.getId());
.setParameter("parent", parentNode);
return query.list();
}
};
@@ -848,7 +870,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOCS)
.setLong("parentId", parentNode.getId());
.setParameter("parent", parentNode);
return query.list();
}
};
@@ -865,7 +887,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOC_REFS)
.setLong("parentId", parentNode.getId());
.setParameter("parent", parentNode);
return query.list();
}
};
@@ -882,10 +904,18 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
public Object doInHibernate(Session session)
{
NamespaceEntity qnameNamespaceEntity = qnameDAO.getNamespaceEntity(assocQName.getNamespaceURI());
String qnameLocalName = assocQName.getLocalName();
if (qnameNamespaceEntity == null)
{
// There can be no match;
return Collections.emptyList();
}
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOC_REFS_BY_QNAME)
.setLong("parentId", parentNode.getId())
.setParameter("childAssocQName", assocQName);
.setParameter("parent", parentNode)
.setParameter("qnameNamespace", qnameNamespaceEntity)
.setParameter("qnameLocalName", qnameLocalName);
return query.list();
}
};
@@ -906,18 +936,19 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
NodeRef parentNodeRef = tenantService.getBaseName(parentNode.getNodeRef());
for (Object[] row : queryResults)
{
String childProtocol = (String) row[5];
String childIdentifier = (String) row[6];
String childUuid = (String) row[7];
String childProtocol = (String) row[6];
String childIdentifier = (String) row[7];
String childUuid = (String) row[8];
NodeRef childNodeRef = tenantService.getBaseName(new NodeRef(new StoreRef(childProtocol, childIdentifier), childUuid));
QName assocTypeQName = (QName) row[0];
QName assocQName = (QName) row[1];
Boolean assocIsPrimary = (Boolean) row[2];
Integer assocIndex = (Integer) row[3];
QNameEntity assocTypeQNameEntity = (QNameEntity) row[0];
NamespaceEntity assocQNameNamespace = (NamespaceEntity) row[1];
String assocQNameLocalName = (String) row[2];
Boolean assocIsPrimary = (Boolean) row[3];
Integer assocIndex = (Integer) row[4];
ChildAssociationRef assocRef = new ChildAssociationRef(
assocTypeQName,
assocTypeQNameEntity.getQName(),
parentNodeRef,
assocQName,
QName.createQName(assocQNameNamespace.getUri(), assocQNameLocalName),
childNodeRef,
assocIsPrimary.booleanValue(),
assocIndex.intValue());
@@ -936,12 +967,21 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
public Object doInHibernate(Session session)
{
QNameEntity typeQNameEntity = qnameDAO.getQNameEntity(assocTypeQName);
NamespaceEntity qnameNamespaceEntity = qnameDAO.getNamespaceEntity(qname.getNamespaceURI());
String qnameLocalName = qname.getLocalName();
if (typeQNameEntity == null || qnameNamespaceEntity == null)
{
// There can be no match;
return null;
}
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOCS_BY_ALL)
.setLong("parentId", parentNode.getId())
.setLong("childId", childNode.getId())
.setParameter("typeQName", assocTypeQName)
.setParameter("qname", qname);
.setParameter("parent", parentNode)
.setParameter("child", childNode)
.setParameter("typeQName", typeQNameEntity)
.setParameter("qnameNamespace", qnameNamespaceEntity)
.setParameter("qnameLocalName", qnameLocalName);
return query.uniqueResult();
}
};
@@ -960,12 +1000,21 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
public Object doInHibernate(Session session)
{
QNameEntity typeQNameEntity = qnameDAO.getQNameEntity(assocTypeQName);
NamespaceEntity qnameNamespaceEntity = qnameDAO.getNamespaceEntity(qname.getNamespaceURI());
String qnameLocalName = qname.getLocalName();
if (typeQNameEntity == null || qnameNamespaceEntity == null)
{
// There can be no match;
return Collections.emptyList();
}
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOCS_BY_ALL)
.setLong("parentId", parentNode.getId())
.setLong("childId", childNode.getId())
.setParameter("typeQName", assocTypeQName)
.setParameter("qname", qname);
.setParameter("parent", parentNode)
.setParameter("child", childNode)
.setParameter("typeQName", typeQNameEntity)
.setParameter("qnameNamespace", qnameNamespaceEntity)
.setParameter("qnameLocalName", qnameLocalName);
return query.list();
}
};
@@ -984,13 +1033,19 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
public Object doInHibernate(Session session)
{
QNameEntity typeQNameEntity = qnameDAO.getQNameEntity(assocTypeQName);
if (typeQNameEntity == null)
{
// There can be no match;
return null;
}
String childNameLower = childName.toLowerCase();
String childNameShort = getShortName(childNameLower);
long childNameLowerCrc = getCrc(childNameLower);
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_CHILD_ASSOC_BY_TYPE_AND_NAME)
.setLong("parentId", parentNode.getId())
.setParameter("typeQName", assocTypeQName)
.setParameter("parent", parentNode)
.setParameter("typeQName", typeQNameEntity)
.setParameter("childNodeName", childNameShort)
.setLong("childNodeNameCrc", childNameLowerCrc);
return query.uniqueResult();
@@ -1078,7 +1133,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
* @return Returns the parent associations without any interpretation
*/
@SuppressWarnings("unchecked")
private Collection<ChildAssoc> getParentAssocsInternal(Node childNode)
private Collection<ChildAssoc> getParentAssocsInternal(final Node childNode)
{
final Long childNodeId = childNode.getId();
List<ChildAssoc> parentAssocs = null;
@@ -1125,7 +1180,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_PARENT_ASSOCS)
.setLong("childId", childNodeId);
.setParameter("child", childNode);
return query.list();
}
};
@@ -1240,8 +1295,11 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
public NodeAssoc newNodeAssoc(Node sourceNode, Node targetNode, QName assocTypeQName)
{
// Get the assoc type QNameEntity
QNameEntity assocTypeQNameEntity = qnameDAO.getOrCreateQNameEntity(assocTypeQName);
NodeAssoc assoc = new NodeAssocImpl();
assoc.setTypeQName(assocTypeQName);
assoc.setTypeQName(assocTypeQNameEntity);
assoc.buildAssociation(sourceNode, targetNode);
// persist
try
@@ -1269,7 +1327,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_NODE_ASSOCS_TO_AND_FROM)
.setLong("nodeId", node.getId());
.setParameter("node", node);
return query.list();
}
};
@@ -1286,11 +1344,17 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
public Object doInHibernate(Session session)
{
QNameEntity assocTypeQNameEntity = qnameDAO.getQNameEntity(assocTypeQName);
if (assocTypeQNameEntity == null)
{
// There can be no match;
return null;
}
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_NODE_ASSOC)
.setLong("sourceId", sourceNode.getId())
.setLong("targetId", targetNode.getId())
.setParameter("assocTypeQName", assocTypeQName);
.setParameter("source", sourceNode)
.setParameter("target", targetNode)
.setParameter("assocTypeQName", assocTypeQNameEntity);
return query.uniqueResult();
}
};
@@ -1307,7 +1371,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_TARGET_ASSOCS)
.setLong("sourceId", sourceNode.getId());
.setParameter("source", sourceNode);
return query.list();
}
};
@@ -1324,7 +1388,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Query query = session
.getNamedQuery(HibernateNodeDaoServiceImpl.QUERY_GET_SOURCE_ASSOCS)
.setLong("targetId", targetNode.getId());
.setParameter("target", targetNode);
return query.list();
}
};
@@ -1362,7 +1426,7 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
{
Node node = (Node) results.get()[0];
// loop through all the node properties
Map<QName, PropertyValue> properties = node.getProperties();
Map<Long, PropertyValue> properties = node.getProperties();
for (PropertyValue propertyValue : properties.values())
{
// ignore nulls

View File

@@ -218,7 +218,7 @@ public class RetryingTransactionHelper
{
if (requiresNew)
{
txn = txnService.getNonPropagatingUserTransaction();
txn = txnService.getNonPropagatingUserTransaction(readOnly);
}
else
{