CAY-2050 | Choosing ExtendedType based on object class

Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/b99c2b4b
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/b99c2b4b
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/b99c2b4b

Branch: refs/heads/master
Commit: b99c2b4b1200a4acfb6a44fc7312b020dc3b1e25
Parents: efa48e5
Author: Savva Kolbachev <s.kolbac...@gmail.com>
Authored: Sat Jan 21 17:17:34 2017 +0300
Committer: Savva Kolbachev <s.kolbac...@gmail.com>
Committed: Sat Jan 21 18:16:02 2017 +0300

----------------------------------------------------------------------
 .../cayenne/access/jdbc/SQLTemplateAction.java  | 33 ++++++------
 .../access/translator/DbAttributeBinding.java   |  5 +-
 .../access/translator/ParameterBinding.java     | 11 ++--
 .../translator/ProcedureParameterBinding.java   |  5 +-
 .../translator/batch/DeleteBatchTranslator.java | 20 ++++----
 .../translator/batch/InsertBatchTranslator.java | 18 ++++---
 .../batch/SoftDeleteBatchTranslator.java        | 11 ++--
 .../translator/batch/UpdateBatchTranslator.java | 31 ++++++------
 .../procedure/ProcedureTranslator.java          | 23 +++++----
 .../translator/select/QueryAssembler.java       | 23 +++++----
 .../org/apache/cayenne/dba/JdbcAdapter.java     | 37 +++++++-------
 .../dba/oracle/Oracle8LOBBatchAction.java       | 53 ++++++++++++--------
 .../dba/oracle/Oracle8LOBBatchTranslator.java   | 22 ++++----
 13 files changed, 160 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
index eea8470..c8369a0 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
@@ -19,6 +19,19 @@
 
 package org.apache.cayenne.access.jdbc;
 
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ResultIterator;
@@ -40,19 +53,6 @@ import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.util.Util;
 import org.apache.commons.collections.IteratorUtils;
 
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Implements a strategy for execution of SQLTemplates.
  * 
@@ -235,9 +235,7 @@ public class SQLTemplateAction implements SQLAction {
                RowDescriptorBuilder builder = 
configureRowDescriptorBuilder(compiled, resultSet);
                RowReader<?> rowReader = 
dataNode.rowReader(builder.getDescriptor(types), queryMetadata);
 
-               JDBCResultIterator result = new JDBCResultIterator(statement, 
resultSet, rowReader);
-
-               ResultIterator it = result;
+               ResultIterator it = new JDBCResultIterator(statement, 
resultSet, rowReader);
 
                if (iteratedResult) {
 
@@ -357,10 +355,11 @@ public class SQLTemplateAction implements SQLAction {
                                                ? 
getAdapter().getExtendedTypes().getRegisteredType(value.getClass())
                                                : 
getAdapter().getExtendedTypes().getDefaultType();
 
-                               ParameterBinding binding = new 
ParameterBinding(extendedType);
+                               ParameterBinding binding = new 
ParameterBinding();
                                binding.setType(bindings[i].getJdbcType());
                                binding.setStatementPosition(i + 1);
                                binding.setValue(value);
+                               binding.setExtendedType(extendedType);
                                
dataNode.getAdapter().bindParameter(preparedStatement, binding);
                        }
                }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/DbAttributeBinding.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/DbAttributeBinding.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/DbAttributeBinding.java
index 523c473..78b6d71 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/DbAttributeBinding.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/DbAttributeBinding.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.access.translator;
 
-import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.map.DbAttribute;
 
 /**
@@ -30,8 +29,8 @@ public class DbAttributeBinding extends ParameterBinding {
 
        private final DbAttribute attribute;
 
-       public DbAttributeBinding(DbAttribute attribute, ExtendedType 
extendedType) {
-               super(extendedType);
+       public DbAttributeBinding(DbAttribute attribute) {
+               super();
                this.attribute = attribute;
        }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
index 8ef6b28..68d68ba 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ParameterBinding.java
@@ -35,9 +35,8 @@ public class ParameterBinding {
        private Integer type;
        private int scale;
 
-       public ParameterBinding(ExtendedType extendedType) {
+       public ParameterBinding() {
                this.statementPosition = EXCLUDED_POSITION;
-               this.extendedType = extendedType;
        }
 
        public Object getValue() {
@@ -64,21 +63,27 @@ public class ParameterBinding {
                return extendedType;
        }
 
+       public void setExtendedType(ExtendedType extendedType) {
+               this.extendedType = extendedType;
+       }
+
        /**
         * Marks the binding object as excluded for the current iteration.
         */
        public void exclude() {
                this.statementPosition = EXCLUDED_POSITION;
                this.value = null;
+               this.extendedType = null;
        }
 
        /**
         * Sets the value of the binding and initializes statement position var,
         * thus "including" this binding in the current iteration.
         */
-       public void include(int statementPosition, Object value) {
+       public void include(int statementPosition, Object value, ExtendedType 
extendedType) {
                this.statementPosition = statementPosition;
                this.value = value;
+               this.extendedType = extendedType;
        }
 
        public Integer getType() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ProcedureParameterBinding.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ProcedureParameterBinding.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ProcedureParameterBinding.java
index df15c96..6ccfaf2 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ProcedureParameterBinding.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/ProcedureParameterBinding.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.access.translator;
 
-import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.map.ProcedureParameter;
 
 /**
@@ -30,8 +29,8 @@ public class ProcedureParameterBinding extends 
ParameterBinding {
 
        private final ProcedureParameter parameter;
 
-       public ProcedureParameterBinding(ProcedureParameter procedureParameter, 
ExtendedType extendedType) {
-               super(extendedType);
+       public ProcedureParameterBinding(ProcedureParameter procedureParameter) 
{
+               super();
                this.parameter = procedureParameter;
        }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
index 9660b3f..d42240e 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/DeleteBatchTranslator.java
@@ -19,18 +19,17 @@
 
 package org.apache.cayenne.access.translator.batch;
 
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.DeleteBatchQuery;
 
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * Translator for delete BatchQueries. Creates parameterized DELETE SQL
  * statements.
@@ -82,11 +81,7 @@ public class DeleteBatchTranslator extends 
DefaultBatchTranslator {
         DbAttributeBinding[] bindings = new DbAttributeBinding[len];
 
         for (int i = 0; i < len; i++) {
-            DbAttribute a = attributes.get(i);
-
-            String typeName = TypesMapping.getJavaBySqlType(a.getType());
-            ExtendedType extendedType = 
adapter.getExtendedTypes().getRegisteredType(typeName);
-            bindings[i] = new DbAttributeBinding(a, extendedType);
+            bindings[i] = new DbAttributeBinding(attributes.get(i));
         }
 
         return bindings;
@@ -107,7 +102,12 @@ public class DeleteBatchTranslator extends 
DefaultBatchTranslator {
             if (deleteBatch.isNull(b.getAttribute())) {
                 b.exclude();
             } else {
-                b.include(j++, row.getValue(i));
+                Object value = row.getValue(i);
+                ExtendedType extendedType = value != null
+                        ? 
adapter.getExtendedTypes().getRegisteredType(value.getClass())
+                        : adapter.getExtendedTypes().getDefaultType();
+
+                b.include(j++, value, extendedType);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
index cf52929..d597f38 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/InsertBatchTranslator.java
@@ -19,17 +19,16 @@
 
 package org.apache.cayenne.access.translator.batch;
 
+import java.util.List;
+
 import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.InsertBatchQuery;
 
-import java.util.List;
-
 /**
  * Translator of InsertBatchQueries.
  */
@@ -93,16 +92,14 @@ public class InsertBatchTranslator extends 
DefaultBatchTranslator {
         for (int i = 0; i < len; i++) {
             DbAttribute a = attributes.get(i);
 
-            String typeName = TypesMapping.getJavaBySqlType(a.getType());
-            ExtendedType extendedType = 
adapter.getExtendedTypes().getRegisteredType(typeName);
-            bindings[i] = new DbAttributeBinding(a, extendedType);
+            bindings[i] = new DbAttributeBinding(a);
 
             // include/exclude state depends on DbAttribute only and can be
             // precompiled here
             if (includeInBatch(a)) {
                 // setting fake position here... all we care about is that it 
is
                 // > -1
-                bindings[i].include(1, null);
+                bindings[i].include(1, null, null);
             } else {
                 bindings[i].exclude();
             }
@@ -121,7 +118,12 @@ public class InsertBatchTranslator extends 
DefaultBatchTranslator {
 
             // exclusions are permanent
             if (!b.isExcluded()) {
-                b.include(j++, row.getValue(i));
+                Object value = row.getValue(i);
+                ExtendedType extendedType = value != null
+                        ? 
adapter.getExtendedTypes().getRegisteredType(value.getClass())
+                        : adapter.getExtendedTypes().getDefaultType();
+
+                b.include(j++, value, extendedType);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
index 514ca26..ed28cc5 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/SoftDeleteBatchTranslator.java
@@ -68,8 +68,8 @@ public class SoftDeleteBatchTranslator extends 
DeleteBatchTranslator {
         String typeName = 
TypesMapping.getJavaBySqlType(deleteAttribute.getType());
         ExtendedType extendedType = 
adapter.getExtendedTypes().getRegisteredType(typeName);
 
-        bindings[0] = new DbAttributeBinding(deleteAttribute, extendedType);
-        bindings[0].include(1, true);
+        bindings[0] = new DbAttributeBinding(deleteAttribute);
+        bindings[0].include(1, true, extendedType);
         
         System.arraycopy(superBindings, 0, bindings, 1, slen);
 
@@ -91,7 +91,12 @@ public class SoftDeleteBatchTranslator extends 
DeleteBatchTranslator {
             if (deleteBatch.isNull(b.getAttribute())) {
                 b.exclude();
             } else {
-                b.include(j++, row.getValue(i - 1));
+                Object value = row.getValue(i - 1);
+                ExtendedType extendedType = value != null
+                        ? 
adapter.getExtendedTypes().getRegisteredType(value.getClass())
+                        : adapter.getExtendedTypes().getDefaultType();
+
+                b.include(j++, value, extendedType);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
index cb34b99..ecd2619 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/batch/UpdateBatchTranslator.java
@@ -19,18 +19,17 @@
 
 package org.apache.cayenne.access.translator.batch;
 
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.QuotingStrategy;
-import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQueryRow;
 import org.apache.cayenne.query.UpdateBatchQuery;
 
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * A translator for UpdateBatchQueries that produces parameterized SQL.
  */
@@ -93,19 +92,11 @@ public class UpdateBatchTranslator extends 
DefaultBatchTranslator {
         DbAttributeBinding[] bindings = new DbAttributeBinding[ul + ql];
 
         for (int i = 0; i < ul; i++) {
-            DbAttribute a = updatedDbAttributes.get(i);
-
-            String typeName = TypesMapping.getJavaBySqlType(a.getType());
-            ExtendedType extendedType = 
adapter.getExtendedTypes().getRegisteredType(typeName);
-            bindings[i] = new DbAttributeBinding(a, extendedType);
+            bindings[i] = new DbAttributeBinding(updatedDbAttributes.get(i));
         }
 
         for (int i = 0; i < ql; i++) {
-            DbAttribute a = qualifierAttributes.get(i);
-
-            String typeName = TypesMapping.getJavaBySqlType(a.getType());
-            ExtendedType extendedType = 
adapter.getExtendedTypes().getRegisteredType(typeName);
-            bindings[ul + i] = new DbAttributeBinding(a, extendedType);
+            bindings[ul + i] = new 
DbAttributeBinding(qualifierAttributes.get(i));
         }
 
         return bindings;
@@ -126,7 +117,11 @@ public class UpdateBatchTranslator extends 
DefaultBatchTranslator {
 
         for (int i = 0; i < ul; i++) {
             Object value = row.getValue(i);
-            bindings[i].include(j++, value);
+            ExtendedType extendedType = value != null
+                    ? 
adapter.getExtendedTypes().getRegisteredType(value.getClass())
+                    : adapter.getExtendedTypes().getDefaultType();
+
+            bindings[i].include(j++, value, extendedType);
         }
 
         for (int i = 0; i < ql; i++) {
@@ -139,7 +134,11 @@ public class UpdateBatchTranslator extends 
DefaultBatchTranslator {
             }
 
             Object value = row.getValue(ul + i);
-            bindings[ul + i].include(j++, value);
+            ExtendedType extendedType = value != null
+                    ? 
adapter.getExtendedTypes().getRegisteredType(value.getClass())
+                    : adapter.getExtendedTypes().getDefaultType();
+
+            bindings[ul + i].include(j++, value, extendedType);
         }
 
         return bindings;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/procedure/ProcedureTranslator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/procedure/ProcedureTranslator.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/procedure/ProcedureTranslator.java
index f919a8b..92feb2c 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/procedure/ProcedureTranslator.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/procedure/ProcedureTranslator.java
@@ -19,6 +19,13 @@
 
 package org.apache.cayenne.access.translator.procedure;
 
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.cayenne.access.translator.ProcedureParameterBinding;
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
@@ -29,13 +36,6 @@ import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
 import org.apache.cayenne.query.ProcedureQuery;
 
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Stored procedure query translator.
  */
@@ -229,11 +229,14 @@ public class ProcedureTranslator {
                        ProcedureParameter param,
                        Object val,
                        int pos) throws Exception {
-               ExtendedType extendedType = val != null ? 
adapter.getExtendedTypes().getRegisteredType(val.getClass())
+               ExtendedType extendedType = val != null
+                               ? 
adapter.getExtendedTypes().getRegisteredType(val.getClass())
                                : adapter.getExtendedTypes().getDefaultType();
-               ProcedureParameterBinding binding = new 
ProcedureParameterBinding(param, extendedType);
-               binding.setValue(val);
+
+               ProcedureParameterBinding binding = new 
ProcedureParameterBinding(param);
                binding.setStatementPosition(pos);
+               binding.setValue(val);
+               binding.setExtendedType(extendedType);
                adapter.bindParameter(stmt, binding);
        }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
index 1128e22..3293168 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QueryAssembler.java
@@ -19,10 +19,13 @@
 
 package org.apache.cayenne.access.translator.select;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbRelationship;
@@ -31,10 +34,6 @@ import org.apache.cayenne.map.JoinType;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryMetadata;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Abstract superclass of Query translators.
  */
@@ -155,13 +154,15 @@ public abstract class QueryAssembler {
         *            DbAttribute being processed.
         */
        public void addToParamList(DbAttribute dbAttr, Object anObject) {
-               String typeName = TypesMapping.SQL_NULL;
-               if (dbAttr != null) typeName = 
TypesMapping.getJavaBySqlType(dbAttr.getType());
-               ExtendedType extendedType = 
adapter.getExtendedTypes().getRegisteredType(typeName);
-               
-               DbAttributeBinding binding = new DbAttributeBinding(dbAttr, 
extendedType);
-               binding.setValue(anObject);
+               ExtendedType extendedType = anObject != null
+                               ? 
adapter.getExtendedTypes().getRegisteredType(anObject.getClass())
+                               : adapter.getExtendedTypes().getDefaultType();
+
+               DbAttributeBinding binding = new DbAttributeBinding(dbAttr);
                binding.setStatementPosition(bindings.size() + 1);
+               binding.setValue(anObject);
+               binding.setExtendedType(extendedType);
+
                bindings.add(binding);
                if(addBindingListener != null) {
                        addBindingListener.onAdd(binding);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java 
b/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
index 979b425..b058719 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcAdapter.java
@@ -19,6 +19,15 @@
 
 package org.apache.cayenne.dba;
 
+import java.net.URL;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.translator.ParameterBinding;
@@ -48,15 +57,6 @@ import org.apache.cayenne.resource.Resource;
 import org.apache.cayenne.resource.ResourceLocator;
 import org.apache.cayenne.util.Util;
 
-import java.net.URL;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * A generic DbAdapter implementation. Can be used as a default adapter or as a
  * superclass of a concrete adapter implementation.
@@ -443,7 +443,7 @@ public class JdbcAdapter implements DbAdapter {
        @Override
        public String createFkConstraint(DbRelationship rel) {
 
-               DbEntity source = (DbEntity) rel.getSourceEntity();
+               DbEntity source = rel.getSourceEntity();
                StringBuilder buf = new StringBuilder();
                StringBuilder refBuf = new StringBuilder();
 
@@ -468,7 +468,7 @@ public class JdbcAdapter implements DbAdapter {
 
                buf.append(") REFERENCES ");
 
-               buf.append(quotingStrategy.quotedFullyQualifiedName((DbEntity) 
rel.getTargetEntity()));
+               
buf.append(quotingStrategy.quotedFullyQualifiedName(rel.getTargetEntity()));
 
                buf.append(" (").append(refBuf.toString()).append(')');
                return buf.toString();
@@ -545,12 +545,15 @@ public class JdbcAdapter implements DbAdapter {
                if (binding.getValue() == null) {
                        statement.setNull(binding.getStatementPosition(), 
binding.getType());
                } else {
-                       ExtendedType typeProcessor = 
getExtendedTypes().getRegisteredType(binding.getValue().getClass());
-                       typeProcessor.setJdbcObject(statement
-                                       , binding.getValue()
-                                       , binding.getStatementPosition()
-                                       , binding.getType()
-                                       , binding.getScale());
+                       ExtendedType typeProcessor = binding.getExtendedType() 
!= null
+                                       ? binding.getExtendedType()
+                                       : 
getExtendedTypes().getRegisteredType(binding.getValue().getClass());
+
+                       typeProcessor.setJdbcObject(statement,
+                                       binding.getValue(),
+                                       binding.getStatementPosition(),
+                                       binding.getType(),
+                                       binding.getScale());
                }
        }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
index 8cfdc2c..93fda77 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchAction.java
@@ -19,23 +19,34 @@
 
 package org.apache.cayenne.dba.oracle;
 
+import java.io.OutputStream;
+import java.io.Writer;
+import java.lang.reflect.Method;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.access.translator.DbAttributeBinding;
+import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.log.JdbcEventLogger;
 import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.query.*;
+import org.apache.cayenne.query.BatchQuery;
+import org.apache.cayenne.query.BatchQueryRow;
+import org.apache.cayenne.query.InsertBatchQuery;
+import org.apache.cayenne.query.SQLAction;
+import org.apache.cayenne.query.UpdateBatchQuery;
 import org.apache.cayenne.util.Util;
 
-import java.io.OutputStream;
-import java.io.Writer;
-import java.lang.reflect.Method;
-import java.sql.*;
-import java.util.Collections;
-import java.util.List;
-
 /**
  * @since 3.0
  */
@@ -49,8 +60,7 @@ class Oracle8LOBBatchAction implements SQLAction {
                        throws SQLException, Exception {
 
                for (DbAttributeBinding b : bindings) {
-                       DbAttributeBinding binding = new 
DbAttributeBinding(b.getAttribute(), adapter.getExtendedTypes()
-                                       
.getRegisteredType(b.getValue().getClass()));
+                       DbAttributeBinding binding = new 
DbAttributeBinding(b.getAttribute());
                        adapter.bindParameter(statement, binding);
                }
        }
@@ -95,7 +105,7 @@ class Oracle8LOBBatchAction implements SQLAction {
                        // 1. run row update
                        logger.logQuery(updateStr, Collections.EMPTY_LIST);
 
-                       try (PreparedStatement statement = 
connection.prepareStatement(updateStr);) {
+                       try (PreparedStatement statement = 
connection.prepareStatement(updateStr)) {
 
                                DbAttributeBinding[] bindings = 
translator.updateBindings(row);
                                logger.logQueryParameters("bind", bindings);
@@ -136,19 +146,22 @@ class Oracle8LOBBatchAction implements SQLAction {
                        logger.logQueryParameters("write LOB", null, lobValues, 
false);
                }
 
-               try (PreparedStatement selectStatement = 
con.prepareStatement(selectStr);) {
+               try (PreparedStatement selectStatement = 
con.prepareStatement(selectStr)) {
                        for (int i = 0; i < parametersSize; i++) {
-                               Object value = qualifierValues.get(i);
                                DbAttribute attribute = 
qualifierAttributes.get(i);
+                               Object value = qualifierValues.get(i);
+                               ExtendedType extendedType = value != null
+                                               ? 
adapter.getExtendedTypes().getRegisteredType(value.getClass())
+                                               : 
adapter.getExtendedTypes().getDefaultType();
 
-                               DbAttributeBinding binding = new 
DbAttributeBinding(attribute, adapter.getExtendedTypes()
-                                               
.getRegisteredType(value.getClass()));
+                               DbAttributeBinding binding = new 
DbAttributeBinding(attribute);
                                binding.setStatementPosition(i + 1);
                                binding.setValue(value);
-                               adapter.bindParameter(selectStatement,binding);
+                               binding.setExtendedType(extendedType);
+                               adapter.bindParameter(selectStatement, binding);
                        }
 
-                       try (ResultSet result = 
selectStatement.executeQuery();) {
+                       try (ResultSet result = selectStatement.executeQuery()) 
{
                                if (!result.next()) {
                                        throw new 
CayenneRuntimeException("Missing LOB row.");
                                }
@@ -200,7 +213,7 @@ class Oracle8LOBBatchAction implements SQLAction {
                Method getBinaryStreamMethod = 
Oracle8Adapter.getOutputStreamFromBlobMethod();
                try {
 
-                       try (OutputStream out = (OutputStream) 
getBinaryStreamMethod.invoke(blob, (Object[]) null);) {
+                       try (OutputStream out = (OutputStream) 
getBinaryStreamMethod.invoke(blob, (Object[]) null)) {
                                out.write(value);
                                out.flush();
                        }
@@ -217,7 +230,7 @@ class Oracle8LOBBatchAction implements SQLAction {
                Method getWriterMethod = 
Oracle8Adapter.getWriterFromClobMethod();
                try {
 
-                       try (Writer out = (Writer) getWriterMethod.invoke(clob, 
(Object[]) null);) {
+                       try (Writer out = (Writer) getWriterMethod.invoke(clob, 
(Object[]) null)) {
                                out.write(value);
                                out.flush();
                        }
@@ -235,7 +248,7 @@ class Oracle8LOBBatchAction implements SQLAction {
                Method getWriterMethod = 
Oracle8Adapter.getWriterFromClobMethod();
                try {
 
-                       try (Writer out = (Writer) getWriterMethod.invoke(clob, 
(Object[]) null);) {
+                       try (Writer out = (Writer) getWriterMethod.invoke(clob, 
(Object[]) null)) {
                                out.write(value);
                                out.flush();
                        }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b99c2b4b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
index d25d32f..4900ec0 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/Oracle8LOBBatchTranslator.java
@@ -19,6 +19,10 @@
 
 package org.apache.cayenne.dba.oracle;
 
+import java.sql.Types;
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.access.translator.batch.DefaultBatchTranslator;
@@ -30,10 +34,6 @@ import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.query.BatchQuery;
 import org.apache.cayenne.query.BatchQueryRow;
 
-import java.sql.Types;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * Superclass of query builders for the DML operations involving LOBs.
  * 
@@ -76,7 +76,7 @@ abstract class Oracle8LOBBatchTranslator extends 
DefaultBatchTranslator {
 
         it = qualifierAttributes.iterator();
         while (it.hasNext()) {
-            DbAttribute attribute = (DbAttribute) it.next();
+            DbAttribute attribute = it.next();
             appendDbAttribute(buf, attribute);
             buf.append(" = ?");
             if (it.hasNext()) {
@@ -118,11 +118,7 @@ abstract class Oracle8LOBBatchTranslator extends 
DefaultBatchTranslator {
         DbAttributeBinding[] bindings = new DbAttributeBinding[len];
 
         for (int i = 0; i < len; i++) {
-            DbAttribute attribute = dbAttributes.get(i);
-
-            String typeName = 
TypesMapping.getJavaBySqlType(attribute.getType());
-            ExtendedType extendedType = 
adapter.getExtendedTypes().getRegisteredType(typeName);
-            bindings[i] = new DbAttributeBinding(attribute, extendedType);
+            bindings[i] = new DbAttributeBinding(dbAttributes.get(i));
         }
 
         return bindings;
@@ -144,7 +140,11 @@ abstract class Oracle8LOBBatchTranslator extends 
DefaultBatchTranslator {
             // TODO: (Andrus) This works as long as there is no LOBs in
             // qualifier
             if (isUpdateableColumn(value, type)) {
-                b.include(j++, value);
+                ExtendedType extendedType = value != null
+                        ? 
adapter.getExtendedTypes().getRegisteredType(value.getClass())
+                        : adapter.getExtendedTypes().getDefaultType();
+
+                b.include(j++, value, extendedType);
             } else {
                 b.exclude();
             }

Reply via email to