mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Further DAO for audit values
- General-purpose property persisting in searchable schema - TODO: More high volume tests for general values git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15556 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -31,6 +31,7 @@ import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.cache.lookup.EntityLookupCache;
|
||||
import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO;
|
||||
import org.alfresco.repo.domain.CrcHelper;
|
||||
import org.alfresco.repo.domain.propval.PropertyValueEntity.PersistedType;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
@@ -46,9 +47,15 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
{
|
||||
private static final String CACHE_REGION_PROPERTY_CLASS = "PropertyClass";
|
||||
private static final String CACHE_REGION_PROPERTY_STRING_VALUE = "PropertyStringValue";
|
||||
private static final String CACHE_REGION_PROPERTY_DOUBLE_VALUE = "PropertyDoubleValue";
|
||||
private static final String CACHE_REGION_PROPERTY_VALUE = "PropertyValue";
|
||||
|
||||
protected PropertyTypeConverter converter;
|
||||
|
||||
private final PropertyClassCallbackDAO propertyClassDaoCallback;
|
||||
private final PropertyStringValueCallbackDAO propertyStringValueCallback;
|
||||
private final PropertyDoubleValueCallbackDAO propertyDoubleValueCallback;
|
||||
private final PropertyValueCallbackDAO propertyValueCallback;
|
||||
/**
|
||||
* Cache for the property class:<br/>
|
||||
* KEY: ID<br/>
|
||||
@@ -63,6 +70,20 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
* VALUE KEY: Short string-crc pair ({@link CrcHelper#getStringCrcPair(String, int, boolean, boolean)})<br/>
|
||||
*/
|
||||
private EntityLookupCache<Long, String, Pair<String, Long>> propertyStringValueCache;
|
||||
/**
|
||||
* Cache for the property double value:<br/>
|
||||
* KEY: ID<br/>
|
||||
* VALUE: The Double instance<br/>
|
||||
* VALUE KEY: The value itself<br/>
|
||||
*/
|
||||
private EntityLookupCache<Long, Double, Double> propertyDoubleValueCache;
|
||||
/**
|
||||
* Cache for the property value:<br/>
|
||||
* KEY: ID<br/>
|
||||
* VALUE: The Serializable instance<br/>
|
||||
* VALUE KEY: A value key based on the persisted type<br/>
|
||||
*/
|
||||
private EntityLookupCache<Long, Serializable, Serializable> propertyValueCache;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@@ -74,11 +95,23 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
{
|
||||
this.propertyClassDaoCallback = new PropertyClassCallbackDAO();
|
||||
this.propertyStringValueCallback = new PropertyStringValueCallbackDAO();
|
||||
this.propertyDoubleValueCallback = new PropertyDoubleValueCallbackDAO();
|
||||
this.propertyValueCallback = new PropertyValueCallbackDAO();
|
||||
|
||||
this.propertyClassCache = new EntityLookupCache<Long, Class<?>, String>(propertyClassDaoCallback);
|
||||
this.propertyStringValueCache = new EntityLookupCache<Long, String, Pair<String, Long>>(propertyStringValueCallback);
|
||||
this.propertyDoubleValueCache = new EntityLookupCache<Long, Double, Double>(propertyDoubleValueCallback);
|
||||
this.propertyValueCache = new EntityLookupCache<Long, Serializable, Serializable>(propertyValueCallback);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param converter the converter that translates between external and persisted values
|
||||
*/
|
||||
public void setConverter(PropertyTypeConverter converter)
|
||||
{
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to use for <b>alf_prop_class</b> lookups (optional).
|
||||
*
|
||||
@@ -105,12 +138,42 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
propertyStringValueCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to use for <b>alf_prop_double_value</b> lookups (optional).
|
||||
*
|
||||
* @param propertyDoubleValueCache the cache of IDs to property values
|
||||
*/
|
||||
public void setPropertyDoubleValueCache(SimpleCache<Serializable, Object> propertyDoubleValueCache)
|
||||
{
|
||||
this.propertyDoubleValueCache = new EntityLookupCache<Long, Double, Double>(
|
||||
propertyDoubleValueCache,
|
||||
CACHE_REGION_PROPERTY_DOUBLE_VALUE,
|
||||
propertyDoubleValueCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to use for <b>alf_prop_value</b> lookups (optional).
|
||||
*
|
||||
* @param propertyValueCache the cache of IDs to property values
|
||||
*/
|
||||
public void setPropertyValueCache(SimpleCache<Serializable, Object> propertyValueCache)
|
||||
{
|
||||
this.propertyValueCache = new EntityLookupCache<Long, Serializable, Serializable>(
|
||||
propertyValueCache,
|
||||
CACHE_REGION_PROPERTY_VALUE,
|
||||
propertyValueCallback);
|
||||
}
|
||||
|
||||
//================================
|
||||
// 'alf_prop_class' accessors
|
||||
//================================
|
||||
|
||||
public Pair<Long, Class<?>> getPropertyClass(Long id)
|
||||
public Pair<Long, Class<?>> getPropertyClassById(Long id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot look up entity by null ID.");
|
||||
}
|
||||
Pair<Long, Class<?>> entityPair = propertyClassCache.getByKey(id);
|
||||
if (entityPair == null)
|
||||
{
|
||||
@@ -121,12 +184,20 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
|
||||
public Pair<Long, Class<?>> getPropertyClass(Class<?> value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Property class cannot be null");
|
||||
}
|
||||
Pair<Long, Class<?>> entityPair = propertyClassCache.getByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Class<?>> getOrCreatePropertyClass(Class<?> value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Property class cannot be null");
|
||||
}
|
||||
Pair<Long, Class<?>> entityPair = propertyClassCache.getOrCreateByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
@@ -136,15 +207,15 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
*/
|
||||
private class PropertyClassCallbackDAO implements EntityLookupCallbackDAO<Long, Class<?>, String>
|
||||
{
|
||||
private final Pair<Long, Class<?>> convertEntityToPair(PropertyClassEntity propertyClassEntity)
|
||||
private final Pair<Long, Class<?>> convertEntityToPair(PropertyClassEntity entity)
|
||||
{
|
||||
if (propertyClassEntity == null)
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return propertyClassEntity.getEntityPair();
|
||||
return entity.getEntityPair();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,24 +251,36 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
// 'alf_prop_string_value' accessors
|
||||
//================================
|
||||
|
||||
public Pair<Long, String> getPropertyStringValue(Long id)
|
||||
public Pair<Long, String> getPropertyStringValueById(Long id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot look up entity by null ID.");
|
||||
}
|
||||
Pair<Long, String> entityPair = propertyStringValueCache.getByKey(id);
|
||||
if (entityPair == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("No property class exists for ID " + id);
|
||||
throw new AlfrescoRuntimeException("No property string value exists for ID " + id);
|
||||
}
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, String> getPropertyStringValue(String value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted string values cannot be null");
|
||||
}
|
||||
Pair<Long, String> entityPair = propertyStringValueCache.getByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, String> getOrCreatePropertyStringValue(String value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted string values cannot be null");
|
||||
}
|
||||
Pair<Long, String> entityPair = propertyStringValueCache.getOrCreateByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
@@ -207,15 +290,15 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
*/
|
||||
private class PropertyStringValueCallbackDAO implements EntityLookupCallbackDAO<Long, String, Pair<String, Long>>
|
||||
{
|
||||
private final Pair<Long, String> convertEntityToPair(PropertyStringValueEntity propertyStringValueEntity)
|
||||
private final Pair<Long, String> convertEntityToPair(PropertyStringValueEntity entity)
|
||||
{
|
||||
if (propertyStringValueEntity == null)
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return propertyStringValueEntity.getEntityPair();
|
||||
return entity.getEntityPair();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,4 +330,185 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
protected abstract PropertyStringValueEntity findStringValueByValue(String value);
|
||||
protected abstract PropertyStringValueEntity createStringValue(String value);
|
||||
|
||||
//================================
|
||||
// 'alf_prop_double_value' accessors
|
||||
//================================
|
||||
|
||||
public Pair<Long, Double> getPropertyDoubleValueById(Long id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot look up entity by null ID.");
|
||||
}
|
||||
Pair<Long, Double> entityPair = propertyDoubleValueCache.getByKey(id);
|
||||
if (entityPair == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("No property double value exists for ID " + id);
|
||||
}
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Double> getPropertyDoubleValue(Double value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted double values cannot be null");
|
||||
}
|
||||
Pair<Long, Double> entityPair = propertyDoubleValueCache.getByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Double> getOrCreatePropertyDoubleValue(Double value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted double values cannot be null");
|
||||
}
|
||||
Pair<Long, Double> entityPair = propertyDoubleValueCache.getOrCreateByValue(value);
|
||||
return (Pair<Long, Double>) entityPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for <b>alf_prop_double_value</b> DAO.
|
||||
*/
|
||||
private class PropertyDoubleValueCallbackDAO implements EntityLookupCallbackDAO<Long, Double, Double>
|
||||
{
|
||||
private final Pair<Long, Double> convertEntityToPair(PropertyDoubleValueEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return entity.getEntityPair();
|
||||
}
|
||||
}
|
||||
|
||||
public Double getValueKey(Double value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public Pair<Long, Double> createValue(Double value)
|
||||
{
|
||||
PropertyDoubleValueEntity entity = createDoubleValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Double> findByKey(Long key)
|
||||
{
|
||||
PropertyDoubleValueEntity entity = findDoubleValueById(key);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Double> findByValue(Double value)
|
||||
{
|
||||
PropertyDoubleValueEntity entity = findDoubleValueByValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PropertyDoubleValueEntity findDoubleValueById(Long id);
|
||||
protected abstract PropertyDoubleValueEntity findDoubleValueByValue(Double value);
|
||||
protected abstract PropertyDoubleValueEntity createDoubleValue(Double value);
|
||||
|
||||
//================================
|
||||
// 'alf_prop_value' accessors
|
||||
//================================
|
||||
|
||||
public Pair<Long, Serializable> getPropertyValueById(Long id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot look up entity by null ID.");
|
||||
}
|
||||
Pair<Long, Serializable> entityPair = propertyValueCache.getByKey(id);
|
||||
if (entityPair == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("No property value exists for ID " + id);
|
||||
}
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Serializable> getPropertyValue(Serializable value)
|
||||
{
|
||||
Pair<Long, Serializable> entityPair = propertyValueCache.getByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Serializable> getOrCreatePropertyValue(Serializable value)
|
||||
{
|
||||
Pair<Long, Serializable> entityPair = propertyValueCache.getOrCreateByValue(value);
|
||||
return (Pair<Long, Serializable>) entityPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for <b>alf_prop_value</b> DAO.
|
||||
*/
|
||||
private class PropertyValueCallbackDAO implements EntityLookupCallbackDAO<Long, Serializable, Serializable>
|
||||
{
|
||||
private final Pair<Long, Serializable> convertEntityToPair(PropertyValueEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return entity.getEntityPair();
|
||||
}
|
||||
}
|
||||
|
||||
public Serializable getValueKey(Serializable value)
|
||||
{
|
||||
// Find out how it would be persisted
|
||||
Pair<Short, Serializable> persistedValuePair = converter.convertToPersistedType(value);
|
||||
// We don't return keys for pure Serializable instances
|
||||
if (persistedValuePair.getFirst().equals(PersistedType.SERIALIZABLE.getOrdinalNumber()))
|
||||
{
|
||||
// It will be Serialized, so no key
|
||||
return null;
|
||||
}
|
||||
else if (value instanceof String)
|
||||
{
|
||||
return CrcHelper.getStringCrcPair((String)value, 128, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We've dodged Serializable and String; everything else is OK as a key.
|
||||
return persistedValuePair;
|
||||
}
|
||||
}
|
||||
|
||||
public Pair<Long, Serializable> createValue(Serializable value)
|
||||
{
|
||||
PropertyValueEntity entity = createPropertyValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Serializable> findByKey(Long key)
|
||||
{
|
||||
PropertyValueEntity entity = findPropertyValueById(key);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Serializable> findByValue(Serializable value)
|
||||
{
|
||||
// // Find out how it would be persisted
|
||||
// Pair<Short, Serializable> persistedValuePair = converter.convertToPersistedType(value);
|
||||
// // We don't do lookups for serializable values
|
||||
// if (persistedValuePair.getFirst().equals(PersistedType.SERIALIZABLE.getOrdinalNumber()))
|
||||
// {
|
||||
// // It will be Serialized, so no we don't look it up
|
||||
// return null;
|
||||
// }
|
||||
PropertyValueEntity entity = findPropertyValueByValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PropertyValueEntity findPropertyValueById(Long id);
|
||||
protected abstract PropertyValueEntity findPropertyValueByValue(Serializable value);
|
||||
protected abstract PropertyValueEntity createPropertyValue(Serializable value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user