mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
This commit is contained in:
parent
1c628f0723
commit
e4a8ecdee8
@ -139,6 +139,10 @@ public abstract class OperationPatterns {
|
||||
add(Ops.OpString.LTRIM, "ltrim(%s)");
|
||||
add(Ops.OpString.RTRIM, "rtrim(%s)");
|
||||
add(Ops.OpString.SPACE, "space(%s)");
|
||||
|
||||
// collection
|
||||
add(Ops.CONTAINS_KEY, "containsKey(%s,%s)");
|
||||
add(Ops.CONTAINS_VALUE, "containsValue(%s,%s)");
|
||||
|
||||
// path types
|
||||
for (PathType type : new PathType[] { PathMetadata.LISTVALUE,
|
||||
|
||||
@ -23,6 +23,7 @@ import com.mysema.query.types.operation.Ops.OpNumberAgg;
|
||||
import com.mysema.query.types.path.PCollection;
|
||||
import com.mysema.query.types.path.PEntity;
|
||||
import com.mysema.query.types.path.PEntityCollection;
|
||||
import com.mysema.query.types.path.PMap;
|
||||
|
||||
/**
|
||||
* Grammar provides the factory methods for the fluent grammar.
|
||||
@ -38,9 +39,6 @@ public class Grammar {
|
||||
protected static final OperationFactory operationFactory = SimpleOperationFactory
|
||||
.getInstance();
|
||||
|
||||
protected Grammar() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Expr : left > right
|
||||
*
|
||||
@ -54,20 +52,7 @@ public class Grammar {
|
||||
// types
|
||||
return operationFactory.createBoolean(Ops.AFTER, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left >= right (after or equals)
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<?>> EBoolean aoe(Expr<A> left, A right) {
|
||||
return operationFactory.createBoolean(Ops.AOE, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Expr : left > right
|
||||
@ -84,7 +69,31 @@ public class Grammar {
|
||||
// types
|
||||
return operationFactory.createBoolean(Ops.AFTER, left, right);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expr : left and right
|
||||
*
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static EBoolean and(EBoolean left, EBoolean right) {
|
||||
return operationFactory.createBoolean(Ops.AND, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left >= right (after or equals)
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<?>> EBoolean aoe(Expr<A> left, A right) {
|
||||
return operationFactory.createBoolean(Ops.AOE, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left >= right
|
||||
*
|
||||
@ -97,18 +106,7 @@ public class Grammar {
|
||||
Expr<A> right) {
|
||||
return operationFactory.createBoolean(Ops.AOE, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left and right
|
||||
*
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static EBoolean and(EBoolean left, EBoolean right) {
|
||||
return operationFactory.createBoolean(Ops.AND, left, right);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expr : from as to
|
||||
*
|
||||
@ -188,19 +186,6 @@ public class Grammar {
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left <= right (before or equals)
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<?>> EBoolean boe(Expr<A> left, A right) {
|
||||
return operationFactory.createBoolean(Ops.BOE, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left < right
|
||||
*
|
||||
@ -211,25 +196,11 @@ public class Grammar {
|
||||
*/
|
||||
public static <A extends Comparable<?>> EBoolean before(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
// NOTE : signature is for Comparables to support other than Java's date
|
||||
// types
|
||||
// NOTE : signature is for Comparables to support other than Java's date types
|
||||
// NOTE : basically same as lt
|
||||
return operationFactory.createBoolean(Ops.BEFORE, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left <= right
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<?>> EBoolean boe(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
return operationFactory.createBoolean(Ops.BOE, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left between start and end
|
||||
*
|
||||
@ -259,6 +230,32 @@ public class Grammar {
|
||||
return operationFactory.createBoolean(Ops.BETWEEN, left, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left <= right (before or equals)
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<?>> EBoolean boe(Expr<A> left, A right) {
|
||||
return operationFactory.createBoolean(Ops.BOE, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left <= right
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A extends Comparable<?>> EBoolean boe(Expr<A> left,
|
||||
Expr<A> right) {
|
||||
return operationFactory.createBoolean(Ops.BOE, left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left.chartAt(right)
|
||||
*
|
||||
@ -330,6 +327,50 @@ public class Grammar {
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <K>
|
||||
* @param path
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static <K> EBoolean containsKey(PMap<K,?> path, Expr<K> key){
|
||||
return operationFactory.createBoolean(Ops.CONTAINS_KEY, (Expr<?>)path, key);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <K>
|
||||
* @param path
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static <K> EBoolean containsKey(PMap<K,?> path, K key){
|
||||
return operationFactory.createBoolean(Ops.CONTAINS_KEY, (Expr<?>)path, exprFactory.createConstant(key));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <V>
|
||||
* @param path
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <V> EBoolean containsValue(PMap<?,V> path, Expr<V> value){
|
||||
return operationFactory.createBoolean(Ops.CONTAINS_VALUE, (Expr<?>)path, value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <V>
|
||||
* @param path
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static <V> EBoolean containsValue(PMap<?,V> path, V value){
|
||||
return operationFactory.createBoolean(Ops.CONTAINS_VALUE, (Expr<?>)path, exprFactory.createConstant(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : count(*)
|
||||
*
|
||||
@ -371,11 +412,6 @@ public class Grammar {
|
||||
(Expr<?>) collection);
|
||||
}
|
||||
|
||||
public static EBoolean notEmpty(PCollection<?> collection) {
|
||||
return operationFactory.createBoolean(Ops.COL_ISNOTEMPTY,
|
||||
(Expr<?>) collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left.endsWith(right)
|
||||
*
|
||||
@ -556,19 +592,6 @@ public class Grammar {
|
||||
.createConstant(left), (Expr<?>) right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left in right OR right contains left
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A> EBoolean in(Expr<A> left, Collection<? extends A> right) {
|
||||
return operationFactory.createBoolean(Ops.IN, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left in rest OR rest contains left
|
||||
*
|
||||
@ -582,6 +605,19 @@ public class Grammar {
|
||||
.createConstant(rest));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left in right OR right contains left
|
||||
*
|
||||
* @param <A>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A> EBoolean in(Expr<A> left, Collection<? extends A> right) {
|
||||
return operationFactory.createBoolean(Ops.IN, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left in right OR right contains left
|
||||
*
|
||||
@ -633,6 +669,21 @@ public class Grammar {
|
||||
.createConstant(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left instanceOf right
|
||||
*
|
||||
* @param <A>
|
||||
* @param <B>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A, B extends A> EBoolean instanceOf(Expr<A> left,
|
||||
Class<B> right) {
|
||||
return operationFactory.createBoolean(Ops.ISTYPEOF, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left.isEmpty()
|
||||
*
|
||||
@ -899,6 +950,11 @@ public class Grammar {
|
||||
return operationFactory.createBoolean(Ops.NOTBETWEEN, left, start, end);
|
||||
}
|
||||
|
||||
public static EBoolean notEmpty(PCollection<?> collection) {
|
||||
return operationFactory.createBoolean(Ops.COL_ISNOTEMPTY,
|
||||
(Expr<?>) collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left not in rest
|
||||
*
|
||||
@ -945,16 +1001,6 @@ public class Grammar {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : cast(source as String)
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static EString stringCast(EComparable<?> source) {
|
||||
return operationFactory.createString(Ops.STRING_CAST, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left or right
|
||||
*
|
||||
@ -1035,6 +1081,16 @@ public class Grammar {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : cast(source as String)
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public static EString stringCast(EComparable<?> source) {
|
||||
return operationFactory.createString(Ops.STRING_CAST, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left.substring(right)
|
||||
*
|
||||
@ -1072,21 +1128,6 @@ public class Grammar {
|
||||
return operationFactory.createString(Ops.TRIM, left);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left instanceOf right
|
||||
*
|
||||
* @param <A>
|
||||
* @param <B>
|
||||
* @param left
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
public static <A, B extends A> EBoolean instanceOf(Expr<A> left,
|
||||
Class<B> right) {
|
||||
return operationFactory.createBoolean(Ops.ISTYPEOF, left, exprFactory
|
||||
.createConstant(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expr : left.toUpperCase()
|
||||
*
|
||||
@ -1096,4 +1137,7 @@ public class Grammar {
|
||||
public static EString upper(Expr<String> left) {
|
||||
return operationFactory.createString(Ops.UPPER, left);
|
||||
}
|
||||
|
||||
protected Grammar() {
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ import java.util.List;
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Ops {
|
||||
|
||||
|
||||
static List<Class<?>> Boolean_x_2 = unmodifiableList(Arrays.<Class<?>> asList(Boolean.class, Boolean.class));
|
||||
|
||||
static List<Class<?>> Comparable_x_2 = unmodifiableList(Arrays.<Class<?>> asList(Comparable.class, Comparable.class));
|
||||
@ -122,6 +122,8 @@ public interface Ops {
|
||||
Op<Boolean> ENDSWITH = new Op<Boolean>(String_x_2);
|
||||
Op<Boolean> ENDSWITH_IC = new Op<Boolean>(String_x_2);
|
||||
Op<Boolean> CONTAINS = new Op<Boolean>(String_x_2);
|
||||
Op<Boolean> CONTAINS_KEY = new Op<Boolean>(Object_x_2);
|
||||
Op<Boolean> CONTAINS_VALUE = new Op<Boolean>(Object_x_2);
|
||||
|
||||
// subquery operations
|
||||
Op<Boolean> EXISTS = new Op<Boolean>(Object.class);
|
||||
|
||||
@ -83,4 +83,24 @@ public class PComponentMap<K, V> extends ESimple<java.util.Map<K, V>> implements
|
||||
return o instanceof Path ? ((Path<?>) o).getMetadata().equals(metadata)
|
||||
: false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsKey(Expr<K> key) {
|
||||
return Grammar.containsKey(this, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsKey(K key) {
|
||||
return Grammar.containsKey(this, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsValue(Expr<V> value) {
|
||||
return Grammar.containsValue(this, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsValue(V value) {
|
||||
return Grammar.containsValue(this, value);
|
||||
}
|
||||
}
|
||||
@ -88,4 +88,24 @@ public class PEntityMap<K, V> extends Expr<Map<K, V>> implements PMap<K, V> {
|
||||
return o instanceof Path ? ((Path<?>) o).getMetadata().equals(metadata)
|
||||
: false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsKey(Expr<K> key) {
|
||||
return Grammar.containsKey(this, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsKey(K key) {
|
||||
return Grammar.containsKey(this, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsValue(Expr<V> value) {
|
||||
return Grammar.containsValue(this, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EBoolean containsValue(V value) {
|
||||
return Grammar.containsValue(this, value);
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package com.mysema.query.types.path;
|
||||
|
||||
import com.mysema.query.types.expr.EBoolean;
|
||||
import com.mysema.query.types.expr.Expr;
|
||||
|
||||
/**
|
||||
@ -21,4 +22,12 @@ public interface PMap<K, V> extends Path<java.util.Map<K, V>> {
|
||||
Class<K> getKeyType();
|
||||
|
||||
Class<V> getValueType();
|
||||
|
||||
EBoolean containsKey(Expr<K> key);
|
||||
|
||||
EBoolean containsKey(K key);
|
||||
|
||||
EBoolean containsValue(Expr<V> value);
|
||||
|
||||
EBoolean containsValue(V value);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user