From b0aac65e9a078d5fab49deb8fd5a4ceeea6c4daa Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Tue, 15 Sep 2009 10:03:18 +0000 Subject: [PATCH] Updates of root (unshared) properties are done via EntityLookupCache git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16269 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../propval/AbstractPropertyValueDAOImpl.java | 155 +++++++++--------- .../repo/domain/propval/PropertyValueDAO.java | 2 + 2 files changed, 81 insertions(+), 76 deletions(-) diff --git a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java index 3640831f6b..4db719e8fa 100644 --- a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java @@ -801,56 +801,95 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO */ public Long createProperty(Serializable value) { - // We will need a new root - Long rootPropId = createPropertyRoot(); - createPropertyImpl(rootPropId, 0L, 0L, null, value); - // Push this value into the cache - propertyCache.updateValue(rootPropId, value); - // Done - if (logger.isDebugEnabled()) - { - logger.debug( - "Created property: \n" + - " ID: " + rootPropId + "\n" + - " Value: " + value); - } - return rootPropId; + Pair entityPair = propertyCache.getOrCreateByValue(value); + return entityPair.getFirst(); } public void updateProperty(Long rootPropId, Serializable value) { - // Remove all entries for the root - PropertyRootEntity entity = getPropertyRoot(rootPropId); - if (entity == null) - { - throw new DataIntegrityViolationException("No property root exists for ID " + rootPropId); - } - // Remove all links using the root - deletePropertyLinks(rootPropId); - // Create the new properties and update the cache - createPropertyImpl(rootPropId, 0L, 0L, null, value); propertyCache.updateValue(rootPropId, value); - // Update the property root to detect concurrent modification - updatePropertyRoot(entity); - // Done - if (logger.isDebugEnabled()) - { - logger.debug( - "Updated property: \n" + - " ID: " + rootPropId + "\n" + - " Value: " + value); - } } public void deleteProperty(Long id) { - deletePropertyRoot(id); - // Done - if (logger.isDebugEnabled()) + propertyCache.deleteByKey(id); + } + + /** + * Callback for alf_prop_root DAO. + */ + private class PropertyCallbackDAO extends EntityLookupCallbackDAOAdaptor + { + public Pair createValue(Serializable value) { - logger.debug( - "Deleted property: \n" + - " ID: " + id); + // We will need a new root + Long rootPropId = createPropertyRoot(); + createPropertyImpl(rootPropId, 0L, 0L, null, value); + // Done + if (logger.isDebugEnabled()) + { + logger.debug( + "Created property: \n" + + " ID: " + rootPropId + "\n" + + " Value: " + value); + } + return new Pair(rootPropId, value); + } + + public Pair findByKey(Long key) + { + List rows = findPropertyById(key); + if (rows.size() == 0) + { + // No results + return null; + } + Serializable value = convertPropertyIdSearchRows(rows); + return new Pair(key, value); + } + + /** + * No-op. This is implemented as we just want to update the cache. + * @return Returns 0 always + */ + @Override + public int updateValue(Long key, Serializable value) + { + // Remove all entries for the root + PropertyRootEntity entity = getPropertyRoot(key); + if (entity == null) + { + throw new DataIntegrityViolationException("No property root exists for ID " + key); + } + // Remove all links using the root + deletePropertyLinks(key); + // Create the new properties and update the cache + createPropertyImpl(key, 0L, 0L, null, value); + // Update the property root to detect concurrent modification + updatePropertyRoot(entity); + // Done + if (logger.isDebugEnabled()) + { + logger.debug( + "Updated property: \n" + + " ID: " + key + "\n" + + " Value: " + value); + } + return 1; + } + + @Override + public int deleteByKey(Long key) + { + deletePropertyRoot(key); + // Done + if (logger.isDebugEnabled()) + { + logger.debug( + "Deleted property: \n" + + " ID: " + key); + } + return 1; } } @@ -991,42 +1030,6 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO } } - /** - * Callback for alf_prop_root DAO. - */ - private class PropertyCallbackDAO extends EntityLookupCallbackDAOAdaptor - { - public Pair createValue(Serializable value) - { - PropertyValueEntity entity = createPropertyValue(value); - // Done - return new Pair(entity.getId(), value); - } - - public Pair findByKey(Long key) - { - List rows = findPropertyById(key); - if (rows.size() == 0) - { - // No results - return null; - } - Serializable value = convertPropertyIdSearchRows(rows); - return new Pair(key, value); - } - - /** - * No-op. This is implemented as we just want to update the cache. - * @return Returns 0 always - */ - @Override - public int updateValue(Long key, Serializable value) - { - return 0; - } - } - - protected abstract List findPropertyById(Long id); protected abstract Long createPropertyRoot(); protected abstract PropertyRootEntity getPropertyRoot(Long id); diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java index 80d06dff76..c8512b4098 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java @@ -30,6 +30,7 @@ import java.util.List; import org.alfresco.repo.domain.CrcHelper; import org.alfresco.util.Pair; +import org.springframework.dao.DataIntegrityViolationException; /** * DAO services for alf_prop_XXX tables. @@ -184,6 +185,7 @@ public interface PropertyValueDAO * * @param id the ID (may not be null) * @return Returns the value of the property (never null) + * @throws DataIntegrityViolationException if the ID is invalid */ Serializable getPropertyById(Long id); /**