mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Further date property support (yyyy-mm-dd)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15666 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -47,17 +47,17 @@ import org.alfresco.util.Pair;
|
||||
public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
{
|
||||
private static final String CACHE_REGION_PROPERTY_CLASS = "PropertyClass";
|
||||
private static final String CACHE_REGION_PROPERTY_DATE_VALUE = "PropertyDateValue";
|
||||
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_DATE_VALUE = "PropertyDateValue";
|
||||
private static final String CACHE_REGION_PROPERTY_VALUE = "PropertyValue";
|
||||
|
||||
protected PropertyTypeConverter converter;
|
||||
|
||||
private final PropertyClassCallbackDAO propertyClassDaoCallback;
|
||||
private final PropertyDateValueCallbackDAO propertyDateValueCallback;
|
||||
private final PropertyStringValueCallbackDAO propertyStringValueCallback;
|
||||
private final PropertyDoubleValueCallbackDAO propertyDoubleValueCallback;
|
||||
private final PropertyDateValueCallbackDAO propertyDateValueCallback;
|
||||
private final PropertyValueCallbackDAO propertyValueCallback;
|
||||
/**
|
||||
* Cache for the property class:<br/>
|
||||
@@ -66,6 +66,13 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
* VALUE KEY: Java class name<br/>
|
||||
*/
|
||||
private EntityLookupCache<Long, Class<?>, String> propertyClassCache;
|
||||
/**
|
||||
* Cache for the property date value:<br/>
|
||||
* KEY: ID<br/>
|
||||
* VALUE: The Date instance<br/>
|
||||
* VALUE KEY: The date-only date (i.e. everything below day is zeroed)<br/>
|
||||
*/
|
||||
private EntityLookupCache<Long, Date, Date> propertyDateValueCache;
|
||||
/**
|
||||
* Cache for the property string value:<br/>
|
||||
* KEY: ID<br/>
|
||||
@@ -80,13 +87,6 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
* VALUE KEY: The value itself<br/>
|
||||
*/
|
||||
private EntityLookupCache<Long, Double, Double> propertyDoubleValueCache;
|
||||
/**
|
||||
* Cache for the property date value:<br/>
|
||||
* KEY: ID<br/>
|
||||
* VALUE: The Date instance<br/>
|
||||
* VALUE KEY: The date-only date (i.e. everything below day is zeroed)<br/>
|
||||
*/
|
||||
private EntityLookupCache<Long, Date, Date> propertyDateValueCache;
|
||||
/**
|
||||
* Cache for the property value:<br/>
|
||||
* KEY: ID<br/>
|
||||
@@ -104,15 +104,15 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
public AbstractPropertyValueDAOImpl()
|
||||
{
|
||||
this.propertyClassDaoCallback = new PropertyClassCallbackDAO();
|
||||
this.propertyDateValueCallback = new PropertyDateValueCallbackDAO();
|
||||
this.propertyStringValueCallback = new PropertyStringValueCallbackDAO();
|
||||
this.propertyDoubleValueCallback = new PropertyDoubleValueCallbackDAO();
|
||||
this.propertyDateValueCallback = new PropertyDateValueCallbackDAO();
|
||||
this.propertyValueCallback = new PropertyValueCallbackDAO();
|
||||
|
||||
this.propertyClassCache = new EntityLookupCache<Long, Class<?>, String>(propertyClassDaoCallback);
|
||||
this.propertyDateValueCache = new EntityLookupCache<Long, Date, Date>(propertyDateValueCallback);
|
||||
this.propertyStringValueCache = new EntityLookupCache<Long, String, Pair<String, Long>>(propertyStringValueCallback);
|
||||
this.propertyDoubleValueCache = new EntityLookupCache<Long, Double, Double>(propertyDoubleValueCallback);
|
||||
this.propertyDateValueCache = new EntityLookupCache<Long, Date, Date>(propertyDateValueCallback);
|
||||
this.propertyValueCache = new EntityLookupCache<Long, Serializable, Serializable>(propertyValueCallback);
|
||||
}
|
||||
|
||||
@@ -137,6 +137,19 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
propertyClassDaoCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to use for <b>alf_prop_date_value</b> lookups (optional).
|
||||
*
|
||||
* @param propertyDateValueCache the cache of IDs to property values
|
||||
*/
|
||||
public void setPropertyDateValueCache(SimpleCache<Serializable, Object> propertyDateValueCache)
|
||||
{
|
||||
this.propertyDateValueCache = new EntityLookupCache<Long, Date, Date>(
|
||||
propertyDateValueCache,
|
||||
CACHE_REGION_PROPERTY_DATE_VALUE,
|
||||
propertyDateValueCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to use for <b>alf_prop_string_value</b> lookups (optional).
|
||||
*
|
||||
@@ -163,19 +176,6 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
propertyDoubleValueCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to use for <b>alf_prop_date_value</b> lookups (optional).
|
||||
*
|
||||
* @param propertyDateValueCache the cache of IDs to property values
|
||||
*/
|
||||
public void setPropertyDateValueCache(SimpleCache<Serializable, Object> propertyDateValueCache)
|
||||
{
|
||||
this.propertyDateValueCache = new EntityLookupCache<Long, Date, Date>(
|
||||
propertyDateValueCache,
|
||||
CACHE_REGION_PROPERTY_DATE_VALUE,
|
||||
propertyDateValueCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache to use for <b>alf_prop_value</b> lookups (optional).
|
||||
*
|
||||
@@ -272,6 +272,102 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
protected abstract PropertyClassEntity findClassByValue(Class<?> value);
|
||||
protected abstract PropertyClassEntity createClass(Class<?> value);
|
||||
|
||||
//================================
|
||||
// 'alf_prop_date_value' accessors
|
||||
//================================
|
||||
|
||||
public Pair<Long, Date> getPropertyDateValueById(Long id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot look up entity by null ID.");
|
||||
}
|
||||
Pair<Long, Date> entityPair = propertyDateValueCache.getByKey(id);
|
||||
if (entityPair == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("No property date value exists for ID " + id);
|
||||
}
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Date> getPropertyDateValue(Date value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted date values cannot be null");
|
||||
}
|
||||
value = PropertyDateValueEntity.truncateDate(value);
|
||||
Pair<Long, Date> entityPair = propertyDateValueCache.getByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Date> getOrCreatePropertyDateValue(Date value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted date values cannot be null");
|
||||
}
|
||||
value = PropertyDateValueEntity.truncateDate(value);
|
||||
Pair<Long, Date> entityPair = propertyDateValueCache.getOrCreateByValue(value);
|
||||
return (Pair<Long, Date>) entityPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for <b>alf_prop_date_value</b> DAO.
|
||||
*/
|
||||
private class PropertyDateValueCallbackDAO extends EntityLookupCallbackDAOAdaptor<Long, Date, Date>
|
||||
{
|
||||
private final Pair<Long, Date> convertEntityToPair(PropertyDateValueEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return entity.getEntityPair();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p/>
|
||||
* The value will already have been truncated to be accurate to the last day
|
||||
*/
|
||||
public Date getValueKey(Date value)
|
||||
{
|
||||
return PropertyDateValueEntity.truncateDate(value);
|
||||
}
|
||||
|
||||
public Pair<Long, Date> createValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity entity = createDateValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Date> findByKey(Long key)
|
||||
{
|
||||
PropertyDateValueEntity entity = findDateValueById(key);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Date> findByValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity entity = findDateValueByValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PropertyDateValueEntity findDateValueById(Long id);
|
||||
/**
|
||||
* @param value a date, accurate to the day
|
||||
*/
|
||||
protected abstract PropertyDateValueEntity findDateValueByValue(Date value);
|
||||
/**
|
||||
* @param value a date, accurate to the day
|
||||
*/
|
||||
protected abstract PropertyDateValueEntity createDateValue(Date value);
|
||||
|
||||
//================================
|
||||
// 'alf_prop_string_value' accessors
|
||||
//================================
|
||||
@@ -439,102 +535,6 @@ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO
|
||||
protected abstract PropertyDoubleValueEntity findDoubleValueByValue(Double value);
|
||||
protected abstract PropertyDoubleValueEntity createDoubleValue(Double value);
|
||||
|
||||
//================================
|
||||
// 'alf_prop_date_value' accessors
|
||||
//================================
|
||||
|
||||
public Pair<Long, Date> getPropertyDateValueById(Long id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot look up entity by null ID.");
|
||||
}
|
||||
Pair<Long, Date> entityPair = propertyDateValueCache.getByKey(id);
|
||||
if (entityPair == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("No property date value exists for ID " + id);
|
||||
}
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Date> getPropertyDateValue(Date value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted date values cannot be null");
|
||||
}
|
||||
value = PropertyDateValueEntity.truncateDate(value);
|
||||
Pair<Long, Date> entityPair = propertyDateValueCache.getByValue(value);
|
||||
return entityPair;
|
||||
}
|
||||
|
||||
public Pair<Long, Date> getOrCreatePropertyDateValue(Date value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Persisted double values cannot be null");
|
||||
}
|
||||
value = PropertyDateValueEntity.truncateDate(value);
|
||||
Pair<Long, Date> entityPair = propertyDateValueCache.getOrCreateByValue(value);
|
||||
return (Pair<Long, Date>) entityPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for <b>alf_prop_date_value</b> DAO.
|
||||
*/
|
||||
private class PropertyDateValueCallbackDAO extends EntityLookupCallbackDAOAdaptor<Long, Date, Date>
|
||||
{
|
||||
private final Pair<Long, Date> convertEntityToPair(PropertyDateValueEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return entity.getEntityPair();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p/>
|
||||
* The value will already have been truncated to have day-accuracy.
|
||||
*/
|
||||
public Date getValueKey(Date value)
|
||||
{
|
||||
return PropertyDateValueEntity.truncateDate(value);
|
||||
}
|
||||
|
||||
public Pair<Long, Date> createValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity entity = createDateValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Date> findByKey(Long key)
|
||||
{
|
||||
PropertyDateValueEntity entity = findDateValueById(key);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
|
||||
public Pair<Long, Date> findByValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity entity = findDateValueByValue(value);
|
||||
return convertEntityToPair(entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PropertyDateValueEntity findDateValueById(Long id);
|
||||
/**
|
||||
* @param value a date with day-accuracy
|
||||
*/
|
||||
protected abstract PropertyDateValueEntity findDateValueByValue(Date value);
|
||||
/**
|
||||
* @param value a date with day-accuracy
|
||||
*/
|
||||
protected abstract PropertyDateValueEntity createDateValue(Date value);
|
||||
|
||||
//================================
|
||||
// 'alf_prop_value' accessors
|
||||
//================================
|
||||
|
@@ -29,7 +29,6 @@ import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
@@ -62,7 +61,7 @@ public class PropertyDateValueEntity
|
||||
return dayOnlyDate;
|
||||
}
|
||||
|
||||
private Long dateValue;
|
||||
private long dateValue;
|
||||
private short fullYear;
|
||||
private short halfOfYear;
|
||||
private short quarterOfYear;
|
||||
@@ -80,7 +79,7 @@ public class PropertyDateValueEntity
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return (dateValue == null ? 0 : dateValue.hashCode());
|
||||
return (int) dateValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +92,7 @@ public class PropertyDateValueEntity
|
||||
else if (obj != null && obj instanceof PropertyDateValueEntity)
|
||||
{
|
||||
PropertyDateValueEntity that = (PropertyDateValueEntity) obj;
|
||||
return EqualsHelper.nullSafeEquals(this.dateValue, that.dateValue);
|
||||
return this.dateValue == that.dateValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -107,7 +106,7 @@ public class PropertyDateValueEntity
|
||||
StringBuilder sb = new StringBuilder(512);
|
||||
sb.append("PropertyDateValueEntity")
|
||||
.append("[ value=").append(dateValue)
|
||||
.append(" (").append(ISO8601DateFormat.format(new Date(dateValue.longValue()))).append(")")
|
||||
.append(" (").append(ISO8601DateFormat.format(new Date(dateValue))).append(")")
|
||||
.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -117,13 +116,13 @@ public class PropertyDateValueEntity
|
||||
*/
|
||||
public Pair<Long, Date> getEntityPair()
|
||||
{
|
||||
return new Pair<Long, Date>(dateValue, new Date(dateValue.longValue()));
|
||||
return new Pair<Long, Date>(dateValue, new Date(dateValue));
|
||||
}
|
||||
|
||||
public void setValue(Date value)
|
||||
{
|
||||
long valueInMs = value.getTime();
|
||||
this.dateValue = new Long(valueInMs);
|
||||
this.dateValue = valueInMs;
|
||||
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
@@ -142,12 +141,12 @@ public class PropertyDateValueEntity
|
||||
this.dayOfWeek = (short) cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
public Long getDateValue()
|
||||
public long getDateValue()
|
||||
{
|
||||
return dateValue;
|
||||
}
|
||||
|
||||
public void setDateValue(Long dateValue)
|
||||
public void setDateValue(long dateValue)
|
||||
{
|
||||
this.dateValue = dateValue;
|
||||
}
|
||||
|
@@ -56,6 +56,25 @@ public interface PropertyValueDAO
|
||||
*/
|
||||
Pair<Long, Class<?>> getOrCreatePropertyClass(Class<?> value);
|
||||
|
||||
/**
|
||||
* <b>alf_prop_date_value</b> accessor
|
||||
*
|
||||
* @param id the ID (may not be <tt>null</tt>)
|
||||
*/
|
||||
Pair<Long, Date> getPropertyDateValueById(Long id);
|
||||
/**
|
||||
* <b>alf_prop_date_value</b> accessor
|
||||
*
|
||||
* @param value the value to find the ID for (may not be <tt>null</tt>)
|
||||
*/
|
||||
Pair<Long, Date> getPropertyDateValue(Date value);
|
||||
/**
|
||||
* <b>alf_prop_date_value</b> accessor
|
||||
*
|
||||
* @param value the value to find the ID for (may not be <tt>null</tt>)
|
||||
*/
|
||||
Pair<Long, Date> getOrCreatePropertyDateValue(Date value);
|
||||
|
||||
/**
|
||||
* <b>alf_prop_string_value</b> accessor
|
||||
*
|
||||
@@ -94,25 +113,6 @@ public interface PropertyValueDAO
|
||||
*/
|
||||
Pair<Long, Double> getOrCreatePropertyDoubleValue(Double value);
|
||||
|
||||
/**
|
||||
* <b>alf_prop_date_value</b> accessor
|
||||
*
|
||||
* @param id the ID (may not be <tt>null</tt>)
|
||||
*/
|
||||
Pair<Long, Date> getPropertyDateValueById(Long id);
|
||||
/**
|
||||
* <b>alf_prop_date_value</b> accessor
|
||||
*
|
||||
* @param value the value to find the ID for (may not be <tt>null</tt>)
|
||||
*/
|
||||
Pair<Long, Date> getPropertyDateValue(Date value);
|
||||
/**
|
||||
* <b>alf_prop_date_value</b> accessor
|
||||
*
|
||||
* @param value the value to find the ID for (may not be <tt>null</tt>)
|
||||
*/
|
||||
Pair<Long, Date> getOrCreatePropertyDateValue(Date value);
|
||||
|
||||
/**
|
||||
* <b>alf_prop_value</b> accessor
|
||||
*
|
||||
|
@@ -26,6 +26,7 @@ package org.alfresco.repo.domain.propval;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -123,6 +124,35 @@ public class PropertyValueDAOTest extends TestCase
|
||||
txnHelper.doInTransaction(noHitCallback, false);
|
||||
}
|
||||
|
||||
public void testPropertyDateValue() throws Exception
|
||||
{
|
||||
final Date dateValue = ISO8601DateFormat.parse("1936-08-04T23:37:25.793Z");
|
||||
final Date dateValueBack = ISO8601DateFormat.parse("1936-08-04T00:00:00.000Z");
|
||||
RetryingTransactionCallback<Pair<Long, Date>> createValueCallback = new RetryingTransactionCallback<Pair<Long, Date>>()
|
||||
{
|
||||
public Pair<Long, Date> execute() throws Throwable
|
||||
{
|
||||
// Get the classes
|
||||
return propertyValueDAO.getOrCreatePropertyDateValue(dateValue);
|
||||
}
|
||||
};
|
||||
final Pair<Long, Date> entityPair = txnHelper.doInTransaction(createValueCallback, false);
|
||||
assertNotNull(entityPair);
|
||||
assertEquals(dateValueBack, entityPair.getSecond());
|
||||
|
||||
RetryingTransactionCallback<Pair<Long, Date>> getValueCallback = new RetryingTransactionCallback<Pair<Long, Date>>()
|
||||
{
|
||||
public Pair<Long, Date> execute() throws Throwable
|
||||
{
|
||||
// Get the classes
|
||||
return propertyValueDAO.getPropertyDateValue(dateValue);
|
||||
}
|
||||
};
|
||||
final Pair<Long, Date> entityPairCheck = txnHelper.doInTransaction(getValueCallback, false);
|
||||
assertNotNull(entityPairCheck);
|
||||
assertEquals(entityPair, entityPairCheck);
|
||||
}
|
||||
|
||||
public void testPropertyStringValue() throws Exception
|
||||
{
|
||||
final String stringValue = "One Two Three - " + System.currentTimeMillis();
|
||||
@@ -172,7 +202,7 @@ public class PropertyValueDAOTest extends TestCase
|
||||
assertEquals(stringValueUpper, stringUpperEntityPair.getSecond());
|
||||
assertNotSame("String IDs were not different", stringEntityPair.getFirst(), stringUpperEntityPair.getFirst());
|
||||
}
|
||||
|
||||
|
||||
public void testPropertyDoubleValue() throws Exception
|
||||
{
|
||||
final Double doubleValue = Double.valueOf(1.7976931348623E+308);
|
||||
@@ -200,36 +230,7 @@ public class PropertyValueDAOTest extends TestCase
|
||||
assertNotNull(entityPairCheck);
|
||||
assertEquals(entityPair, entityPairCheck);
|
||||
}
|
||||
|
||||
public void testPropertyDateValue() throws Exception
|
||||
{
|
||||
final Date dateValue = ISO8601DateFormat.parse("1936-08-04T23:37:25.793Z");
|
||||
final Date dateValueBack = ISO8601DateFormat.parse("1936-08-04T00:00:00.000Z");
|
||||
RetryingTransactionCallback<Pair<Long, Date>> createValueCallback = new RetryingTransactionCallback<Pair<Long, Date>>()
|
||||
{
|
||||
public Pair<Long, Date> execute() throws Throwable
|
||||
{
|
||||
// Get the classes
|
||||
return propertyValueDAO.getOrCreatePropertyDateValue(dateValue);
|
||||
}
|
||||
};
|
||||
final Pair<Long, Date> entityPair = txnHelper.doInTransaction(createValueCallback, false);
|
||||
assertNotNull(entityPair);
|
||||
assertEquals(dateValueBack, entityPair.getSecond());
|
||||
|
||||
RetryingTransactionCallback<Pair<Long, Date>> getValueCallback = new RetryingTransactionCallback<Pair<Long, Date>>()
|
||||
{
|
||||
public Pair<Long, Date> execute() throws Throwable
|
||||
{
|
||||
// Get the classes
|
||||
return propertyValueDAO.getPropertyDateValue(dateValue);
|
||||
}
|
||||
};
|
||||
final Pair<Long, Date> entityPairCheck = txnHelper.doInTransaction(getValueCallback, false);
|
||||
assertNotNull(entityPairCheck);
|
||||
assertEquals(entityPair, entityPairCheck);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the given value can be persisted and retrieved with the same resulting ID
|
||||
*/
|
||||
@@ -328,10 +329,10 @@ public class PropertyValueDAOTest extends TestCase
|
||||
|
||||
public void testPropertyValue_Date() throws Exception
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
for (long i = 0; i < 100; i++)
|
||||
Random rand = new Random();
|
||||
for (long i = 0; i < 1000; i++)
|
||||
{
|
||||
runPropertyValueTest(new Date(now + i));
|
||||
runPropertyValueTest(new Date(rand.nextLong()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,4 +343,37 @@ public class PropertyValueDAOTest extends TestCase
|
||||
runPropertyValueTest(new String("Value-" + i + ".xyz"));
|
||||
}
|
||||
}
|
||||
|
||||
private void removeCaches()
|
||||
{
|
||||
((AbstractPropertyValueDAOImpl)propertyValueDAO).setPropertyClassCache(null);
|
||||
((AbstractPropertyValueDAOImpl)propertyValueDAO).setPropertyDateValueCache(null);
|
||||
((AbstractPropertyValueDAOImpl)propertyValueDAO).setPropertyDoubleValueCache(null);
|
||||
((AbstractPropertyValueDAOImpl)propertyValueDAO).setPropertyStringValueCache(null);
|
||||
((AbstractPropertyValueDAOImpl)propertyValueDAO).setPropertyValueCache(null);
|
||||
}
|
||||
|
||||
public void testPropertyClass_NoCache() throws Exception
|
||||
{
|
||||
removeCaches();
|
||||
testPropertyClass();
|
||||
}
|
||||
|
||||
public void testPropertyDateValue_NoCache() throws Exception
|
||||
{
|
||||
removeCaches();
|
||||
testPropertyDateValue();
|
||||
}
|
||||
|
||||
public void testPropertyStringValue_NoCache() throws Exception
|
||||
{
|
||||
removeCaches();
|
||||
testPropertyStringValue();
|
||||
}
|
||||
|
||||
public void testPropertyDoubleValue_NoCache() throws Exception
|
||||
{
|
||||
removeCaches();
|
||||
testPropertyDoubleValue();
|
||||
}
|
||||
}
|
||||
|
@@ -50,6 +50,10 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
|
||||
private static final String SELECT_PROPERTY_CLASS_BY_NAME = "select.PropertyClassByName";
|
||||
private static final String INSERT_PROPERTY_CLASS = "insert.PropertyClass";
|
||||
|
||||
private static final String SELECT_PROPERTY_DATE_VALUE_BY_ID = "select.PropertyDateValueByID";
|
||||
private static final String SELECT_PROPERTY_DATE_VALUE_BY_VALUE = "select.PropertyDateValueByValue";
|
||||
private static final String INSERT_PROPERTY_DATE_VALUE = "insert.PropertyDateValue";
|
||||
|
||||
private static final String SELECT_PROPERTY_STRING_VALUE_BY_ID = "select.PropertyStringValueByID";
|
||||
private static final String SELECT_PROPERTY_STRING_VALUE_BY_VALUE = "select.PropertyStringValueByValue";
|
||||
private static final String INSERT_PROPERTY_STRING_VALUE = "insert.PropertyStringValue";
|
||||
@@ -58,10 +62,6 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
|
||||
private static final String SELECT_PROPERTY_DOUBLE_VALUE_BY_VALUE = "select.PropertyDoubleValueByValue";
|
||||
private static final String INSERT_PROPERTY_DOUBLE_VALUE = "insert.PropertyDoubleValue";
|
||||
|
||||
private static final String SELECT_PROPERTY_DATE_VALUE_BY_ID = "select.PropertyDateValueByID";
|
||||
private static final String SELECT_PROPERTY_DATE_VALUE_BY_VALUE = "select.PropertyDateValueByValue";
|
||||
private static final String INSERT_PROPERTY_DATE_VALUE = "insert.PropertyDateValue";
|
||||
|
||||
private static final String SELECT_PROPERTY_VALUE_BY_ID = "select.PropertyValueById";
|
||||
private static final String SELECT_PROPERTY_VALUE_BY_LOCAL_VALUE = "select.PropertyValueByLocalValue";
|
||||
private static final String SELECT_PROPERTY_VALUE_BY_DOUBLE_VALUE = "select.PropertyValueByDoubleValue";
|
||||
@@ -114,6 +114,40 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
|
||||
return entity;
|
||||
}
|
||||
|
||||
//================================
|
||||
// 'alf_prop_date_value' accessors
|
||||
//================================
|
||||
|
||||
@Override
|
||||
protected PropertyDateValueEntity findDateValueById(Long id)
|
||||
{
|
||||
PropertyDateValueEntity entity = (PropertyDateValueEntity) template.queryForObject(
|
||||
SELECT_PROPERTY_DATE_VALUE_BY_ID,
|
||||
id);
|
||||
// Done
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PropertyDateValueEntity findDateValueByValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity result = (PropertyDateValueEntity) template.queryForObject(
|
||||
SELECT_PROPERTY_DATE_VALUE_BY_VALUE,
|
||||
new Long(value.getTime()));
|
||||
// The ID is the actual time in ms (GMT)
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PropertyDateValueEntity createDateValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity entity = new PropertyDateValueEntity();
|
||||
entity.setValue(value);
|
||||
template.insert(INSERT_PROPERTY_DATE_VALUE, entity);
|
||||
// Done
|
||||
return entity;
|
||||
}
|
||||
|
||||
//================================
|
||||
// 'alf_prop_string_value' accessors
|
||||
//================================
|
||||
@@ -212,40 +246,6 @@ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl
|
||||
return entity;
|
||||
}
|
||||
|
||||
//================================
|
||||
// 'alf_prop_date_value' accessors
|
||||
//================================
|
||||
|
||||
@Override
|
||||
protected PropertyDateValueEntity findDateValueById(Long id)
|
||||
{
|
||||
PropertyDateValueEntity entity = (PropertyDateValueEntity) template.queryForObject(
|
||||
SELECT_PROPERTY_DATE_VALUE_BY_ID,
|
||||
id);
|
||||
// Done
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PropertyDateValueEntity findDateValueByValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity result = (PropertyDateValueEntity) template.queryForObject(
|
||||
SELECT_PROPERTY_DATE_VALUE_BY_VALUE,
|
||||
new Long(value.getTime()));
|
||||
// The ID is the actual time in ms (GMT)
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PropertyDateValueEntity createDateValue(Date value)
|
||||
{
|
||||
PropertyDateValueEntity entity = new PropertyDateValueEntity();
|
||||
entity.setValue(value);
|
||||
template.insert(INSERT_PROPERTY_DATE_VALUE, entity);
|
||||
// Done
|
||||
return entity;
|
||||
}
|
||||
|
||||
//================================
|
||||
// 'alf_prop_value' accessors
|
||||
//================================
|
||||
|
Reference in New Issue
Block a user