mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added method to delete multiple child contexts for unique property contexts
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16441 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -461,4 +461,17 @@
|
|||||||
id = #id#
|
id = #id#
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<delete id="delete_PropertyUniqueContextByValues" parameterClass="PropertyUniqueContext">
|
||||||
|
delete from
|
||||||
|
alf_prop_unique_ctx
|
||||||
|
where
|
||||||
|
value1_prop_id = #value1PropId#
|
||||||
|
<isNotNull property="value2PropId">
|
||||||
|
and value2_prop_id = #value2PropId#
|
||||||
|
</isNotNull>
|
||||||
|
<isNotNull property="value3PropId">
|
||||||
|
and value3_prop_id = #value3PropId#
|
||||||
|
</isNotNull>
|
||||||
|
</delete>
|
||||||
|
|
||||||
</sqlMap>
|
</sqlMap>
|
@@ -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<Long, Serializable> 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 createPropertyUniqueContext(Long valueId1, Long valueId2, Long valueId3);
|
||||||
protected abstract PropertyUniqueContextEntity getPropertyUniqueContextById(Long id);
|
protected abstract PropertyUniqueContextEntity getPropertyUniqueContextById(Long id);
|
||||||
protected abstract PropertyUniqueContextEntity getPropertyUniqueContextByValues(Long valueId1, Long valueId2, Long valueId3);
|
protected abstract PropertyUniqueContextEntity getPropertyUniqueContextByValues(Long valueId1, Long valueId2, Long valueId3);
|
||||||
protected abstract PropertyUniqueContextEntity updatePropertyUniqueContext(PropertyUniqueContextEntity entity);
|
protected abstract PropertyUniqueContextEntity updatePropertyUniqueContext(PropertyUniqueContextEntity entity);
|
||||||
|
protected abstract int deletePropertyUniqueContexts(Long ... valueIds);
|
||||||
|
|
||||||
//================================
|
//================================
|
||||||
// Utility methods
|
// Utility methods
|
||||||
|
@@ -279,6 +279,13 @@ public interface PropertyValueDAO
|
|||||||
* @see #createPropertyUniqueContext(Serializable, Serializable, Serializable)
|
* @see #createPropertyUniqueContext(Serializable, Serializable, Serializable)
|
||||||
*/
|
*/
|
||||||
void deletePropertyUniqueContext(Long id);
|
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
|
// Utility methods
|
||||||
|
@@ -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 INSERT_PROPERTY_UNIQUE_CTX = "alfresco.propval.insert_PropertyUniqueContext";
|
||||||
private static final String UPDATE_PROPERTY_UNIQUE_CTX = "alfresco.propval.update_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_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 INSERT_PROPERTY_LINK = "alfresco.propval.insert_PropertyLink";
|
||||||
private static final String DELETE_PROPERTY_LINKS_BY_ROOT_ID = "alfresco.propval.delete_PropertyLinksByRootId";
|
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);
|
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
|
@Override
|
||||||
protected void createPropertyLink(
|
protected void createPropertyLink(
|
||||||
Long rootPropId,
|
Long rootPropId,
|
||||||
|
@@ -143,9 +143,8 @@ public interface PropertyValueComponent
|
|||||||
* Delete a combination of three unique properties. It doesn't matter if the unique combination
|
* Delete a combination of three unique properties. It doesn't matter if the unique combination
|
||||||
* already existed or not.
|
* already existed or not.
|
||||||
*
|
*
|
||||||
* @param value1 the first property (<tt>null</tt> allowed)
|
* @param values an array of one, two or three values, any of which may be <tt>null</tt>
|
||||||
* @param value2 the second property (<tt>null</tt> allowed)
|
* @return Returns the number of unique combinations deleted
|
||||||
* @param value3 the third property (<tt>null</tt> allowed)
|
|
||||||
*/
|
*/
|
||||||
void deletePropertyUniqueContext(Serializable value1, Serializable value2, Serializable value3);
|
int deletePropertyUniqueContexts(Serializable ... values);
|
||||||
}
|
}
|
||||||
|
@@ -236,35 +236,16 @@ public class PropertyValueComponentImpl implements PropertyValueComponent
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public void deletePropertyUniqueContext(Serializable value1, Serializable value2, Serializable value3)
|
public int deletePropertyUniqueContexts(Serializable ... values)
|
||||||
{
|
{
|
||||||
// Get the ID of the values
|
int deleted = propertyValueDAO.deletePropertyUniqueContext(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Done
|
// Done
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(
|
||||||
|
"Deleted " + deleted + " unique property contexts: \n" +
|
||||||
|
" Values: " + values);
|
||||||
|
}
|
||||||
|
return deleted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -122,5 +122,31 @@ public class PropertyValueComponentTest extends TestCase
|
|||||||
logger.debug("Expected exception: " + e.getMessage());
|
logger.debug("Expected exception: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete everything for the store and check that both are creatable again
|
||||||
|
RetryingTransactionCallback<Void> deleteStoreCallback = new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
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<Void> deleteContextCallback = new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
propertyValueComponent.deletePropertyUniqueContexts(context);
|
||||||
|
propertyValueComponent.createPropertyUniqueContext(context, store, uuid1);
|
||||||
|
propertyValueComponent.createPropertyUniqueContext(context, store, uuid2);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
transactionService.getRetryingTransactionHelper().doInTransaction(deleteContextCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user