aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/iciql/SQLDialectDefault.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2015-04-16 19:11:30 -0400
committerJames Moger <james.moger@gitblit.com>2015-04-16 19:11:30 -0400
commite4952b2465ae4167e24d416b4fc4f6996e2fe229 (patch)
tree8da93c36a6891c697e718cb3499869703c50942c /src/main/java/com/iciql/SQLDialectDefault.java
parentf897fc7d25c757fc0607ce010c1e8c50ce127131 (diff)
downloadiciql-e4952b2465ae4167e24d416b4fc4f6996e2fe229.tar.gz
iciql-e4952b2465ae4167e24d416b4fc4f6996e2fe229.zip
Move standard object deserialization into the dialect
Diffstat (limited to 'src/main/java/com/iciql/SQLDialectDefault.java')
-rw-r--r--src/main/java/com/iciql/SQLDialectDefault.java39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/main/java/com/iciql/SQLDialectDefault.java b/src/main/java/com/iciql/SQLDialectDefault.java
index 7c656bd..8547f3c 100644
--- a/src/main/java/com/iciql/SQLDialectDefault.java
+++ b/src/main/java/com/iciql/SQLDialectDefault.java
@@ -18,8 +18,11 @@
package com.iciql;
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
@@ -476,14 +479,40 @@ public class SQLDialectDefault implements SQLDialect {
}
@Override
- public Object deserialize(Object value, Class<? extends DataTypeAdapter<?>> typeAdapter) {
+ public Object deserialize(ResultSet rs, int columnIndex, Class<?> targetType, Class<? extends DataTypeAdapter<?>> typeAdapter) {
if (typeAdapter == null) {
- // pass-through
+ // standard object deserialization
+ Object value = null;
+ try {
+ // use internal Iciql type conversion
+ Object o = rs.getObject(columnIndex);
+ if (Clob.class.isAssignableFrom(o.getClass())) {
+ value = Utils.convert(o, String.class);
+ } else if (Blob.class.isAssignableFrom(o.getClass())) {
+ value = Utils.convert(o, byte[].class);
+ } else {
+ value = Utils.convert(o, targetType);
+ }
+ } catch (SQLException e) {
+ throw new IciqlException(e, "Can not convert the value at column {0} to {1}",
+ columnIndex, targetType.getName());
+ }
+
return value;
- }
+ } else {
+ // custom object deserialization with a DataTypeAdapter
+ DataTypeAdapter<?> dta = getAdapter(typeAdapter);
+ Object object = null;
+ try {
+ object = rs.getObject(columnIndex);
+ } catch (SQLException e) {
+ throw new IciqlException(e, "Can not convert the value at column {0} to {1}",
+ columnIndex, targetType.getName());
+ }
- DataTypeAdapter<?> dta = getAdapter(typeAdapter);
- return dta.deserialize(value);
+ Object value = dta.deserialize(object);
+ return value;
+ }
}
@Override