|
|
@ -32,23 +32,39 @@ public class Criteria { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static final Object NOT_SET = new Object(); |
|
|
|
private static final Object NOT_SET = new Object(); |
|
|
|
|
|
|
|
|
|
|
|
private String key; |
|
|
|
private enum CriteriaType { |
|
|
|
|
|
|
|
GT, |
|
|
|
|
|
|
|
GTE, |
|
|
|
|
|
|
|
LT, |
|
|
|
|
|
|
|
LTE, |
|
|
|
|
|
|
|
NE, |
|
|
|
|
|
|
|
IN, |
|
|
|
|
|
|
|
NIN, |
|
|
|
|
|
|
|
ALL, |
|
|
|
|
|
|
|
SIZE, |
|
|
|
|
|
|
|
EXISTS, |
|
|
|
|
|
|
|
TYPE, |
|
|
|
|
|
|
|
REGEX, |
|
|
|
|
|
|
|
OR |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String key; |
|
|
|
|
|
|
|
|
|
|
|
private List<Criteria> criteriaChain; |
|
|
|
private final List<Criteria> criteriaChain; |
|
|
|
|
|
|
|
|
|
|
|
private LinkedHashMap<String, Object> criteria = new LinkedHashMap<String, Object>(); |
|
|
|
private final LinkedHashMap<CriteriaType, Object> criteria = new LinkedHashMap<CriteriaType, Object>(); |
|
|
|
|
|
|
|
|
|
|
|
private Object isValue = NOT_SET; |
|
|
|
private Object isValue = NOT_SET; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Criteria(String key) { |
|
|
|
private Criteria(String key) { |
|
|
|
notEmpty(key, "key can not be null or empty"); |
|
|
|
notEmpty(key, "key can not be null or empty"); |
|
|
|
this.criteriaChain = new ArrayList<Criteria>(); |
|
|
|
this.criteriaChain = new ArrayList<Criteria>(); |
|
|
|
this.criteriaChain.add(this); |
|
|
|
this.criteriaChain.add(this); |
|
|
|
this.key = key; |
|
|
|
this.key = key; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Criteria(List<Criteria> criteriaChain, String key) { |
|
|
|
private Criteria(List<Criteria> criteriaChain, String key) { |
|
|
|
notEmpty(key, "key can not be null or empty"); |
|
|
|
notEmpty(key, "key can not be null or empty"); |
|
|
|
this.criteriaChain = criteriaChain; |
|
|
|
this.criteriaChain = criteriaChain; |
|
|
|
this.criteriaChain.add(this); |
|
|
|
this.criteriaChain.add(this); |
|
|
@ -59,14 +75,20 @@ public class Criteria { |
|
|
|
return this.key; |
|
|
|
return this.key; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean apply(Map<String, Object> map) { |
|
|
|
/** |
|
|
|
|
|
|
|
* Checks if this criteria matches the given map |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param map map to check |
|
|
|
|
|
|
|
* @return true if criteria is a match |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean matches(Map<String, Object> map) { |
|
|
|
|
|
|
|
|
|
|
|
if (this.criteriaChain.size() == 1) { |
|
|
|
if (this.criteriaChain.size() == 1) { |
|
|
|
return criteriaChain.get(0).singleObjectApply(map); |
|
|
|
return criteriaChain.get(0).singleObjectApply(map); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
for (Criteria c : this.criteriaChain) { |
|
|
|
for (Criteria c : this.criteriaChain) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(""); |
|
|
|
if (!c.singleObjectApply(map)) { |
|
|
|
if (!c.singleObjectApply(map)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -75,21 +97,17 @@ public class Criteria { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected boolean singleObjectApply(Map<String, Object> map) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean not = false; |
|
|
|
|
|
|
|
for (String key : this.criteria.keySet()) { |
|
|
|
|
|
|
|
Object expectedVal = null; |
|
|
|
boolean singleObjectApply(Map<String, Object> map) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CriteriaType key : this.criteria.keySet()) { |
|
|
|
|
|
|
|
|
|
|
|
Object actualVal = map.get(this.key); |
|
|
|
Object actualVal = map.get(this.key); |
|
|
|
if (not) { |
|
|
|
Object expectedVal = this.criteria.get(key); |
|
|
|
expectedVal = this.criteria.get(key); |
|
|
|
|
|
|
|
not = false; |
|
|
|
if (CriteriaType.GT.equals(key)) { |
|
|
|
} else { |
|
|
|
|
|
|
|
if ("$not".equals(key)) { |
|
|
|
|
|
|
|
not = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
expectedVal = this.criteria.get(key); |
|
|
|
|
|
|
|
if ("$gt".equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -100,7 +118,7 @@ public class Criteria { |
|
|
|
|
|
|
|
|
|
|
|
return (actualNumber.doubleValue() > expectedNumber.doubleValue()); |
|
|
|
return (actualNumber.doubleValue() > expectedNumber.doubleValue()); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$gte".equals(key)) { |
|
|
|
} else if (CriteriaType.GTE.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -111,7 +129,7 @@ public class Criteria { |
|
|
|
|
|
|
|
|
|
|
|
return (actualNumber.doubleValue() >= expectedNumber.doubleValue()); |
|
|
|
return (actualNumber.doubleValue() >= expectedNumber.doubleValue()); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$lt".equals(key)) { |
|
|
|
} else if (CriteriaType.LT.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -122,7 +140,7 @@ public class Criteria { |
|
|
|
|
|
|
|
|
|
|
|
return (actualNumber.doubleValue() < expectedNumber.doubleValue()); |
|
|
|
return (actualNumber.doubleValue() < expectedNumber.doubleValue()); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$lte".equals(key)) { |
|
|
|
} else if (CriteriaType.LTE.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
if (expectedVal == null || actualVal == null) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -133,49 +151,49 @@ public class Criteria { |
|
|
|
|
|
|
|
|
|
|
|
return (actualNumber.doubleValue() <= expectedNumber.doubleValue()); |
|
|
|
return (actualNumber.doubleValue() <= expectedNumber.doubleValue()); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$ne".equals(key)) { |
|
|
|
} else if (CriteriaType.NE.equals(key)) { |
|
|
|
if (expectedVal == null && actualVal == null) { |
|
|
|
if (expectedVal == null && actualVal == null) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (expectedVal == null) { |
|
|
|
if (expectedVal == null) { |
|
|
|
return !(actualVal == null); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
return !expectedVal.equals(actualVal); |
|
|
|
return !expectedVal.equals(actualVal); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$in".equals(key)) { |
|
|
|
} else if (CriteriaType.IN.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
Collection exp = (Collection) expectedVal; |
|
|
|
Collection exp = (Collection) expectedVal; |
|
|
|
|
|
|
|
|
|
|
|
return exp.contains(actualVal); |
|
|
|
return exp.contains(actualVal); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$nin".equals(key)) { |
|
|
|
} else if (CriteriaType.NIN.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
Collection exp = (Collection) expectedVal; |
|
|
|
Collection exp = (Collection) expectedVal; |
|
|
|
|
|
|
|
|
|
|
|
return !exp.contains(actualVal); |
|
|
|
return !exp.contains(actualVal); |
|
|
|
} else if ("$all".equals(key)) { |
|
|
|
} else if (CriteriaType.ALL.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
Collection exp = (Collection) expectedVal; |
|
|
|
Collection exp = (Collection) expectedVal; |
|
|
|
Collection act = (Collection) actualVal; |
|
|
|
Collection act = (Collection) actualVal; |
|
|
|
|
|
|
|
|
|
|
|
return act.containsAll(exp); |
|
|
|
return act.containsAll(exp); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$size".equals(key)) { |
|
|
|
} else if (CriteriaType.SIZE.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
int exp = (Integer) expectedVal; |
|
|
|
int exp = (Integer) expectedVal; |
|
|
|
List act = (List) actualVal; |
|
|
|
List act = (List) actualVal; |
|
|
|
|
|
|
|
|
|
|
|
return (act.size() == exp); |
|
|
|
return (act.size() == exp); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$exists".equals(key)) { |
|
|
|
} else if (CriteriaType.EXISTS.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
boolean exp = (Boolean) expectedVal; |
|
|
|
boolean exp = (Boolean) expectedVal; |
|
|
|
boolean act = map.containsKey(this.key); |
|
|
|
boolean act = map.containsKey(this.key); |
|
|
|
|
|
|
|
|
|
|
|
return act == exp; |
|
|
|
return act == exp; |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$type".equals(key)) { |
|
|
|
} else if (CriteriaType.TYPE.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
Class<?> exp = (Class<?>) expectedVal; |
|
|
|
Class<?> exp = (Class<?>) expectedVal; |
|
|
|
Class<?> act = null; |
|
|
|
Class<?> act = null; |
|
|
@ -191,35 +209,41 @@ public class Criteria { |
|
|
|
return act.equals(exp); |
|
|
|
return act.equals(exp); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$regex".equals(key)) { |
|
|
|
} else if (CriteriaType.REGEX.equals(key)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pattern exp = (Pattern) expectedVal; |
|
|
|
Pattern exp = (Pattern) expectedVal; |
|
|
|
String act = (String) actualVal; |
|
|
|
String act = (String) actualVal; |
|
|
|
if(act == null){ |
|
|
|
if (act == null) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return exp.matcher(act).matches(); |
|
|
|
return exp.matcher(act).matches(); |
|
|
|
|
|
|
|
|
|
|
|
} else if ("$or".equals(key)) { |
|
|
|
} else { |
|
|
|
|
|
|
|
throw new UnsupportedOperationException("Criteria type not supported: " + key.name()); |
|
|
|
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException("Or not supported yet"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isValue != NOT_SET) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isValue instanceof Collection) { |
|
|
|
|
|
|
|
Collection<Criteria> cs = (Collection<Criteria>) isValue; |
|
|
|
|
|
|
|
for (Criteria crit : cs) { |
|
|
|
|
|
|
|
for (Criteria c : crit.criteriaChain) { |
|
|
|
|
|
|
|
if (!c.singleObjectApply(map)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (isValue != NOT_SET) { |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isValue == null) { |
|
|
|
if (isValue == null) { |
|
|
|
return (map.get(key) == null); |
|
|
|
return (map.get(key) == null); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return isValue.equals(map.get(key)); |
|
|
|
return isValue.equals(map.get(key)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -230,8 +254,8 @@ public class Criteria { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Static factory method to create a Criteria using the provided key |
|
|
|
* Static factory method to create a Criteria using the provided key |
|
|
|
* |
|
|
|
* |
|
|
|
* @param key |
|
|
|
* @param key filed name |
|
|
|
* @return |
|
|
|
* @return the new criteria |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public static Criteria where(String key) { |
|
|
|
public static Criteria where(String key) { |
|
|
@ -241,7 +265,8 @@ public class Criteria { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Static factory method to create a Criteria using the provided key |
|
|
|
* Static factory method to create a Criteria using the provided key |
|
|
|
* |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @param key ads new filed to criteria |
|
|
|
|
|
|
|
* @return the criteria builder |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria and(String key) { |
|
|
|
public Criteria and(String key) { |
|
|
|
return new Criteria(this.criteriaChain, key); |
|
|
|
return new Criteria(this.criteriaChain, key); |
|
|
@ -264,6 +289,7 @@ public class Criteria { |
|
|
|
this.isValue = o; |
|
|
|
this.isValue = o; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using equality |
|
|
|
* Creates a criterion using equality |
|
|
|
* |
|
|
|
* |
|
|
@ -275,62 +301,63 @@ public class Criteria { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $ne operator |
|
|
|
* Creates a criterion using the <b>!=</b> operator |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o |
|
|
|
* @param o |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria ne(Object o) { |
|
|
|
public Criteria ne(Object o) { |
|
|
|
criteria.put("$ne", o); |
|
|
|
criteria.put(CriteriaType.NE, o); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $lt operator |
|
|
|
* Creates a criterion using the <b><</b> operator |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o |
|
|
|
* @param o |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria lt(Object o) { |
|
|
|
public Criteria lt(Object o) { |
|
|
|
criteria.put("$lt", o); |
|
|
|
criteria.put(CriteriaType.LT, o); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $lte operator |
|
|
|
* Creates a criterion using the <b><=</b> operator |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o |
|
|
|
* @param o |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria lte(Object o) { |
|
|
|
public Criteria lte(Object o) { |
|
|
|
criteria.put("$lte", o); |
|
|
|
criteria.put(CriteriaType.LTE, o); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $gt operator |
|
|
|
* Creates a criterion using the <b>></b> operator |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o |
|
|
|
* @param o |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria gt(Object o) { |
|
|
|
public Criteria gt(Object o) { |
|
|
|
criteria.put("$gt", o); |
|
|
|
criteria.put(CriteriaType.GT, o); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $gte operator |
|
|
|
* Creates a criterion using the <b>>=</b> operator |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o |
|
|
|
* @param o |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria gte(Object o) { |
|
|
|
public Criteria gte(Object o) { |
|
|
|
criteria.put("$gte", o); |
|
|
|
criteria.put(CriteriaType.GTE, o); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $in operator |
|
|
|
* The <code>in</code> operator is analogous to the SQL IN modifier, allowing you |
|
|
|
|
|
|
|
* to specify an array of possible matches. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o the values to match against |
|
|
|
* @param o the values to match against |
|
|
|
* @return |
|
|
|
* @return |
|
|
@ -344,35 +371,45 @@ public class Criteria { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $in operator |
|
|
|
* The <code>in</code> operator is analogous to the SQL IN modifier, allowing you |
|
|
|
|
|
|
|
* to specify an array of possible matches. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param c the collection containing the values to match against |
|
|
|
* @param c the collection containing the values to match against |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria in(Collection<?> c) { |
|
|
|
public Criteria in(Collection<?> c) { |
|
|
|
criteria.put("$in", c); |
|
|
|
notNull(c, "collection can not be null"); |
|
|
|
|
|
|
|
criteria.put(CriteriaType.IN, c); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $nin operator |
|
|
|
* The <code>nin</code> operator is similar to $in except that it selects objects for |
|
|
|
|
|
|
|
* which the specified field does not have any value in the specified array. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o |
|
|
|
* @param o the values to match against |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria nin(Object... o) { |
|
|
|
public Criteria nin(Object... o) { |
|
|
|
return nin(Arrays.asList(o)); |
|
|
|
return nin(Arrays.asList(o)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Criteria nin(Collection<?> o) { |
|
|
|
/** |
|
|
|
notNull(o, "collection can not be null"); |
|
|
|
* The <code>nin</code> operator is similar to $in except that it selects objects for |
|
|
|
criteria.put("$nin", o); |
|
|
|
* which the specified field does not have any value in the specified array. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param c the values to match against |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Criteria nin(Collection<?> c) { |
|
|
|
|
|
|
|
notNull(c, "collection can not be null"); |
|
|
|
|
|
|
|
criteria.put(CriteriaType.NIN, c); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $all operator |
|
|
|
* The <code>all</code> operator is similar to $in, but instead of matching any value in the specified array all values in the array must be matched. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param o |
|
|
|
* @param o |
|
|
|
* @return |
|
|
|
* @return |
|
|
@ -380,94 +417,77 @@ public class Criteria { |
|
|
|
public Criteria all(Object... o) { |
|
|
|
public Criteria all(Object... o) { |
|
|
|
return all(Arrays.asList(o)); |
|
|
|
return all(Arrays.asList(o)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
public Criteria all(Collection<?> o) { |
|
|
|
* The <code>all</code> operator is similar to $in, but instead of matching any value in the specified array all values in the array must be matched. |
|
|
|
criteria.put("$all", o); |
|
|
|
* |
|
|
|
|
|
|
|
* @param c |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Criteria all(Collection<?> c) { |
|
|
|
|
|
|
|
notNull(c, "collection can not be null"); |
|
|
|
|
|
|
|
criteria.put(CriteriaType.ALL, c); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $size operator |
|
|
|
* The <code>size</code> operator matches any array with the specified number of elements. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param s |
|
|
|
* @param s |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria size(int s) { |
|
|
|
public Criteria size(int s) { |
|
|
|
criteria.put("$size", s); |
|
|
|
criteria.put(CriteriaType.SIZE, s); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $exists operator |
|
|
|
* Check for existence (or lack thereof) of a field. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param b |
|
|
|
* @param b |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria exists(boolean b) { |
|
|
|
public Criteria exists(boolean b) { |
|
|
|
criteria.put("$exists", b); |
|
|
|
criteria.put(CriteriaType.EXISTS, b); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using the $type operator |
|
|
|
* The $type operator matches values based on their Java type. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param t |
|
|
|
* @param t |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria type(Class<?> t) { |
|
|
|
public Criteria type(Class<?> t) { |
|
|
|
criteria.put("$type", t); |
|
|
|
notNull(t, "type can not be null"); |
|
|
|
return this; |
|
|
|
criteria.put(CriteriaType.TYPE, t); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a criterion using the $not meta operator which affects the clause directly following |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Criteria not() { |
|
|
|
|
|
|
|
criteria.put("$not", null); |
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a criterion using a $regex and $options |
|
|
|
* Creates a criterion using a Regex |
|
|
|
* |
|
|
|
* |
|
|
|
* @param pattern |
|
|
|
* @param pattern |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Criteria regex(Pattern pattern) { |
|
|
|
public Criteria regex(Pattern pattern) { |
|
|
|
criteria.put("$regex", pattern); |
|
|
|
notNull(pattern, "pattern can not be null"); |
|
|
|
|
|
|
|
criteria.put(CriteriaType.REGEX, pattern); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a criterion using the $mod operator |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param value |
|
|
|
|
|
|
|
* @param remainder |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
public Criteria mod(Number value, Number remainder) { |
|
|
|
|
|
|
|
List<Object> l = new ArrayList<Object>(); |
|
|
|
|
|
|
|
l.add(value); |
|
|
|
|
|
|
|
l.add(remainder); |
|
|
|
|
|
|
|
criteria.put("$mod", l); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates an 'or' criteria using the $or operator for all of the provided criteria |
|
|
|
* Creates an 'or' criteria using the $or operator for all of the provided criteria |
|
|
|
* |
|
|
|
* |
|
|
|
* @param criteria |
|
|
|
* @param criteria |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
/* |
|
|
|
public Criteria orOperator(Criteria... criteria) { |
|
|
|
public Criteria orOperator(Criteria... criteria) { |
|
|
|
criteriaChain.add(new Criteria("$or").is(asList(criteria))); |
|
|
|
criteriaChain.add(new Criteria("$or").is(asList(criteria))); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a 'nor' criteria using the $nor operator for all of the provided criteria |
|
|
|
* Creates a 'nor' criteria using the $nor operator for all of the provided criteria |
|
|
|