diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml
index 471bc1eeb2..5c09e4fdb4 100644
--- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml
+++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/propval-common-SqlMap.xml
@@ -461,4 +461,17 @@
id = #id#
+
+ delete from
+ alf_prop_unique_ctx
+ where
+ value1_prop_id = #value1PropId#
+
+ and value2_prop_id = #value2PropId#
+
+
+ and value3_prop_id = #value3PropId#
+
+
+
\ No newline at end of file
diff --git a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java
index fcec61e7c0..dbba823740 100644
--- a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java
@@ -1147,10 +1147,40 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
}
}
+ public int deletePropertyUniqueContext(Serializable... values)
+ {
+ if (values.length < 1 || values.length > 3)
+ {
+ throw new IllegalArgumentException("Deletion of unique property sets must have 1, 2 or 3 values");
+ }
+ Long[] valueIds = new Long[values.length];
+ for (int i = 0; i < values.length; i++)
+ {
+ Pair valuePair = getPropertyValue(values[i]);
+ if (valuePair == null)
+ {
+ // No such value, so no need to delete
+ return 0;
+ }
+ valueIds[i] = valuePair.getFirst();
+ }
+ int deleted = deletePropertyUniqueContexts(valueIds);
+ // Done
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(
+ "Deleted " + deleted + " unique property contexts: \n" +
+ " Values: " + values + "\n" +
+ " IDs: " + valueIds);
+ }
+ return deleted;
+ }
+
protected abstract PropertyUniqueContextEntity createPropertyUniqueContext(Long valueId1, Long valueId2, Long valueId3);
protected abstract PropertyUniqueContextEntity getPropertyUniqueContextById(Long id);
protected abstract PropertyUniqueContextEntity getPropertyUniqueContextByValues(Long valueId1, Long valueId2, Long valueId3);
protected abstract PropertyUniqueContextEntity updatePropertyUniqueContext(PropertyUniqueContextEntity entity);
+ protected abstract int deletePropertyUniqueContexts(Long ... valueIds);
//================================
// Utility methods
diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java
index 5986f4c5f5..9cf855b931 100644
--- a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java
+++ b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java
@@ -279,6 +279,13 @@ public interface PropertyValueDAO
* @see #createPropertyUniqueContext(Serializable, Serializable, Serializable)
*/
void deletePropertyUniqueContext(Long id);
+ /**
+ * Delete sets of unique contexts based on one, two or three context values.
+ *
+ * @param values a combination of one to three values in order
+ * @return Returns the number of unique contexts deleted
+ */
+ int deletePropertyUniqueContext(Serializable ... values);
//================================
// Utility methods
diff --git a/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java b/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java
index c38bf82cf0..04d4bbced9 100644
--- a/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java
@@ -88,6 +88,7 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
private static final String INSERT_PROPERTY_UNIQUE_CTX = "alfresco.propval.insert_PropertyUniqueContext";
private static final String UPDATE_PROPERTY_UNIQUE_CTX = "alfresco.propval.update_PropertyUniqueContext";
private static final String DELETE_PROPERTY_UNIQUE_CTX_BY_ID = "alfresco.propval.delete_PropertyUniqueContextById";
+ private static final String DELETE_PROPERTY_UNIQUE_CTX_BY_VALUES = "alfresco.propval.delete_PropertyUniqueContextByValues";
private static final String INSERT_PROPERTY_LINK = "alfresco.propval.insert_PropertyLink";
private static final String DELETE_PROPERTY_LINKS_BY_ROOT_ID = "alfresco.propval.delete_PropertyLinksByRootId";
@@ -533,6 +534,30 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
template.delete(DELETE_PROPERTY_UNIQUE_CTX_BY_ID, entity);
}
+ @Override
+ protected int deletePropertyUniqueContexts(Long... valueIds)
+ {
+ PropertyUniqueContextEntity entity = new PropertyUniqueContextEntity();
+ for (int i = 0; i < valueIds.length; i++)
+ {
+ switch (i)
+ {
+ case 0:
+ entity.setValue1PropId(valueIds[i]);
+ break;
+ case 1:
+ entity.setValue2PropId(valueIds[i]);
+ break;
+ case 2:
+ entity.setValue3PropId(valueIds[i]);
+ break;
+ default:
+ throw new IllegalArgumentException("Only 3 ids allowed");
+ }
+ }
+ return template.delete(DELETE_PROPERTY_UNIQUE_CTX_BY_VALUES, entity);
+ }
+
@Override
protected void createPropertyLink(
Long rootPropId,
diff --git a/source/java/org/alfresco/repo/props/PropertyValueComponent.java b/source/java/org/alfresco/repo/props/PropertyValueComponent.java
index 8884011f2e..7986167352 100644
--- a/source/java/org/alfresco/repo/props/PropertyValueComponent.java
+++ b/source/java/org/alfresco/repo/props/PropertyValueComponent.java
@@ -143,9 +143,8 @@ public interface PropertyValueComponent
* Delete a combination of three unique properties. It doesn't matter if the unique combination
* already existed or not.
*
- * @param value1 the first property (null allowed)
- * @param value2 the second property (null allowed)
- * @param value3 the third property (null allowed)
+ * @param values an array of one, two or three values, any of which may be null
+ * @return Returns the number of unique combinations deleted
*/
- void deletePropertyUniqueContext(Serializable value1, Serializable value2, Serializable value3);
+ int deletePropertyUniqueContexts(Serializable ... values);
}
diff --git a/source/java/org/alfresco/repo/props/PropertyValueComponentImpl.java b/source/java/org/alfresco/repo/props/PropertyValueComponentImpl.java
index 7edfda9c93..14b2eab4a9 100644
--- a/source/java/org/alfresco/repo/props/PropertyValueComponentImpl.java
+++ b/source/java/org/alfresco/repo/props/PropertyValueComponentImpl.java
@@ -236,35 +236,16 @@ public class PropertyValueComponentImpl implements PropertyValueComponent
/**
* {@inheritDoc}
*/
- public void deletePropertyUniqueContext(Serializable value1, Serializable value2, Serializable value3)
+ public int deletePropertyUniqueContexts(Serializable ... values)
{
- // Get the ID of the values
- Long id = getPropertyUniqueContext(value1, value2, value3);
- if (id == null)
- {
- // No need to delete
- if (logger.isDebugEnabled())
- {
- logger.debug(
- "No unique property context exists: \n" +
- " Value1: " + value1 + "\n" +
- " Value2: " + value2 + "\n" +
- " Value3: " + value3);
- }
- }
- else
- {
- deletePropertyUniqueContext(id);
- // Deleted
- if (logger.isDebugEnabled())
- {
- logger.debug(
- "Deleted unique property context: \n" +
- " Value1: " + value1 + "\n" +
- " Value2: " + value2 + "\n" +
- " Value3: " + value3);
- }
- }
+ int deleted = propertyValueDAO.deletePropertyUniqueContext(values);
// Done
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(
+ "Deleted " + deleted + " unique property contexts: \n" +
+ " Values: " + values);
+ }
+ return deleted;
}
}
diff --git a/source/java/org/alfresco/repo/props/PropertyValueComponentTest.java b/source/java/org/alfresco/repo/props/PropertyValueComponentTest.java
index ed74887369..b45dcdd613 100644
--- a/source/java/org/alfresco/repo/props/PropertyValueComponentTest.java
+++ b/source/java/org/alfresco/repo/props/PropertyValueComponentTest.java
@@ -122,5 +122,31 @@ public class PropertyValueComponentTest extends TestCase
logger.debug("Expected exception: " + e.getMessage());
}
}
+
+ // Delete everything for the store and check that both are creatable again
+ RetryingTransactionCallback deleteStoreCallback = new RetryingTransactionCallback()
+ {
+ public Void execute() throws Throwable
+ {
+ propertyValueComponent.deletePropertyUniqueContexts(context, store);
+ propertyValueComponent.createPropertyUniqueContext(context, store, uuid1);
+ propertyValueComponent.createPropertyUniqueContext(context, store, uuid2);
+ return null;
+ }
+ };
+ transactionService.getRetryingTransactionHelper().doInTransaction(deleteStoreCallback);
+
+ // Delete everything for the context and check that both are creatable again
+ RetryingTransactionCallback deleteContextCallback = new RetryingTransactionCallback()
+ {
+ public Void execute() throws Throwable
+ {
+ propertyValueComponent.deletePropertyUniqueContexts(context);
+ propertyValueComponent.createPropertyUniqueContext(context, store, uuid1);
+ propertyValueComponent.createPropertyUniqueContext(context, store, uuid2);
+ return null;
+ }
+ };
+ transactionService.getRetryingTransactionHelper().doInTransaction(deleteContextCallback);
}
}