added support for Joda time types via the QComparable library

This commit is contained in:
Timo Westkämper 2009-04-20 13:15:27 +00:00
parent 9abb5ca381
commit acf57e95ea
2 changed files with 73 additions and 19 deletions

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2008 Mysema Ltd.
* All rights reserved.
*
*/
package com.mysema.query.grammar;
import com.mysema.query.grammar.types.Expr;
import com.mysema.query.grammar.types.SimpleExprFactory;
import com.mysema.query.grammar.types.Expr.EBoolean;
/**
* QComparable provides helper methods to construct comparison expressions for types
* that don't implement Comparable in generic fashion such as Joda time types
*
* @author tiwe
* @version $Id$
*/
public class QComparable {
protected static final SimpleExprFactory factory = new SimpleExprFactory();
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean before(Expr<A> left, A right) {
return factory.createBoolean(Ops.BEFORE, left, factory.createConstant(right));
}
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean before(Expr<A> left, Expr<A> right) {
return factory.createBoolean(Ops.BEFORE, left, right);
}
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean after(Expr<A> left, A right) {
return factory.createBoolean(Ops.AFTER, left, factory.createConstant(right));
}
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean after(Expr<A> left, Expr<A> right) {
return factory.createBoolean(Ops.AFTER, left, right);
}
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean boe(Expr<A> left,A right) {
return factory.createBoolean(Ops.BOE, left, factory.createConstant(right));
}
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean boe(Expr<A> left, Expr<A> right) {
return factory.createBoolean(Ops.BOE, left, right);
}
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean aoe(Expr<A> left, A right) {
return factory.createBoolean(Ops.AOE, left, factory.createConstant(right));
}
@SuppressWarnings("unchecked")
public static <A extends Comparable> EBoolean aoe(Expr<A> left, Expr<A> right) {
return factory.createBoolean(Ops.AOE, left, right);
}
}

View File

@ -19,42 +19,37 @@ import com.mysema.query.grammar.types.Expr.ENumber;
* @author tiwe
* @version $Id$
*/
// TODO : provide Joda Time variant ?!?
public class QDateTime{
private static final SimpleExprFactory factory = new SimpleExprFactory();
public static EComparable<Date> currentDate() {
return factory.createComparable(Date.class, Ops.OpDateTime.CURRENT_DATE);
}
public static EComparable<Date> currentTime() {
return factory.createComparable(Date.class, Ops.OpDateTime.CURRENT_DATE);
return factory.createComparable(Date.class, Ops.OpDateTime.CURRENT_DATE);
}
public static ENumber<Integer> dayOfMonth(Expr<Date> d) {
return factory.createNumber(Integer.class, Ops.OpDateTime.DAY_OF_MONTH, d);
return factory.createNumber(Integer.class, Ops.OpDateTime.DAY_OF_MONTH, d);
}
public static ENumber<Integer> dayOfWeek(Expr<Date> d) {
return factory.createNumber(Integer.class, Ops.OpDateTime.DAY_OF_WEEK, d);
return factory.createNumber(Integer.class, Ops.OpDateTime.DAY_OF_WEEK, d);
}
public static ENumber<Integer> dayOfYear(Expr<Date> d) {
return factory.createNumber(Integer.class, Ops.OpDateTime.DAY_OF_YEAR, d);
return factory.createNumber(Integer.class, Ops.OpDateTime.DAY_OF_YEAR, d);
}
public static ENumber<Integer> hour(Expr<Time> t) {
return factory.createNumber(Integer.class, Ops.OpDateTime.HOUR, t);
return factory.createNumber(Integer.class, Ops.OpDateTime.HOUR, t);
}
public static ENumber<Integer> minute(Expr<Time> t) {
return factory.createNumber(Integer.class, Ops.OpDateTime.MINUTE, t);
return factory.createNumber(Integer.class, Ops.OpDateTime.MINUTE, t);
}
public static ENumber<Integer> year(Expr<Date> d) {
@ -62,8 +57,7 @@ public class QDateTime{
}
public static ENumber<Integer> week(Expr<Date> d) {
return factory.createNumber(Integer.class, Ops.OpDateTime.WEEK, d);
return factory.createNumber(Integer.class, Ops.OpDateTime.WEEK, d);
}
public static ENumber<Integer> second(Expr<Time> t) {
@ -71,13 +65,11 @@ public class QDateTime{
}
public static EComparable<Date> now() {
return factory.createComparable(Date.class, Ops.OpDateTime.CURRENT_TIME);
return factory.createComparable(Date.class, Ops.OpDateTime.CURRENT_TIME);
}
public static ENumber<Integer> month(Expr<Date> d) {
return factory.createNumber(Integer.class, Ops.OpDateTime.MONTH, d);
return factory.createNumber(Integer.class, Ops.OpDateTime.MONTH, d);
}
}