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:
Derek Hulley
2009-08-11 04:56:29 +00:00
parent aeef3a5af8
commit fe4d547316
8 changed files with 323 additions and 329 deletions

View File

@@ -49,9 +49,9 @@
<bean class="org.alfresco.repo.domain.propval.DefaultPropertyTypeConverter"/>
</property>
<property name="propertyClassCache" ref="immutableEntityCache"/>
<property name="propertyDateValueCache" ref="immutableEntityCache"/>
<property name="propertyStringValueCache" ref="immutableEntityCache"/>
<property name="propertyDoubleValueCache" ref="immutableEntityCache"/>
<property name="propertyDateValueCache" ref="immutableEntityCache"/>
<property name="propertyValueCache" ref="immutableEntityCache"/>
</bean>

View File

@@ -18,6 +18,22 @@ CREATE TABLE alf_prop_class
PRIMARY KEY (id)
) ENGINE=InnoDB;
CREATE TABLE alf_prop_date_value
(
date_value BIGINT NOT NULL,
full_year SMALLINT NOT NULL,
half_of_year TINYINT NOT NULL,
quarter_of_year TINYINT NOT NULL,
month_of_year TINYINT NOT NULL,
week_of_year TINYINT NOT NULL,
week_of_month TINYINT NOT NULL,
day_of_year SMALLINT NOT NULL,
day_of_month TINYINT NOT NULL,
day_of_week TINYINT NOT NULL,
INDEX idx_alf_prop_date_units (full_year, month_of_year, day_of_month),
PRIMARY KEY (date_value)
) ENGINE=InnoDB;
CREATE TABLE alf_prop_double_value
(
id BIGINT NOT NULL AUTO_INCREMENT,
@@ -41,42 +57,6 @@ CREATE TABLE alf_prop_serializable_value
PRIMARY KEY (id)
) ENGINE=InnoDB;
CREATE TABLE alf_prop_date_value
(
date_value BIGINT NOT NULL,
full_year SMALLINT NOT NULL,
half_of_year TINYINT NOT NULL,
quarter_of_year TINYINT NOT NULL,
month_of_year TINYINT NOT NULL,
week_of_year TINYINT NOT NULL,
week_of_month TINYINT NOT NULL,
day_of_year SMALLINT NOT NULL,
day_of_month TINYINT NOT NULL,
day_of_week TINYINT NOT NULL,
INDEX idx_alf_prop_date_val (date_value),
INDEX idx_alf_prop_date_fy (full_year),
INDEX idx_alf_prop_date_moy (month_of_year),
INDEX idx_alf_prop_date_doy (day_of_year),
INDEX idx_alf_prop_date_dom (day_of_month),
INDEX idx_alf_prop_date_dow (day_of_week),
PRIMARY KEY (date_value)
) ENGINE=InnoDB;
CREATE TABLE alf_prop_time_value
(
time_value BIGINT NOT NULL,
hour_of_day TINYINT NOT NULL,
minute_of_hour TINYINT NOT NULL,
second_of_minute TINYINT NOT NULL,
ms_of_second TINYINT NOT NULL,
INDEX idx_alf_prop_time_val (time_value),
INDEX idx_alf_prop_time_hod (hour_of_day),
INDEX idx_alf_prop_time_moh (minute_of_hour),
INDEX idx_alf_prop_time_som (second_of_minute),
INDEX idx_alf_prop_time_msos (ms_of_second),
PRIMARY KEY (time_value)
) ENGINE=InnoDB;
CREATE TABLE alf_prop_value
(
id BIGINT NOT NULL AUTO_INCREMENT,

View File

@@ -11,9 +11,9 @@
<!-- -->
<typeAlias alias="PropertyClass" type="org.alfresco.repo.domain.propval.PropertyClassEntity"/>
<typeAlias alias="PropertyDateValue" type="org.alfresco.repo.domain.propval.PropertyDateValueEntity"/>
<typeAlias alias="PropertyStringValue" type="org.alfresco.repo.domain.propval.PropertyStringValueEntity"/>
<typeAlias alias="PropertyDoubleValue" type="org.alfresco.repo.domain.propval.PropertyDoubleValueEntity"/>
<typeAlias alias="PropertyDateValue" type="org.alfresco.repo.domain.propval.PropertyDateValueEntity"/>
<typeAlias alias="PropertyValue" type="org.alfresco.repo.domain.propval.PropertyValueEntity"/>
<!-- -->
@@ -26,6 +26,19 @@
<result property="javaClassNameShort" column="java_class_name_short" jdbcType="VARCHAR" javaType="java.lang.String"/>
<result property="javaClassNameCrc" column="java_class_name_crc" jdbcType="BIGINT" javaType="java.lang.Long"/>
</resultMap>
<resultMap id="result.PropertyDateValue" class="PropertyDateValue">
<!-- date_value is the PK as well -->
<result property="dateValue" column="date_value" jdbcType="BIGINT" javaType="long"/>
<result property="fullYear" column="full_year" jdbcType="SMALLINT" javaType="short"/>
<result property="halfOfYear" column="half_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="quarterOfYear" column="quarter_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="monthOfYear" column="month_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="weekOfYear" column="week_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="weekOfMonth" column="week_of_month" jdbcType="TINYINT" javaType="short"/>
<result property="dayOfYear" column="day_of_year" jdbcType="SMALLINT" javaType="short"/>
<result property="dayOfMonth" column="day_of_month" jdbcType="TINYINT" javaType="short"/>
<result property="dayOfWeek" column="day_of_week" jdbcType="TINYINT" javaType="short"/>
</resultMap>
<resultMap id="result.PropertyStringValue" class="PropertyStringValue">
<result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="stringValue" column="string_value" jdbcType="VARCHAR" javaType="java.lang.String"/>
@@ -34,19 +47,6 @@
<result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="doubleValue" column="double_value" jdbcType="DOUBLE" javaType="java.lang.Double"/>
</resultMap>
<resultMap id="result.PropertyDateValue" class="PropertyDateValue">
<!-- date_value is the PK as well -->
<result property="dateValue" column="date_value" jdbcType="BIGINT" javaType="long"/>
<result property="fullYear" column="full_year" jdbcType="TINYINT" javaType="short"/>
<result property="halfOfYear" column="half_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="quarterOfYear" column="quarter_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="monthOfYear" column="month_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="weekOfYear" column="week_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="weekOfMonth" column="week_of_month" jdbcType="TINYINT" javaType="short"/>
<result property="dayOfYear" column="day_of_year" jdbcType="TINYINT" javaType="short"/>
<result property="dayOfMonth" column="day_of_month" jdbcType="TINYINT" javaType="short"/>
<result property="dayOfWeek" column="day_of_week" jdbcType="TINYINT" javaType="short"/>
</resultMap>
<resultMap id="result.PropertyValue" class="PropertyValue">
<result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="actualTypeId" column="actual_type_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
@@ -90,25 +90,6 @@
values (#doubleValue#)
</sql>
<sql id="insert.PropertyDateValue">
insert into alf_prop_date_value
(
date_value,
full_year, half_of_year, quarter_of_year,
month_of_year,
week_of_year, week_of_month,
day_of_year, day_of_month, day_of_week
)
values
(
#dateValue#,
#fullYear#, #halfOfYear#, #quarterOfYear#,
#monthOfYear#,
#weekOfYear#, #weekOfMonth#,
#dayOfYear#, #dayOfMonth#, #dayOfWeek#
)
</sql>
<sql id="insert.PropertyValue.AutoIncrement">
insert into alf_prop_value (actual_type_id, persisted_type, long_value)
values (#actualTypeId#, #persistedType#, #longValue#)
@@ -139,6 +120,45 @@
java_class_name_short = #javaClassNameShort#
</select>
<insert id="insert.PropertyDateValue" parameterClass="PropertyDateValue" >
insert into alf_prop_date_value
(
date_value,
full_year, half_of_year, quarter_of_year,
month_of_year,
week_of_year, week_of_month,
day_of_year, day_of_month, day_of_week
)
values
(
#dateValue#,
#fullYear#, #halfOfYear#, #quarterOfYear#,
#monthOfYear#,
#weekOfYear#, #weekOfMonth#,
#dayOfYear#, #dayOfMonth#, #dayOfWeek#
)
</insert>
<!-- Get a property date value by ID -->
<select id="select.PropertyDateValueByID" parameterClass="java.lang.Long" resultMap="result.PropertyDateValue">
select
*
from
alf_prop_date_value
where
date_value = #dateValue#
</select>
<!-- Get the property date value by value -->
<select id="select.PropertyDateValueByValue" parameterClass="java.lang.Long" resultMap="result.PropertyDateValue">
select
*
from
alf_prop_date_value
where
date_value = #dateValue#
</select>
<!-- Get a property string value by ID -->
<select id="select.PropertyStringValueByID" parameterClass="PropertyStringValue" resultMap="result.PropertyStringValue">
select
@@ -179,45 +199,6 @@
double_value = #doubleValue#
</select>
<insert id="insert.PropertyDateValue" parameterClass="PropertyDateValue" >
insert into alf_prop_date_value
(
date_value,
full_year, half_of_year, quarter_of_year,
month_of_year,
week_of_year, week_of_month,
day_of_year, day_of_month, day_of_week
)
values
(
#dateValue#,
#fullYear#, #halfOfYear#, #quarterOfYear#,
#monthOfYear#,
#weekOfYear#, #weekOfMonth#,
#dayOfYear#, #dayOfMonth#, #dayOfWeek#
)
</insert>
<!-- Get a property date value by ID -->
<select id="select.PropertyDateValueByID" parameterClass="java.lang.Long" resultMap="result.PropertyDateValue">
select
*
from
alf_prop_date_value
where
id = #dateValue#
</select>
<!-- Get the property date value by value -->
<select id="select.PropertyDateValueByValue" parameterClass="java.lang.Long" resultMap="result.PropertyDateValue">
select
*
from
alf_prop_date_value
where
date_value = #dateValue#
</select>
<!-- Get the property value by value in alf_prop_value -->
<select id="select.PropertyValueByLocalValue" parameterClass="PropertyValue" resultMap="result.PropertyValue">
select

View File

@@ -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
//================================

View File

@@ -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;
}

View File

@@ -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
*

View File

@@ -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();
@@ -201,35 +231,6 @@ public class PropertyValueDAOTest extends TestCase
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();
}
}

View File

@@ -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
//================================