@@ -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); |
@@ -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); | |||
} | |||
} |
@@ -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); |
@@ -131,13 +131,13 @@ public class ModelsTest { | |||
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); | |||
@@ -148,9 +148,9 @@ public class ModelsTest { | |||
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()); | |||
} | |||