aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-10-30 09:59:05 -0400
committerJames Moger <james.moger@gitblit.com>2014-10-30 09:59:05 -0400
commitfa57a7684e9d4592aac06057fb2de14ccd0df38a (patch)
treecf15d7fd963f6d1057385db2c7c3f38fc198dea2 /src
parentccbdddcf18d892859f9200b2c9285b5cd771d575 (diff)
downloadiciql-fa57a7684e9d4592aac06057fb2de14ccd0df38a.tar.gz
iciql-fa57a7684e9d4592aac06057fb2de14ccd0df38a.zip
Allow manual registration of type adapters
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/iciql/SQLDialect.java9
-rw-r--r--src/main/java/com/iciql/SQLDialectDefault.java9
-rw-r--r--src/main/java/com/iciql/TableDefinition.java2
3 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/com/iciql/SQLDialect.java b/src/main/java/com/iciql/SQLDialect.java
index 8937baf..7c45cc2 100644
--- a/src/main/java/com/iciql/SQLDialect.java
+++ b/src/main/java/com/iciql/SQLDialect.java
@@ -32,12 +32,19 @@ import com.iciql.TableDefinition.IndexDefinition;
public interface SQLDialect {
/**
+ * Registers the type adapter instance.
+ *
+ * @param typeAdapter
+ */
+ void registerAdapter(DataTypeAdapter<?> typeAdapter);
+
+ /**
* Returns the registered instance of the type adapter.
*
* @param typeAdapter
* @return the type adapter instance
*/
- DataTypeAdapter<?> getTypeAdapter(Class<? extends DataTypeAdapter<?>> typeAdapter);
+ DataTypeAdapter<?> getAdapter(Class<? extends DataTypeAdapter<?>> typeAdapter);
/**
* Serialize the Java object into a type or format that the database will accept.
diff --git a/src/main/java/com/iciql/SQLDialectDefault.java b/src/main/java/com/iciql/SQLDialectDefault.java
index 7789412..bcfa64f 100644
--- a/src/main/java/com/iciql/SQLDialectDefault.java
+++ b/src/main/java/com/iciql/SQLDialectDefault.java
@@ -345,7 +345,12 @@ public class SQLDialectDefault implements SQLDialect {
}
@Override
- public DataTypeAdapter<?> getTypeAdapter(Class<? extends DataTypeAdapter<?>> typeAdapter) {
+ public void registerAdapter(DataTypeAdapter<?> typeAdapter) {
+ typeAdapters.put((Class<? extends DataTypeAdapter<?>>) typeAdapter.getClass(), typeAdapter);
+ }
+
+ @Override
+ public DataTypeAdapter<?> getAdapter(Class<? extends DataTypeAdapter<?>> typeAdapter) {
DataTypeAdapter<?> dtt = typeAdapters.get(typeAdapter);
if (dtt == null) {
dtt = Utils.newObject(typeAdapter);
@@ -362,7 +367,7 @@ public class SQLDialectDefault implements SQLDialect {
return value;
}
- DataTypeAdapter<T> dtt = (DataTypeAdapter<T>) getTypeAdapter(typeAdapter);
+ DataTypeAdapter<T> dtt = (DataTypeAdapter<T>) getAdapter(typeAdapter);
return dtt.serialize(value);
}
diff --git a/src/main/java/com/iciql/TableDefinition.java b/src/main/java/com/iciql/TableDefinition.java
index 4536695..7857a5a 100644
--- a/src/main/java/com/iciql/TableDefinition.java
+++ b/src/main/java/com/iciql/TableDefinition.java
@@ -534,7 +534,7 @@ public class TableDefinition<T> {
if (col.typeAdapter() != null && col.typeAdapter() != StandardJDBCTypeAdapter.class) {
typeAdapter = col.typeAdapter();
- DataTypeAdapter<?> dtt = db.getDialect().getTypeAdapter(col.typeAdapter());
+ DataTypeAdapter<?> dtt = db.getDialect().getAdapter(col.typeAdapter());
dataType = dtt.getDataType();
}