added some lazy inits to Expr types

This commit is contained in:
Timo Westkämper 2009-10-10 09:06:00 +00:00
parent 0e220e92fc
commit 572d63818c
20 changed files with 184 additions and 210 deletions

View File

@ -8,11 +8,18 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* @author tiwe
*
*/
@Documented
@Target({FIELD,METHOD})
@Retention(RUNTIME)
public @interface QueryInit {
/**
* @return
*/
String[] value();
}

View File

@ -21,16 +21,38 @@ import com.mysema.query.types.operation.Ops;
@SuppressWarnings({"unchecked","serial"})
public abstract class EDate<D extends Comparable> extends EDateOrTime<D> {
private volatile ENumber<Integer> dayOfMonth, month, year;
private static final EDate<Date> currentDate = currentDate(Date.class);
public static EDate<java.sql.Date> create(java.sql.Date date){
return new EDateConst(date);
}
/**
* Get an expression representing the current date as a EDate instance
*
* @return
*/
public static EDate<Date> currentDate() {
return currentDate;
}
/**
* Get an expression representing the current date as a EDate instance
*
* @return
*/
public static <T extends Comparable> EDate<T> currentDate(Class<T> cl) {
return ODate.create(cl, Ops.DateTimeOps.CURRENT_DATE);
}
private volatile ENumber<Integer> dayOfMonth, dayOfWeek, dayOfYear;
private volatile ENumber<Integer> week, month, year;
public EDate(Class<? extends D> type) {
super(type);
}
/**
* Create a day of month expression (range 1-31)
*
@ -42,6 +64,32 @@ public abstract class EDate<D extends Comparable> extends EDateOrTime<D> {
}
return dayOfMonth;
}
/**
* Create a day of week expression (range 1-7 / SUN-SAT)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfWeek() {
if (dayOfWeek == null){
dayOfWeek = ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_WEEK, this);
}
return dayOfWeek;
}
/**
* Create a day of year expression (range 1-356)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfYear() {
if (dayOfYear == null){
dayOfYear = ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_YEAR, this);
}
return dayOfYear;
}
/**
* Create a month expression (range 1-12)
@ -55,6 +103,18 @@ public abstract class EDate<D extends Comparable> extends EDateOrTime<D> {
return month;
}
/**
* Create a week expression
*
* @return
*/
public ENumber<Integer> getWeek() {
if (week == null){
week = ONumber.create(Integer.class, Ops.DateTimeOps.WEEK, this);
}
return week;
}
/**
* Create a year expression
*
@ -66,51 +126,4 @@ public abstract class EDate<D extends Comparable> extends EDateOrTime<D> {
}
return year;
}
/**
* Create a day of week expression (range 1-7 / SUN-SAT)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfWeek() {
return ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_WEEK, this);
}
/**
* Create a day of year expression (range 1-356)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfYear() {
return ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_YEAR, this);
}
/**
* Create a week expression
*
* @return
*/
public ENumber<Integer> getWeek() {
return ONumber.create(Integer.class, Ops.DateTimeOps.WEEK, this);
}
/**
* Get an expression representing the current date as a EDate instance
*
* @return
*/
public static EDate<Date> currentDate() {
return currentDate(Date.class);
}
/**
* Get an expression representing the current date as a EDate instance
*
* @return
*/
public static <T extends Comparable> EDate<T> currentDate(Class<T> cl) {
return ODate.create(cl, Ops.DateTimeOps.CURRENT_DATE);
}
}

View File

@ -21,12 +21,54 @@ import com.mysema.query.types.operation.Ops;
@SuppressWarnings({"unchecked","serial"})
public abstract class EDateTime<D extends Comparable> extends EDateOrTime<D> {
private volatile ENumber<Integer> dayOfMonth, month, year, hours, minutes, seconds, milliseconds;
private static final EDateTime<Date> currentDate = currentDate(Date.class);
private static final EDateTime<Date> currentTimestamp = currentTimestamp(Date.class);
public static EDateTime<java.util.Date> create(java.util.Date date){
return new EDateTimeConst(date);
}
/**
* Get an expression representing the current date as a EDateTime instance
*
* @return
*/
public static EDateTime<Date> currentDate() {
return currentDate;
}
/**
* Get an expression representing the current date as a EDateTime instance
*
* @return
*/
public static <T extends Comparable> EDateTime<T> currentDate(Class<T> cl) {
return ODateTime.create(cl, Ops.DateTimeOps.CURRENT_DATE);
}
/**
* Get an expression representing the current time instant as a EDateTime instance
*
* @return
*/
public static EDateTime<Date> currentTimestamp() {
return currentTimestamp;
}
/**
* Get an expression representing the current time instant as a EDateTime instance
*
* @return
*/
public static <T extends Comparable> EDateTime<T> currentTimestamp(Class<T> cl) {
return ODateTime.create(cl, Ops.DateTimeOps.CURRENT_TIMESTAMP);
}
private volatile ENumber<Integer> dayOfMonth, dayOfWeek, dayOfYear;
private volatile ENumber<Integer> year, month, week, hours, minutes, seconds, milliseconds;
public EDateTime(Class<? extends D> type) {
super(type);
}
@ -43,6 +85,32 @@ public abstract class EDateTime<D extends Comparable> extends EDateOrTime<D> {
return dayOfMonth;
}
/**
* Create a day of week expression (range 1-7 / SUN-SAT)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfWeek() {
if (dayOfWeek == null){
dayOfWeek = ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_WEEK, this);
}
return dayOfWeek;
}
/**
* Create a day of year expression (range 1-356)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfYear() {
if (dayOfYear == null){
dayOfYear = ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_YEAR, this);
}
return dayOfYear;
}
/**
* Create a hours expression (range 0-23)
*
@ -55,6 +123,19 @@ public abstract class EDateTime<D extends Comparable> extends EDateOrTime<D> {
return hours;
}
/**
* Create a milliseconds expression (range 0-999)
* <p>Is always 0 in HQL and JDOQL modules</p>
*
* @return
*/
public ENumber<Integer> getMilliSecond(){
if (milliseconds == null){
milliseconds = ONumber.create(Integer.class, Ops.DateTimeOps.MILLISECOND, this);
}
return milliseconds;
}
/**
* Create a minutes expression (range 0-59)
*
@ -66,7 +147,7 @@ public abstract class EDateTime<D extends Comparable> extends EDateOrTime<D> {
}
return minutes;
}
/**
* Create a month expression (range 1-12)
*
@ -90,18 +171,18 @@ public abstract class EDateTime<D extends Comparable> extends EDateOrTime<D> {
}
return seconds;
}
/**
* Create a milliseconds expression (range 0-999)
* <p>Is always 0 in HQL and JDOQL modules</p>
* Create a week expression
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getMilliSecond(){
if (milliseconds == null){
milliseconds = ONumber.create(Integer.class, Ops.DateTimeOps.MILLISECOND, this);
public ENumber<Integer> getWeek() {
if (week == null){
week = ONumber.create(Integer.class, Ops.DateTimeOps.WEEK, this);
}
return milliseconds;
return week;
}
/**
@ -115,70 +196,4 @@ public abstract class EDateTime<D extends Comparable> extends EDateOrTime<D> {
}
return year;
}
/**
* Create a day of week expression (range 1-7 / SUN-SAT)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfWeek() {
return ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_WEEK, this);
}
/**
* Create a day of year expression (range 1-356)
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getDayOfYear() {
return ONumber.create(Integer.class, Ops.DateTimeOps.DAY_OF_YEAR, this);
}
/**
* Create a week expression
* <p>NOT supported in JDOQL and not in Derby</p>
*
* @return
*/
public ENumber<Integer> getWeek() {
return ONumber.create(Integer.class, Ops.DateTimeOps.WEEK, this);
}
/**
* Get an expression representing the current date as a EDateTime instance
*
* @return
*/
public static EDateTime<Date> currentDate() {
return currentDate(Date.class);
}
/**
* Get an expression representing the current time instant as a EDateTime instance
*
* @return
*/
public static EDateTime<Date> currentTimestamp() {
return currentTimestamp(Date.class);
}
/**
* Get an expression representing the current date as a EDateTime instance
*
* @return
*/
public static <T extends Comparable> EDateTime<T> currentDate(Class<T> cl) {
return ODateTime.create(cl, Ops.DateTimeOps.CURRENT_DATE);
}
/**
* Get an expression representing the current time instant as a EDateTime instance
*
* @return
*/
public static <T extends Comparable> EDateTime<T> currentTimestamp(Class<T> cl) {
return ODateTime.create(cl, Ops.DateTimeOps.CURRENT_TIMESTAMP);
}
}

View File

@ -26,7 +26,7 @@ import com.mysema.query.types.operation.Ops.MathOps;
@SuppressWarnings("serial")
public abstract class ENumber<D extends Number & Comparable<?>> extends EComparableBase<D> {
private static ENumber<Double> random;
private static final ENumber<Double> random = ONumber.create(Double.class, MathOps.RANDOM);
/**
* Factory method
@ -59,17 +59,14 @@ public abstract class ENumber<D extends Number & Comparable<?>> extends ECompara
* @return random()
*/
public static ENumber<Double> random(){
if (random == null){
random = ONumber.create(Double.class, MathOps.RANDOM);
}
return random;
}
private ENumber<D> abs, sum, min, max;
private volatile ENumber<D> abs, sum, min, max;
private ENumber<Double> avg, sqrt;
private volatile ENumber<Double> avg, sqrt;
private ENumber<D> round, floor, ceil;
private volatile ENumber<D> round, floor, ceil;
public ENumber(Class<? extends D> type) {
super(type);

View File

@ -222,42 +222,6 @@ public abstract class EString extends EComparable<String> {
return isEmpty().not();
}
// /**
// * Expr : <code>this.lastIndexOf(right, third);</code>
// * <p>NOT supported in JDOQL, HQL and SQL</p>
// *
// * @param right
// * @param third
// * @return this.lastIndexOf(right, third)
// * @see java.lang.String#lastIndexOf(String, int)
// */
// public ENumber<Integer> lastIndex(String right, int third) {
// return ONumber.create(Integer.class, Ops.StringOps.LAST_INDEX_2ARGS, this, EString.create(right), ENumber.create(third));
// }
//
// /**
// * Expr : <code>this.lastIndexOf(right)</code>
// * <p>NOT supported in JDOQL, HQL and SQL</p>
// *
// * @param right
// * @return this.lastIndexOf(right)
// * @see java.lang.String#lastIndexOf(String)
// */
// public ENumber<Integer> lastIndexOf(Expr<String> right) {
// return ONumber.create(Integer.class, Ops.StringOps.LAST_INDEX, this, right);
// }
//
// /**
// * Expr : <code>this.lastIndexOf(right)</code>
// * <p>NOT supported in JDOQL, HQL and SQL</p>
// *
// * @param right
// * @return this.lastIndexOf(right)
// * @see java.lang.String#lastIndexOf(String)
// */
// public ENumber<Integer> lastIndexOf(String right) {
// return ONumber.create(Integer.class, Ops.StringOps.LAST_INDEX, this, EString.create(right));
// }
/**
* @return this.length()

View File

@ -31,11 +31,11 @@ public abstract class PArray<D> extends Expr<D[]> implements Path<D[]>{
protected final Class<D> componentType;
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;
private ENumber<Integer> size;
private volatile ENumber<Integer> size;
private final Path<?> root;

View File

@ -7,7 +7,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.util.NotEmpty;
@ -22,7 +21,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings("serial")
public class PBoolean extends EBoolean implements Path<Boolean> {
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -8,7 +8,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EComparable;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.util.NotEmpty;
@ -25,7 +24,7 @@ import com.mysema.query.util.NotEmpty;
public class PComparable<D extends Comparable> extends EComparable<D> implements
Path<D> {
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -31,7 +31,7 @@ public class PComponentCollection<D> extends ECollectionBase<D> implements PColl
private final PathMetadata<?> metadata;
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
@SuppressWarnings("unchecked")
public PComponentCollection(Class<D> type, PathMetadata<?> metadata) {

View File

@ -34,7 +34,7 @@ public class PComponentMap<K, V> extends EMapBase<K, V> implements PMap<K, V> {
private final Path<?> root;
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
@SuppressWarnings("unchecked")
public PComponentMap(Class<K> keyType, Class<V> valueType,

View File

@ -8,7 +8,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EDate;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.util.NotEmpty;
@ -21,7 +20,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings({"unchecked","serial"})
public class PDate<D extends Comparable> extends EDate<D> implements Path<D>{
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -8,7 +8,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EDateTime;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.util.NotEmpty;
@ -21,7 +20,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings({"unchecked","serial"})
public class PDateTime<D extends Comparable> extends EDateTime<D> implements Path<D> {
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -5,14 +5,10 @@
*/
package com.mysema.query.types.path;
import java.lang.reflect.InvocationTargetException;
import com.mysema.commons.lang.Assert;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EDateTime;
import com.mysema.query.types.expr.ExprConst;
import com.mysema.query.types.expr.EEntity;
import com.mysema.query.types.expr.ExprConst;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
import com.mysema.query.util.NotEmpty;
@ -29,7 +25,7 @@ public class PEntity<D> extends EEntity<D> implements Path<D> {
private final String entityName;
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -10,11 +10,10 @@ import java.util.Collection;
import com.mysema.commons.lang.Assert;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EDateTime;
import com.mysema.query.types.expr.ExprConst;
import com.mysema.query.types.expr.EEntity;
import com.mysema.query.types.expr.ENumber;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.expr.ExprConst;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.ONumber;
import com.mysema.query.types.operation.Ops;
@ -36,16 +35,12 @@ public class PEntityCollection<D> extends EEntity<java.util.Collection<D>> imple
protected final String entityName;
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull, empty;
private ENumber<Integer> size;
private volatile ENumber<Integer> size;
private final Path<?> root;
private EBoolean empty;
private EBoolean notEmpty;
@SuppressWarnings("unchecked")
public PEntityCollection(Class<D> type, @NotEmpty String entityName, PathMetadata<?> metadata) {
super((Class)Collection.class);
@ -123,10 +118,7 @@ public class PEntityCollection<D> extends EEntity<java.util.Collection<D>> imple
@Override
public EBoolean isNotEmpty() {
if (notEmpty == null){
notEmpty = isEmpty().not();
}
return notEmpty;
return isEmpty().not();
}
@Override

View File

@ -32,15 +32,13 @@ public class PEntityList<D> extends PEntityCollection<D> implements PList<D> {
@Override
public PEntity<D> get(Expr<Integer> index) {
return new PEntity<D>(elementType, entityName, PathMetadata.forListAccess(
this, index));
return new PEntity<D>(elementType, entityName, PathMetadata.forListAccess(this, index));
}
@Override
public PEntity<D> get(int index) {
// TODO : cache
return new PEntity<D>(elementType, entityName, PathMetadata.forListAccess(
this, index));
return new PEntity<D>(elementType, entityName, PathMetadata.forListAccess(this, index));
}
}

View File

@ -26,7 +26,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings("serial")
public class PEntityMap<K, V> extends EMapBase<K, V> implements PMap<K, V> {
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final Class<K> keyType;

View File

@ -7,7 +7,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EMapBase;
import com.mysema.query.types.expr.ENumber;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
@ -23,7 +22,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings("serial")
public class PNumber<D extends Number & Comparable<?>> extends ENumber<D> implements Path<D> {
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -7,7 +7,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EMapBase;
import com.mysema.query.types.expr.Expr;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
@ -23,7 +22,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings("serial")
public class PSimple<D> extends Expr<D> implements Path<D> {
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -7,7 +7,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EMapBase;
import com.mysema.query.types.expr.EString;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
@ -22,7 +21,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings("serial")
public class PString extends EString implements Path<String> {
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;

View File

@ -7,7 +7,6 @@ package com.mysema.query.types.path;
import com.mysema.query.types.Visitor;
import com.mysema.query.types.expr.EBoolean;
import com.mysema.query.types.expr.EMapBase;
import com.mysema.query.types.expr.ETime;
import com.mysema.query.types.operation.OBoolean;
import com.mysema.query.types.operation.Ops;
@ -21,7 +20,7 @@ import com.mysema.query.util.NotEmpty;
@SuppressWarnings({"unchecked","serial"})
public class PTime<D extends Comparable> extends ETime<D> implements Path<D>{
private EBoolean isnull, isnotnull;
private volatile EBoolean isnull, isnotnull;
private final PathMetadata<?> metadata;