mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
added some more functions
This commit is contained in:
parent
39129cc070
commit
0890d647ee
@ -26,22 +26,6 @@ public class HqlGrammar extends Grammar{
|
||||
return new CountExpr(expr);
|
||||
}
|
||||
|
||||
public static <D extends Comparable<D>> ExprNoEntity<D> distinct(ExprNoEntity<D> left){
|
||||
return _comparable(OpHql.DISTINCT, left);
|
||||
}
|
||||
|
||||
public static <A> Expr<A> newInstance(Class<A> a, Expr<?>... args){
|
||||
return new Constructor<A>(a,args);
|
||||
}
|
||||
|
||||
public static <D extends Comparable<D>> ExprComparable<D> sum(Expr<D> left){
|
||||
return _number(OpHql.SUM, left);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> sysdate(){
|
||||
return _comparable(OpHql.SYSDATE);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> current_date(){
|
||||
return _comparable(OpHql.CURRENT_DATE);
|
||||
}
|
||||
@ -53,7 +37,61 @@ public class HqlGrammar extends Grammar{
|
||||
public static ExprComparable<Date> current_timestamp(){
|
||||
return _comparable(OpHql.CURRENT_TIMESTAMP);
|
||||
}
|
||||
public static ExprComparable<Date> day(Expr<Date> date){
|
||||
return _comparable(OpHql.DAY, date);
|
||||
}
|
||||
|
||||
public static <D extends Comparable<D>> ExprNoEntity<D> distinct(ExprNoEntity<D> left){
|
||||
return _comparable(OpHql.DISTINCT, left);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> hour(Expr<Date> date){
|
||||
return _comparable(OpHql.HOUR, date);
|
||||
}
|
||||
|
||||
public static ExprComparable<Integer> maxindex(PathEntityCollection<?> collection) {
|
||||
return _comparable(OpHql.MAXINDEX, collection);
|
||||
}
|
||||
|
||||
public static ExprComparable<Integer> minindex(PathEntityCollection<?> collection) {
|
||||
return _comparable(OpHql.MININDEX, collection);
|
||||
}
|
||||
|
||||
public static ExprBoolean isempty(PathEntityCollection<?> collection) {
|
||||
return _boolean(OpHql.ISEMPTY, collection);
|
||||
}
|
||||
|
||||
public static ExprBoolean isnotempty(PathEntityCollection<?> collection) {
|
||||
return _boolean(OpHql.ISNOTEMPTY, collection);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> minute(Expr<Date> date){
|
||||
return _comparable(OpHql.MINUTE, date);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> month(Expr<Date> date){
|
||||
return _comparable(OpHql.MONTH, date);
|
||||
}
|
||||
|
||||
public static <A> Expr<A> newInstance(Class<A> a, Expr<?>... args){
|
||||
return new Constructor<A>(a,args);
|
||||
}
|
||||
public static ExprComparable<Date> second(Expr<Date> date){
|
||||
return _comparable(OpHql.SECOND, date);
|
||||
}
|
||||
|
||||
public static <D extends Comparable<D>> ExprComparable<D> sum(Expr<D> left){
|
||||
return _number(OpHql.SUM, left);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> sysdate(){
|
||||
return _comparable(OpHql.SYSDATE);
|
||||
}
|
||||
|
||||
public static ExprComparable<Date> year(Expr<Date> date){
|
||||
return _comparable(OpHql.YEAR, date);
|
||||
}
|
||||
|
||||
public static class Constructor<D> extends Expr<D>{
|
||||
public final Expr<?>[] args;
|
||||
public Constructor(Class<D> type, Expr<?>... args){
|
||||
|
||||
@ -9,6 +9,8 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mysema.query.grammar.Ops.Op;
|
||||
|
||||
/**
|
||||
* Ops provides
|
||||
*
|
||||
@ -68,6 +70,12 @@ public class HqlOps extends Ops {
|
||||
patterns.put(OpHql.CURRENT_DATE, "current_date()");
|
||||
patterns.put(OpHql.CURRENT_TIME, "current_time()");
|
||||
patterns.put(OpHql.CURRENT_TIMESTAMP, "current_timestamp()");
|
||||
patterns.put(OpHql.SECOND, "second(%s)");
|
||||
patterns.put(OpHql.MINUTE, "minute(%s)");
|
||||
patterns.put(OpHql.HOUR, "hour(%s)");
|
||||
patterns.put(OpHql.DAY, "day(%s)");
|
||||
patterns.put(OpHql.MONTH, "month(%s)");
|
||||
patterns.put(OpHql.YEAR, "year(%s)");
|
||||
}
|
||||
|
||||
public static String getPattern(Op<?> op){
|
||||
@ -81,6 +89,16 @@ public class HqlOps extends Ops {
|
||||
Op<Comparable<?>> DISTINCT = new OpImpl<Comparable<?>>();
|
||||
Op<Number> SUM = new OpImpl<Number>();
|
||||
Op<Date> SYSDATE = new OpImpl<Date>();
|
||||
Op<Date> SECOND = new OpImpl<Date>();
|
||||
Op<Date> MINUTE = new OpImpl<Date>();
|
||||
Op<Date> HOUR = new OpImpl<Date>();
|
||||
Op<Date> DAY = new OpImpl<Date>();
|
||||
Op<Date> MONTH = new OpImpl<Date>();
|
||||
Op<Date> YEAR = new OpImpl<Date>();
|
||||
Op<Object> MAXINDEX = new OpImpl<Object>();
|
||||
Op<Object> MININDEX = new OpImpl<Object>();
|
||||
Op<Boolean> ISNOTEMPTY = new OpImpl<Boolean>();
|
||||
Op<Boolean> ISEMPTY = new OpImpl<Boolean>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ import com.mysema.query.grammar.HqlQueryBase;
|
||||
import com.mysema.query.grammar.HqlSerializer;
|
||||
import com.mysema.query.grammar.HqlGrammar.Constructor;
|
||||
import com.mysema.query.grammar.Types.Expr;
|
||||
import com.mysema.query.grammar.Types.PathEntityCollection;
|
||||
import com.mysema.query.grammar.hql.domain.Cat;
|
||||
|
||||
/**
|
||||
* FeaturesTest provides
|
||||
@ -86,13 +88,13 @@ public class FeaturesTest extends HqlQueryBase<FeaturesTest>{
|
||||
@Test
|
||||
public void testCollectionOperations(){
|
||||
// HQL functions that take collection-valued path expressions: size(), minelement(), maxelement(), minindex(), maxindex(), along with the special elements() and indices functions which may be quantified using some, all, exists, any, in.
|
||||
// size(cat.kittens());
|
||||
// minelement(cat.kittens());
|
||||
// maxelement(cat.kittens());
|
||||
// minindex(cat.kittens());
|
||||
// maxindex(cat.kittens());
|
||||
// size(cat.kittens);
|
||||
// minelement(cat.kittens);
|
||||
// maxelement(cat.kittens);
|
||||
minindex(cat.kittens);
|
||||
maxindex(cat.kittens);
|
||||
toString("cat.kittens[0]",cat.kittens(0));
|
||||
toString("cat.kittens[0]",cat.kittens.get(0));
|
||||
toString("cat.kittens[0]",cat.kittens.get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -119,12 +121,12 @@ public class FeaturesTest extends HqlQueryBase<FeaturesTest>{
|
||||
@Test
|
||||
public void testDateOperations2(){
|
||||
// second(...), minute(...), hour(...), day(...), month(...), year(...),
|
||||
// second(catalog.effectiveDate);
|
||||
// minute(catalog.effectiveDate);
|
||||
// hour(catalog.effectiveDate);
|
||||
// day(catalog.effectiveDate);
|
||||
// month(catalog.effectiveDate);
|
||||
// year(catalog.effectiveDate);
|
||||
second(catalog.effectiveDate);
|
||||
minute(catalog.effectiveDate);
|
||||
hour(catalog.effectiveDate);
|
||||
day(catalog.effectiveDate);
|
||||
month(catalog.effectiveDate);
|
||||
year(catalog.effectiveDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -174,8 +176,8 @@ public class FeaturesTest extends HqlQueryBase<FeaturesTest>{
|
||||
kitten.bodyWeight.between(10, 20);
|
||||
kitten.bodyWeight.isnull();
|
||||
kitten.bodyWeight.isnotnull();
|
||||
// cat.kittens.isEmpty();
|
||||
// cat.kittens.isNotEmpty();
|
||||
isempty(cat.kittens);
|
||||
isnotempty(cat.kittens);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user