diff options
author | James Moger <james.moger@gmail.com> | 2011-08-08 07:54:28 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-08 07:54:28 -0400 |
commit | 19326deded5a62997962d6d612de4b857303e21b (patch) | |
tree | 766efb5eb93f5a5c7edfaf4b8acec66ff2883d0d /src/com | |
parent | 99359ad5077e416c897e9596f081fc694f9ae5df (diff) | |
download | iciql-19326deded5a62997962d6d612de4b857303e21b.tar.gz iciql-19326deded5a62997962d6d612de4b857303e21b.zip |
Refinement to BETWEEN to feel more like the rest of the API.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/iciql/Query.java | 21 | ||||
-rw-r--r-- | src/com/iciql/QueryBetween.java | 35 | ||||
-rw-r--r-- | src/com/iciql/QueryCondition.java | 11 |
3 files changed, 55 insertions, 12 deletions
diff --git a/src/com/iciql/Query.java b/src/com/iciql/Query.java index d6ee0ef..2d31e8d 100644 --- a/src/com/iciql/Query.java +++ b/src/com/iciql/Query.java @@ -367,7 +367,7 @@ public class Query<T> { stat.appendSQL("?");
addParameter(stat, alias, value);
}
-
+
/**
* INTERNAL
*
@@ -375,19 +375,28 @@ public class Query<T> { * the statement
* @param alias
* the alias object (can be null)
- * @param value
- * the value
+ * @param valueLeft
+ * the value on the left of the compound clause
+ * @param valueRight
+ * the value on the right of the compound clause
+ * @param compareType
+ * the current compare type (e.g. BETWEEN)
*/
- public void appendSQL(SQLStatement stat, Object alias, Object valueLeft, Object valueRight, CompareType compareType) {
+ public void appendSQL(SQLStatement stat, Object alias, Object valueLeft, Object valueRight,
+ CompareType compareType) {
stat.appendSQL("?");
stat.appendSQL(" ");
- stat.appendSQL("AND");
+ switch (compareType) {
+ case BETWEEN:
+ stat.appendSQL("AND");
+ break;
+ }
stat.appendSQL(" ");
stat.appendSQL("?");
addParameter(stat, alias, valueLeft);
addParameter(stat, alias, valueRight);
}
-
+
private void addParameter(SQLStatement stat, Object alias, Object value) {
if (alias != null && value.getClass().isEnum()) {
SelectColumn<T> col = aliasMap.get(alias);
diff --git a/src/com/iciql/QueryBetween.java b/src/com/iciql/QueryBetween.java new file mode 100644 index 0000000..26ac40e --- /dev/null +++ b/src/com/iciql/QueryBetween.java @@ -0,0 +1,35 @@ +/*
+ * Copyright 2011 James Moger.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.iciql;
+
+public class QueryBetween<T, A> {
+
+ private Query<T> query;
+ private A x;
+ private A y;
+
+ public QueryBetween(Query<T> query, A x, A y) {
+ this.query = query;
+ this.x = x;
+ this.y = y;
+ }
+
+ public QueryWhere<T> and(A z) {
+ query.addConditionToken(new Condition<A>(x, y, z, CompareType.BETWEEN));
+ return new QueryWhere<T>(query);
+ }
+}
diff --git a/src/com/iciql/QueryCondition.java b/src/com/iciql/QueryCondition.java index efaccb6..583f26d 100644 --- a/src/com/iciql/QueryCondition.java +++ b/src/com/iciql/QueryCondition.java @@ -45,7 +45,7 @@ public class QueryCondition<T, A> { query.addConditionToken(new Condition<A>(x, y, CompareType.NOT_EQUAL)); return new QueryWhere<T>(query); } - + public QueryWhere<T> isNull() { query.addConditionToken(new Condition<A>(x, null, CompareType.IS_NULL)); return new QueryWhere<T>(query); @@ -75,12 +75,11 @@ public class QueryCondition<T, A> { query.addConditionToken(new Condition<A>(x, y, CompareType.AT_MOST)); return new QueryWhere<T>(query); } - - public QueryWhere<T> between(A y, A z) { - query.addConditionToken(new Condition<A>(x, y, z, CompareType.BETWEEN)); - return new QueryWhere<T>(query); + + public QueryBetween<T, A> between(A y) { + return new QueryBetween<T, A>(query, x, y); } - + public QueryWhere<T> like(A pattern) { query.addConditionToken(new Condition<A>(x, pattern, CompareType.LIKE)); return new QueryWhere<T>(query); |