cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/6] cayenne git commit: CAY-2050 parameter binding with better encapsulation
Date Sat, 05 Mar 2016 08:21:50 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
index 24f06b8..d93d91d 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/oracle/OracleAdapter.java
@@ -21,16 +21,12 @@ package org.apache.cayenne.dba.oracle;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.translator.Binding;
 import org.apache.cayenne.access.translator.ejbql.EJBQLTranslatorFactory;
 import org.apache.cayenne.access.translator.select.QualifierTranslator;
 import org.apache.cayenne.access.translator.select.QueryAssembler;
 import org.apache.cayenne.access.translator.select.SelectTranslator;
-import org.apache.cayenne.access.types.ByteType;
-import org.apache.cayenne.access.types.ExtendedType;
-import org.apache.cayenne.access.types.ExtendedTypeFactory;
-import org.apache.cayenne.access.types.ExtendedTypeMap;
-import org.apache.cayenne.access.types.ShortType;
+import org.apache.cayenne.access.types.*;
 import org.apache.cayenne.configuration.Constants;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.dba.JdbcAdapter;
@@ -40,20 +36,11 @@ import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.merge.MergerFactory;
-import org.apache.cayenne.query.BatchQuery;
-import org.apache.cayenne.query.InsertBatchQuery;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.SQLAction;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.UpdateBatchQuery;
+import org.apache.cayenne.query.*;
 import org.apache.cayenne.resource.ResourceLocator;
 
 import java.lang.reflect.Field;
-import java.sql.CallableStatement;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
+import java.sql.*;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -231,16 +218,16 @@ public class OracleAdapter extends JdbcAdapter {
 	}
 
 	@Override
-	public void bindParameter(PreparedStatement statement, ParameterBinding binding)
+	public void bindParameter(PreparedStatement statement, Binding binding)
 			throws SQLException, Exception {
 
 		// Oracle doesn't support BOOLEAN even when binding NULL, so have to
 		// intercept
 		// NULL Boolean here, as super doesn't pass it through ExtendedType...
-		if (binding.getValue() == null && binding.getAttribute().getType() == Types.BOOLEAN)
{
+		if (binding.getValue() == null && binding.getType() == Types.BOOLEAN) {
 			ExtendedType typeProcessor = getExtendedTypes().getRegisteredType(Boolean.class);
 			typeProcessor.setJdbcObject(statement, binding.getValue(), binding.getStatementPosition(),
binding
-							.getAttribute().getType(),binding.getAttribute().getScale());
+							.getType(),binding.getScale());
 		} else {
 			super.bindParameter(statement, binding);
 		}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
index e4c7eff..5e61b89 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/postgres/PostgresAdapter.java
@@ -21,7 +21,7 @@ package org.apache.cayenne.dba.postgres;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.translator.Binding;
 import org.apache.cayenne.access.translator.select.QualifierTranslator;
 import org.apache.cayenne.access.translator.select.QueryAssembler;
 import org.apache.cayenne.access.translator.select.SelectTranslator;
@@ -131,7 +131,7 @@ public class PostgresAdapter extends JdbcAdapter {
 	}
 
 	@Override
-	public void bindParameter(PreparedStatement statement, ParameterBinding binding)
+	public void bindParameter(PreparedStatement statement, Binding binding)
 			throws SQLException, Exception {
 		binding.setType(mapNTypes(binding.getType()));
 		super.bindParameter(statement, binding);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
index 29afb68..839b548 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteAdapter.java
@@ -19,7 +19,6 @@
 package org.apache.cayenne.dba.sqlite;
 
 import org.apache.cayenne.access.DataNode;
-import org.apache.cayenne.access.translator.ParameterBinding;
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.access.types.ExtendedTypeFactory;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
@@ -34,8 +33,6 @@ import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLAction;
 import org.apache.cayenne.resource.ResourceLocator;
 
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
 import java.sql.Types;
 import java.util.Calendar;
 import java.util.Collection;
@@ -102,11 +99,6 @@ public class SQLiteAdapter extends JdbcAdapter {
         return query.createSQLAction(new SQLiteActionBuilder(node));
     }
 
-    @Override
-    public void bindParameter(PreparedStatement statement, ParameterBinding binding) throws
SQLException, Exception {
-        super.bindParameter(statement, binding);
-    }
-
     private int mapNTypes(int sqlType) {
         switch (sqlType) {
             case Types.NCHAR : return Types.CHAR;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
index b7592d4..e31fd50 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/sybase/SybaseAdapter.java
@@ -19,15 +19,9 @@
 
 package org.apache.cayenne.dba.sybase;
 
-import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.translator.Binding;
 import org.apache.cayenne.access.translator.ejbql.EJBQLTranslatorFactory;
-import org.apache.cayenne.access.types.ByteArrayType;
-import org.apache.cayenne.access.types.ByteType;
-import org.apache.cayenne.access.types.CharType;
-import org.apache.cayenne.access.types.ExtendedType;
-import org.apache.cayenne.access.types.ExtendedTypeFactory;
-import org.apache.cayenne.access.types.ExtendedTypeMap;
-import org.apache.cayenne.access.types.ShortType;
+import org.apache.cayenne.access.types.*;
 import org.apache.cayenne.configuration.Constants;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.dba.DefaultQuotingStrategy;
@@ -110,19 +104,19 @@ public class SybaseAdapter extends JdbcAdapter {
     }
 
     @Override
-    public void bindParameter(PreparedStatement statement, ParameterBinding binding)
+    public void bindParameter(PreparedStatement statement, Binding binding)
             throws SQLException, Exception {
 
         // Sybase driver doesn't like CLOBs and BLOBs as parameters
         if (binding.getValue() == null) {
-            if (binding.getAttribute().getType() == Types.CLOB) {
-                binding.getAttribute().setType(Types.VARCHAR);
-            } else if (binding.getAttribute().getType() == Types.BLOB) {
-                binding.getAttribute().setType(Types.VARBINARY);
+            if (binding.getType() == Types.CLOB) {
+                binding.setType(Types.VARCHAR);
+            } else if (binding.getType() == Types.BLOB) {
+                binding.setType(Types.VARBINARY);
             }
         }
 
-        if (binding.getValue() == null && binding.getAttribute().getType() == 0)
{
+        if (binding.getValue() == null && binding.getType() == 0) {
             statement.setNull(binding.getStatementPosition(), Types.VARCHAR);
         } else {
             super.bindParameter(statement, binding);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/main/java/org/apache/cayenne/log/CommonsJdbcEventLogger.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/log/CommonsJdbcEventLogger.java
b/cayenne-server/src/main/java/org/apache/cayenne/log/CommonsJdbcEventLogger.java
index 6908fcc..f9351bf 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/log/CommonsJdbcEventLogger.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/log/CommonsJdbcEventLogger.java
@@ -26,7 +26,7 @@ import java.util.List;
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ExtendedEnumeration;
 import org.apache.cayenne.access.jdbc.SQLParameterBinding;
-import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.configuration.Constants;
 import org.apache.cayenne.configuration.RuntimeProperties;
 import org.apache.cayenne.conn.DataSourceInfo;
@@ -227,7 +227,7 @@ public class CommonsJdbcEventLogger implements JdbcEventLogger {
 
 	/**
 	 * @deprecated since 4.0 use
-	 *             {@link #logQuery(String, ParameterBinding[], long)}.
+	 *             {@link #logQuery(String, DbAttributeBinding[], long)}.
 	 */
 	@Deprecated
 	@Override
@@ -295,7 +295,7 @@ public class CommonsJdbcEventLogger implements JdbcEventLogger {
 	}
 
 	@Override
-	public void logQuery(String sql, ParameterBinding[] bindings, long translatedIn) {
+	public void logQuery(String sql, DbAttributeBinding[] bindings, long translatedIn) {
 		if (isLoggable()) {
 
 			StringBuilder buffer = new StringBuilder(sql).append(" ");
@@ -335,7 +335,7 @@ public class CommonsJdbcEventLogger implements JdbcEventLogger {
 	}
 
 	@Override
-	public void logQueryParameters(String label, ParameterBinding[] bindings) {
+	public void logQueryParameters(String label, DbAttributeBinding[] bindings) {
 
 		if (isLoggable() && bindings.length > 0) {
 
@@ -348,7 +348,7 @@ public class CommonsJdbcEventLogger implements JdbcEventLogger {
 		}
 	}
 
-	private void appendParameters(StringBuilder buffer, String label, ParameterBinding[] bindings)
{
+	private void appendParameters(StringBuilder buffer, String label, DbAttributeBinding[] bindings)
{
 
 		int len = bindings.length;
 		if (len > 0) {
@@ -356,7 +356,7 @@ public class CommonsJdbcEventLogger implements JdbcEventLogger {
 			boolean hasIncluded = false;
 
 			for (int i = 0, j = 1; i < len; i++) {
-				ParameterBinding b = bindings[i];
+				DbAttributeBinding b = bindings[i];
 
 				if (b.isExcluded()) {
 					continue;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java b/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
index 49ad655..5ada199 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/log/JdbcEventLogger.java
@@ -20,7 +20,7 @@ package org.apache.cayenne.log;
 
 import java.util.List;
 
-import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.conn.DataSourceInfo;
 import org.apache.cayenne.map.DbAttribute;
 
@@ -77,14 +77,14 @@ public interface JdbcEventLogger {
 
 	/**
 	 * @deprecated since 4.0 use
-	 *             {@link #logQuery(String, ParameterBinding[], long)}.
+	 *             {@link #logQuery(String, DbAttributeBinding[], long)}.
 	 */
 	@Deprecated
 	void logQuery(String sql, List<?> params);
 
 	/**
 	 * @deprecated since 4.0 use
-	 *             {@link #logQuery(String, ParameterBinding[], long)}.
+	 *             {@link #logQuery(String, DbAttributeBinding[], long)}.
 	 */
 	@Deprecated
 	void logQuery(String sql, List<DbAttribute> attrs, List<?> params, long time);
@@ -92,16 +92,16 @@ public interface JdbcEventLogger {
 	/**
 	 * @since 4.0
 	 */
-	void logQuery(String sql, ParameterBinding[] bindings, long translatedIn);
+	void logQuery(String sql, DbAttributeBinding[] bindings, long translatedIn);
 
 	/**
 	 * @since 4.0
 	 */
-	void logQueryParameters(String label, ParameterBinding[] bindings);
+	void logQueryParameters(String label, DbAttributeBinding[] bindings);
 
 	/**
 	 * @deprecated since 4.0 in favor of
-	 *             {@link #logQueryParameters(String, ParameterBinding[])}
+	 *             {@link #logQueryParameters(String, DbAttributeBinding[])}
 	 */
 	@Deprecated
 	void logQueryParameters(String label, List<DbAttribute> attrs, List<Object>
parameters, boolean isInserting);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
b/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
index 8a56d94..1ed2252 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/log/NoopJdbcEventLogger.java
@@ -20,7 +20,7 @@ package org.apache.cayenne.log;
 
 import java.util.List;
 
-import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.conn.DataSourceInfo;
 import org.apache.cayenne.map.DbAttribute;
 
@@ -82,7 +82,7 @@ public class NoopJdbcEventLogger implements JdbcEventLogger {
 	}
 	
 	@Override
-	public void logQuery(String sql, ParameterBinding[] bindings, long translatedIn) {		
+	public void logQuery(String sql, DbAttributeBinding[] bindings, long translatedIn) {
 	}
 
 	@Override
@@ -91,7 +91,7 @@ public class NoopJdbcEventLogger implements JdbcEventLogger {
 	}
 
 	@Override
-	public void logQueryParameters(String label, ParameterBinding[] bindings) {
+	public void logQueryParameters(String label, DbAttributeBinding[] bindings) {
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d3f999b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/batch/DefaultBatchTranslatorIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/batch/DefaultBatchTranslatorIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/batch/DefaultBatchTranslatorIT.java
index 0fdc48b..a1998be 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/batch/DefaultBatchTranslatorIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/batch/DefaultBatchTranslatorIT.java
@@ -19,7 +19,7 @@
 
 package org.apache.cayenne.access.translator.batch;
 
-import org.apache.cayenne.access.translator.ParameterBinding;
+import org.apache.cayenne.access.translator.DbAttributeBinding;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.di.AdhocObjectFactory;
@@ -55,13 +55,13 @@ public class DefaultBatchTranslatorIT extends ServerCase {
             }
 
             @Override
-            protected ParameterBinding[] createBindings() {
-                return new ParameterBinding[0];
+            protected DbAttributeBinding[] createBindings() {
+                return new DbAttributeBinding[0];
             }
 
             @Override
-            protected ParameterBinding[] doUpdateBindings(BatchQueryRow row) {
-                return new ParameterBinding[0];
+            protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
+                return new DbAttributeBinding[0];
             }
         };
 
@@ -81,13 +81,13 @@ public class DefaultBatchTranslatorIT extends ServerCase {
             }
 
             @Override
-            protected ParameterBinding[] createBindings() {
-                return new ParameterBinding[0];
+            protected DbAttributeBinding[] createBindings() {
+                return new DbAttributeBinding[0];
             }
 
             @Override
-            protected ParameterBinding[] doUpdateBindings(BatchQueryRow row) {
-                return new ParameterBinding[0];
+            protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
+                return new DbAttributeBinding[0];
             }
         };
 
@@ -116,13 +116,13 @@ public class DefaultBatchTranslatorIT extends ServerCase {
             }
 
             @Override
-            protected ParameterBinding[] createBindings() {
-                return new ParameterBinding[0];
+            protected DbAttributeBinding[] createBindings() {
+                return new DbAttributeBinding[0];
             }
 
             @Override
-            protected ParameterBinding[] doUpdateBindings(BatchQueryRow row) {
-                return new ParameterBinding[0];
+            protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
+                return new DbAttributeBinding[0];
             }
         };
 


Mime
View raw message