]> source.dussan.org Git - iciql.git/commitdiff
Allow manual registration of type adapters
authorJames Moger <james.moger@gitblit.com>
Thu, 30 Oct 2014 13:59:05 +0000 (09:59 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 30 Oct 2014 13:59:05 +0000 (09:59 -0400)
src/main/java/com/iciql/SQLDialect.java
src/main/java/com/iciql/SQLDialectDefault.java
src/main/java/com/iciql/TableDefinition.java

index 8937baf2b765025f8ae2954d2a17d3e594389065..7c45cc2d5f0d63064473f2ddab985614717eaa22 100644 (file)
@@ -31,13 +31,20 @@ 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.
index 77894120776f82bf25984808fd48a5e7237a0454..bcfa64f9574e750aae13b139657d9aefaa4d3855 100644 (file)
@@ -345,7 +345,12 @@ public class SQLDialectDefault implements SQLDialect {
        }\r
 \r
        @Override\r
-       public DataTypeAdapter<?> getTypeAdapter(Class<? extends DataTypeAdapter<?>> typeAdapter) {\r
+       public void registerAdapter(DataTypeAdapter<?> typeAdapter) {\r
+               typeAdapters.put((Class<? extends DataTypeAdapter<?>>) typeAdapter.getClass(), typeAdapter);\r
+       }\r
+\r
+       @Override\r
+       public DataTypeAdapter<?> getAdapter(Class<? extends DataTypeAdapter<?>> typeAdapter) {\r
                DataTypeAdapter<?> dtt = typeAdapters.get(typeAdapter);\r
                if (dtt == null) {\r
                        dtt = Utils.newObject(typeAdapter);\r
@@ -362,7 +367,7 @@ public class SQLDialectDefault implements SQLDialect {
                        return value;\r
                }\r
 \r
-               DataTypeAdapter<T> dtt = (DataTypeAdapter<T>) getTypeAdapter(typeAdapter);\r
+               DataTypeAdapter<T> dtt = (DataTypeAdapter<T>) getAdapter(typeAdapter);\r
                return dtt.serialize(value);\r
        }\r
 \r
index 4536695d51479f1ea3455e671574a27644501947..7857a5ac4652baeb7d8410f6f884b634ea90daf8 100644 (file)
@@ -534,7 +534,7 @@ public class TableDefinition<T> {
 \r
                                if (col.typeAdapter() != null && col.typeAdapter() != StandardJDBCTypeAdapter.class) {\r
                                        typeAdapter = col.typeAdapter();\r
-                                       DataTypeAdapter<?> dtt = db.getDialect().getTypeAdapter(col.typeAdapter());\r
+                                       DataTypeAdapter<?> dtt = db.getDialect().getAdapter(col.typeAdapter());\r
                                        dataType = dtt.getDataType();\r
                                }\r
 \r