diff --git a/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java b/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java index 9ead92c233..de7bd077f0 100644 --- a/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java @@ -1569,10 +1569,23 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO // Remove sys:referenceable ReferenceablePropertiesEntity.removeReferenceableProperties(node, newProps); + // Get the old properties in the raw format, attempting a shortcut for new nodes + Map oldPropsRaw = null; + Map oldProps = propertiesCache.getValue(nodeId); + if (oldProps != null && oldProps.isEmpty()) + { + // Don't requery + oldPropsRaw = Collections.emptyMap(); + isAddOnly = false; + } + else + { + oldPropsRaw = selectNodeProperties(nodeId); + } + // Determine which properties we are interested in. For addition of properties, we only // need the old properties for the QNames being added. For complete setting of properties, // we need the full set of old properties. - Map oldPropsRaw = selectNodeProperties(nodeId); Set qnameIdsOfInterest = qnameDAO.convertQNamesToIds(newProps.keySet(), true); // Get new property raw values @@ -1617,7 +1630,7 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO if (newContentData != null) { Long newContentDataId = contentDataDAO.createContentData(newContentData).getFirst(); - newPropValue = new NodePropertyValue(DataTypeDefinition.CONTENT, newContentDataId); + newPropValue = new NodePropertyValue(DataTypeDefinition.CONTENT, new ContentDataId(newContentDataId)); propsToAdd.put(key, newPropValue); } } @@ -1678,7 +1691,7 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO if (newContentData != null) { Long newContentDataId = contentDataDAO.createContentData(newContentData).getFirst(); - newPropValue = new NodePropertyValue(DataTypeDefinition.CONTENT, newContentDataId); + newPropValue = new NodePropertyValue(DataTypeDefinition.CONTENT, new ContentDataId(newContentDataId)); propsToAdd.put(key, newPropValue); } } diff --git a/source/java/org/alfresco/repo/domain/ContentDataId.java b/source/java/org/alfresco/repo/domain/node/ContentDataId.java similarity index 94% rename from source/java/org/alfresco/repo/domain/ContentDataId.java rename to source/java/org/alfresco/repo/domain/node/ContentDataId.java index 98373ef78d..2bb83f718c 100644 --- a/source/java/org/alfresco/repo/domain/ContentDataId.java +++ b/source/java/org/alfresco/repo/domain/node/ContentDataId.java @@ -22,7 +22,7 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ -package org.alfresco.repo.domain; +package org.alfresco.repo.domain.node; import java.io.Serializable; diff --git a/source/java/org/alfresco/repo/domain/node/ContentDataWithId.java b/source/java/org/alfresco/repo/domain/node/ContentDataWithId.java new file mode 100644 index 0000000000..690baa0446 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/node/ContentDataWithId.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2005-2008 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.node; + +import org.alfresco.service.cmr.repository.ContentData; + +/** + * ContentData-derived class with ID. + * + * @author Derek Hulley + * @since 3.4 + */ +public class ContentDataWithId extends ContentData +{ + private final Long id; + + public ContentDataWithId(ContentData contentData, Long id) + { + super(contentData); + this.id = id; + } + + @Override + public String toString() + { + return "ContentData [id=" + id + "]"; + } + + public Long getId() + { + return id; + } +} diff --git a/source/java/org/alfresco/repo/domain/node/NodePropertyHelper.java b/source/java/org/alfresco/repo/domain/node/NodePropertyHelper.java index 0e6c2c3262..d1a6356cff 100644 --- a/source/java/org/alfresco/repo/domain/node/NodePropertyHelper.java +++ b/source/java/org/alfresco/repo/domain/node/NodePropertyHelper.java @@ -35,7 +35,6 @@ import java.util.SortedMap; import java.util.TreeMap; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.domain.ContentDataId; import org.alfresco.repo.domain.contentdata.ContentDataDAO; import org.alfresco.repo.domain.locale.LocaleDAO; import org.alfresco.repo.domain.qname.QNameDAO; @@ -252,18 +251,6 @@ public class NodePropertyHelper + " Property: " + propertyDef + "\n" + " Type: " + propertyTypeQName + "\n" + " Value: " + value); } - // Handle ContentData - // We used to check the property type, but we now handle d:any ContentData as well - if (value instanceof ContentData) - { - // We keep the ContentData i.e. we treat it as a low-level property that will be handled externally. - // This will be converted to a String and persisted as such unless the value is ultimately - // replaced by and ID-based ContentData reference -// // Needs converting to an ID -// ContentData contentData = (ContentData) value; -// Long contentDataId = contentDataDAO.createContentData(contentData).getFirst(); -// value = new ContentDataId(contentDataId); - } // Handle MLText if (value instanceof MLText) { @@ -618,30 +605,14 @@ public class NodePropertyHelper // ContentData used to be persisted as a String and then as a Long. // Now it has a special type to denote the ID Long contentDataId = ((ContentDataId) value).getId(); - Pair contentDataPair = contentDataDAO.getContentData(contentDataId); - if (contentDataPair == null) - { - // It is invalid - value = null; - } - else - { - value = contentDataPair.getSecond(); - } + ContentData contentData = contentDataDAO.getContentData(contentDataId).getSecond(); + value = new ContentDataWithId(contentData, contentDataId); } - else if (propertyTypeQName.equals(DataTypeDefinition.CONTENT) && (value instanceof Long)) + else if ((value instanceof Long) && propertyTypeQName.equals(DataTypeDefinition.CONTENT)) { - // ContentData used to be persisted - Pair contentDataPair = contentDataDAO.getContentData((Long) value); - if (contentDataPair == null) - { - // It is invalid - value = null; - } - else - { - value = contentDataPair.getSecond(); - } + Long contentDataId = (Long) value; + ContentData contentData = contentDataDAO.getContentData(contentDataId).getSecond(); + value = new ContentDataWithId(contentData, contentDataId); } // done return value; diff --git a/source/java/org/alfresco/repo/domain/node/NodePropertyValue.java b/source/java/org/alfresco/repo/domain/node/NodePropertyValue.java index fef3daf6c2..5705f9f794 100644 --- a/source/java/org/alfresco/repo/domain/node/NodePropertyValue.java +++ b/source/java/org/alfresco/repo/domain/node/NodePropertyValue.java @@ -37,7 +37,6 @@ import java.util.Locale; import java.util.Map; import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.domain.ContentDataId; import org.alfresco.repo.domain.schema.SchemaBootstrap; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.repository.AssociationRef; @@ -50,10 +49,10 @@ import org.alfresco.service.cmr.repository.Period; import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.namespace.QName; import org.alfresco.util.EqualsHelper; -import org.springframework.extensions.surf.util.ParameterCheck; import org.alfresco.util.VersionNumber; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.ParameterCheck; /** * Immutable property value storage class.