aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/iciql/Query.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2011-08-07 15:53:18 -0400
committerJames Moger <james.moger@gmail.com>2011-08-07 15:53:18 -0400
commit684838def9e1646c266ffb46bbc65b5dfdc8f14d (patch)
treeab0625631b4c845ee4d9b2e48b12035df13a038b /src/com/iciql/Query.java
parent0c5463e7372fe4c47341dcf0c48bdd94682d0c7c (diff)
downloadiciql-684838def9e1646c266ffb46bbc65b5dfdc8f14d.tar.gz
iciql-684838def9e1646c266ffb46bbc65b5dfdc8f14d.zip
Finished enum query support (issue 4)
Diffstat (limited to 'src/com/iciql/Query.java')
-rw-r--r--src/com/iciql/Query.java29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/com/iciql/Query.java b/src/com/iciql/Query.java
index b6018ea..c44cac7 100644
--- a/src/com/iciql/Query.java
+++ b/src/com/iciql/Query.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
+import com.iciql.Iciql.EnumType;
import com.iciql.bytecode.ClassReader;
import com.iciql.util.JdbcUtils;
import com.iciql.util.StatementLogger;
@@ -213,7 +214,7 @@ public class Query<T> {
@SuppressWarnings("unchecked")
private <X> List<X> selectSimple(X x, boolean distinct) {
SQLStatement stat = getSelectStatement(distinct);
- appendSQL(stat, x);
+ appendSQL(stat, null, x);
appendFromWhere(stat);
ResultSet rs = stat.executeQuery();
List<X> result = Utils.newArrayList();
@@ -343,26 +344,36 @@ public class Query<T> {
*
* @param stat
* the statement
- * @param x
- * the alias object
+ * @param alias
+ * the alias object (can be null)
+ * @param value
+ * the value
*/
- public void appendSQL(SQLStatement stat, Object x) {
- if (x == Function.count()) {
+ public void appendSQL(SQLStatement stat, Object alias, Object value) {
+ if (value == Function.count()) {
stat.appendSQL("COUNT(*)");
return;
}
- Token token = Db.getToken(x);
+ Token token = Db.getToken(value);
if (token != null) {
token.appendSQL(stat, this);
return;
}
- SelectColumn<T> col = aliasMap.get(x);
+ SelectColumn<T> col = aliasMap.get(value);
if (col != null) {
col.appendSQL(stat);
return;
}
stat.appendSQL("?");
- stat.addParameter(x);
+ if (alias != null && value.getClass().isEnum()) {
+ col = aliasMap.get(alias);
+ EnumType type = col.getFieldDefinition().enumType;
+ Enum<?> anEnum = (Enum<?>) value;
+ Object y = Utils.convertEnum(anEnum, type);
+ stat.addParameter(y);
+ } else {
+ stat.addParameter(value);
+ }
}
void addConditionToken(Token condition) {
@@ -397,7 +408,7 @@ public class Query<T> {
if (i++ > 0) {
stat.appendSQL(", ");
}
- appendSQL(stat, obj);
+ appendSQL(stat, null, obj);
stat.appendSQL(" ");
}
}