summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/iciql/Query.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-10-29 17:12:14 -0400
committerJames Moger <james.moger@gitblit.com>2014-10-29 17:12:14 -0400
commit8d28bc740c9bcb76186e7572f74a144397e780ce (patch)
tree1815e1d21df77e352ba2e8106557f71cb5561a8e /src/main/java/com/iciql/Query.java
parentbdb2899da4cbb27016d85c5e4fe268ddbccef546 (diff)
downloadiciql-8d28bc740c9bcb76186e7572f74a144397e780ce.tar.gz
iciql-8d28bc740c9bcb76186e7572f74a144397e780ce.zip
Support data type adapters
This allows custom types to be (de)serialized into a standard JDBC type or to support db-specific data types, like the Postgres json and xml types.
Diffstat (limited to 'src/main/java/com/iciql/Query.java')
-rw-r--r--src/main/java/com/iciql/Query.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main/java/com/iciql/Query.java b/src/main/java/com/iciql/Query.java
index f22215c..7c5c985 100644
--- a/src/main/java/com/iciql/Query.java
+++ b/src/main/java/com/iciql/Query.java
@@ -28,9 +28,9 @@ import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
+import com.iciql.Iciql.EnumType;
import com.iciql.NestedConditions.And;
import com.iciql.NestedConditions.Or;
-import com.iciql.Iciql.EnumType;
import com.iciql.bytecode.ClassReader;
import com.iciql.util.IciqlLogger;
import com.iciql.util.JdbcUtils;
@@ -253,7 +253,7 @@ public class Query<T> {
int[] columns = def.mapColumns(false, rs);
while (rs.next()) {
T item = from.newObject();
- def.readRow(item, rs, columns);
+ def.readRow(db.getDialect(), item, rs, columns);
result.add(item);
}
} catch (SQLException e) {
@@ -406,7 +406,7 @@ public class Query<T> {
int[] columns = def.mapColumns(false, rs);
while (rs.next()) {
X row = Utils.newObject(clazz);
- def.readRow(row, rs, columns);
+ def.readRow(db.getDialect(), row, rs, columns);
result.add(row);
}
} catch (SQLException e) {
@@ -841,13 +841,19 @@ public class Query<T> {
}
private void addParameter(SQLStatement stat, Object alias, Object value) {
- if (alias != null && value.getClass().isEnum()) {
- SelectColumn<T> col = getColumnByReference(alias);
+ SelectColumn<T> col = getColumnByReference(alias);
+ if (col != null && value.getClass().isEnum()) {
+ // enum
EnumType type = col.getFieldDefinition().enumType;
Enum<?> anEnum = (Enum<?>) value;
Object y = Utils.convertEnum(anEnum, type);
stat.addParameter(y);
+ } else if (col != null) {
+ // object
+ Object parameter = db.getDialect().serialize(value, col.getFieldDefinition().typeAdapter);
+ stat.addParameter(parameter);
} else {
+ // primitive
stat.addParameter(value);
}
}