From fa57a7684e9d4592aac06057fb2de14ccd0df38a Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 30 Oct 2014 09:59:05 -0400 Subject: [PATCH] Allow manual registration of type adapters --- src/main/java/com/iciql/SQLDialect.java | 9 ++++++++- src/main/java/com/iciql/SQLDialectDefault.java | 9 +++++++-- src/main/java/com/iciql/TableDefinition.java | 2 +- 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 @@ -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> typeAdapter); + DataTypeAdapter getAdapter(Class> 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> typeAdapter) { + public void registerAdapter(DataTypeAdapter typeAdapter) { + typeAdapters.put((Class>) typeAdapter.getClass(), typeAdapter); + } + + @Override + public DataTypeAdapter getAdapter(Class> 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 dtt = (DataTypeAdapter) getTypeAdapter(typeAdapter); + DataTypeAdapter dtt = (DataTypeAdapter) 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 { 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(); } -- 2.39.5