diff options
author | Sotaro SUZUKI <sotaro.suzuki@architector.jp> | 2014-10-01 16:17:34 +0900 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-10-06 10:22:39 -0400 |
commit | 48da60f625b53dccbc4a34737eba55eb0eda181b (patch) | |
tree | 0b048e6247ce0ec196df7015c8fa77bf36e062a0 /src/main/java/com/iciql/QueryWhere.java | |
parent | 8ba3b92816e65acc0d1d71ba23259deed616eefe (diff) | |
download | iciql-48da60f625b53dccbc4a34737eba55eb0eda181b.tar.gz iciql-48da60f625b53dccbc4a34737eba55eb0eda181b.zip |
add support stackable condition: ex. X and (Y or Z)
see samples in
src/test/java/com/iciql/test/StackableConditionsTest.java
Diffstat (limited to 'src/main/java/com/iciql/QueryWhere.java')
-rw-r--r-- | src/main/java/com/iciql/QueryWhere.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main/java/com/iciql/QueryWhere.java b/src/main/java/com/iciql/QueryWhere.java index 5baa5ab..5ea8bdb 100644 --- a/src/main/java/com/iciql/QueryWhere.java +++ b/src/main/java/com/iciql/QueryWhere.java @@ -19,6 +19,9 @@ package com.iciql; import java.util.List;
+import com.iciql.Conditions.And;
+import com.iciql.Conditions.Or;
+
/**
* This class represents a query with a condition.
*
@@ -135,6 +138,26 @@ public class QueryWhere<T> { return new QueryCondition<T, A>(query, x);
}
+ public QueryWhere<T> and(And<T> conditions) {
+ andOpenTrue();
+ query.addConditionToken(conditions.where.query);
+ return close();
+ }
+
+ public QueryWhere<T> and(Or<T> conditions) {
+ andOpenFalse();
+ query.addConditionToken(conditions.where.query);
+ return close();
+ }
+
+ public QueryWhere<T> andOpenTrue() {
+ return open(ConditionAndOr.AND, true);
+ }
+
+ public QueryWhere<T> andOpenFalse() {
+ return open(ConditionAndOr.AND, false);
+ }
+
/**
* Specify an OR condition with a mapped primitive boolean.
*
@@ -226,6 +249,38 @@ public class QueryWhere<T> { return new QueryCondition<T, A>(query, x);
}
+ public QueryWhere<T> or(And<T> conditions) {
+ orOpenTrue();
+ query.addConditionToken(conditions.where.query);
+ return close();
+ }
+
+ public QueryWhere<T> or(Or<T> conditions) {
+ orOpenFalse();
+ query.addConditionToken(conditions.where.query);
+ return close();
+ }
+
+ public QueryWhere<T> orOpenTrue() {
+ return open(ConditionAndOr.OR, true);
+ }
+
+ public QueryWhere<T> orOpenFalse() {
+ return open(ConditionAndOr.OR, false);
+ }
+
+ private QueryWhere<T> open(ConditionAndOr andOr, Boolean condition) {
+ query.addConditionToken(andOr);
+ query.addConditionToken(ConditionOpenClose.OPEN);
+ query.addConditionToken(new Function("", condition));
+ return this;
+ }
+
+ public QueryWhere<T> close() {
+ query.addConditionToken(ConditionOpenClose.CLOSE);
+ return this;
+ }
+
public QueryWhere<T> limit(long limit) {
query.limit(limit);
return this;
|