stat.appendSQL("?");\r
addParameter(stat, alias, value);\r
}\r
- \r
+\r
/**\r
* INTERNAL\r
* \r
* the statement\r
* @param alias\r
* the alias object (can be null)\r
- * @param value\r
- * the value\r
+ * @param valueLeft\r
+ * the value on the left of the compound clause\r
+ * @param valueRight\r
+ * the value on the right of the compound clause\r
+ * @param compareType\r
+ * the current compare type (e.g. BETWEEN)\r
*/\r
- public void appendSQL(SQLStatement stat, Object alias, Object valueLeft, Object valueRight, CompareType compareType) {\r
+ public void appendSQL(SQLStatement stat, Object alias, Object valueLeft, Object valueRight,\r
+ CompareType compareType) {\r
stat.appendSQL("?");\r
stat.appendSQL(" ");\r
- stat.appendSQL("AND");\r
+ switch (compareType) {\r
+ case BETWEEN:\r
+ stat.appendSQL("AND");\r
+ break;\r
+ }\r
stat.appendSQL(" ");\r
stat.appendSQL("?");\r
addParameter(stat, alias, valueLeft);\r
addParameter(stat, alias, valueRight);\r
}\r
- \r
+\r
private void addParameter(SQLStatement stat, Object alias, Object value) {\r
if (alias != null && value.getClass().isEnum()) {\r
SelectColumn<T> col = aliasMap.get(alias);\r
--- /dev/null
+/*\r
+ * Copyright 2011 James Moger.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package com.iciql;\r
+\r
+public class QueryBetween<T, A> {\r
+ \r
+ private Query<T> query;\r
+ private A x;\r
+ private A y;\r
+\r
+ public QueryBetween(Query<T> query, A x, A y) {\r
+ this.query = query;\r
+ this.x = x;\r
+ this.y = y;\r
+ }\r
+ \r
+ public QueryWhere<T> and(A z) {\r
+ query.addConditionToken(new Condition<A>(x, y, z, CompareType.BETWEEN));\r
+ return new QueryWhere<T>(query);\r
+ }\r
+}\r
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);
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);
List<EnumModels> list = db.from(e).where(e.tree()).atLeast(Tree.BIRCH).select();
assertEquals(3, list.size());
-
+
// between is an int compare
- list = db.from(e).where(e.tree()).between(Tree.BIRCH, Tree.WALNUT).select();
+ list = db.from(e).where(e.tree()).between(Tree.BIRCH).and(Tree.WALNUT).select();
assertEquals(2, list.size());
}
-
+
private void testStringEnums(EnumModels e, List<?> models) {
db.insertAll(models);
List<EnumModels> list = db.from(e).where(e.tree()).isNot(Tree.BIRCH).select();
assertEquals(models.size() - 1, list.size());
-
+
// between is a string compare
- list = db.from(e).where(e.tree()).between(Tree.MAPLE, Tree.PINE).select();
+ list = db.from(e).where(e.tree()).between(Tree.MAPLE).and(Tree.PINE).select();
assertEquals(3, list.size());
}