cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/3] cayenne git commit: CAY-2364 Wrong logging in SQLTemplate
Date Thu, 21 Sep 2017 14:03:16 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master a4075721b -> f4627713c


CAY-2364 Wrong logging in SQLTemplate


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

Branch: refs/heads/master
Commit: bb9f8cdcbda33c01ea9bd6d00028812556ac4536
Parents: a407572
Author: Maxim Petrusevich <maks1464@gmail.com>
Authored: Thu Sep 21 16:01:07 2017 +0300
Committer: Maxim Petrusevich <maks1464@gmail.com>
Committed: Thu Sep 21 16:01:07 2017 +0300

----------------------------------------------------------------------
 .../cayenne/access/jdbc/SQLTemplateAction.java  | 47 +++++++++++---------
 1 file changed, 27 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/bb9f8cdc/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 f5d8900..a1f4b3d 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
@@ -53,7 +53,7 @@ import org.apache.cayenne.util.Util;
 
 /**
  * Implements a strategy for execution of SQLTemplates.
- * 
+ *
  * @since 1.2 replaces SQLTemplateExecutionPlan
  */
 public class SQLTemplateAction implements SQLAction {
@@ -123,12 +123,25 @@ public class SQLTemplateAction implements SQLAction {
 		callback.nextBatchCount(query, ints);
 	}
 
+	private void bindExtendedTypes(ParameterBinding[] bindings) {
+		int i = 1;
+		for (ParameterBinding binding : bindings) {
+			Object value = binding.getValue();
+			ExtendedType extendedType = value != null
+					? getAdapter().getExtendedTypes().getRegisteredType(value.getClass())
+					: getAdapter().getExtendedTypes().getDefaultType();
+			binding.setExtendedType(extendedType);
+			binding.setStatementPosition(i++);
+		}
+	}
+
 	private void runWithPositionalParameters(Connection connection, OperationObserver callback,
String template,
-			Collection<Number> counts, boolean loggable) throws Exception {
+											 Collection<Number> counts, boolean loggable) throws Exception {
 
 		SQLStatement compiled = dataNode.getSqlTemplateProcessor().processTemplate(template,
 				query.getPositionalParams());
 
+		bindExtendedTypes(compiled.getBindings());
 		if (loggable) {
 			dataNode.getJdbcEventLogger().logQuery(compiled.getSql(), compiled.getBindings());
 		}
@@ -158,6 +171,7 @@ public class SQLTemplateAction implements SQLAction {
 		for (int i = 0; i < batchSize; i++) {
 			Map<String, ?> nextParameters = it.next();
 			SQLStatement compiled = dataNode.getSqlTemplateProcessor().processTemplate(template, nextParameters);
+			bindExtendedTypes(compiled.getBindings());
 			if (loggable) {
 				dataNode.getJdbcEventLogger().logQuery(compiled.getSql(), compiled.getBindings());
 			}
@@ -168,7 +182,7 @@ public class SQLTemplateAction implements SQLAction {
 	}
 
 	protected void execute(Connection connection, OperationObserver callback, SQLStatement compiled,
-			Collection<Number> updateCounts) throws SQLException, Exception {
+						   Collection<Number> updateCounts) throws SQLException, Exception {
 
 		long t1 = System.currentTimeMillis();
 		boolean iteratedResult = callback.isIteratedResult();
@@ -225,7 +239,7 @@ public class SQLTemplateAction implements SQLAction {
 
 	@SuppressWarnings({ "unchecked", "rawtypes" })
 	protected void processSelectResult(SQLStatement compiled, Connection connection, Statement
statement,
-			ResultSet resultSet, OperationObserver callback, final long startTime) throws Exception
{
+									   ResultSet resultSet, OperationObserver callback, final long startTime) throws
Exception {
 
 		boolean iteratedResult = callback.isIteratedResult();
 
@@ -273,8 +287,8 @@ public class SQLTemplateAction implements SQLAction {
 	protected RowDescriptorBuilder configureRowDescriptorBuilder(SQLStatement compiled, ResultSet
resultSet)
 			throws SQLException {
 		RowDescriptorBuilder builder = new RowDescriptorBuilder()
-                .setResultSet(resultSet)
-                .validateDuplicateColumnNames();
+				.setResultSet(resultSet)
+				.validateDuplicateColumnNames();
 
 		// SQLTemplate #result columns take precedence over other ways to determine the type
 		if (compiled.getResultColumns().length > 0) {
@@ -305,12 +319,12 @@ public class SQLTemplateAction implements SQLAction {
 		}
 
 		switch (query.getColumnNamesCapitalization()) {
-		case LOWER:
-			builder.useLowercaseColumnNames();
-			break;
-		case UPPER:
-			builder.useUppercaseColumnNames();
-			break;
+			case LOWER:
+				builder.useLowercaseColumnNames();
+				break;
+			case UPPER:
+				builder.useUppercaseColumnNames();
+				break;
 		}
 
 		return builder;
@@ -319,7 +333,7 @@ public class SQLTemplateAction implements SQLAction {
 	/**
 	 * Extracts a template string from a SQLTemplate query. Exists mainly for
 	 * the benefit of subclasses that can customize returned template.
-	 * 
+	 *
 	 * @since 1.2
 	 */
 	protected String extractTemplateString() {
@@ -336,14 +350,7 @@ public class SQLTemplateAction implements SQLAction {
 	protected void bind(PreparedStatement preparedStatement, ParameterBinding[] bindings)
 			throws SQLException, Exception {
 		// bind parameters
-		int i = 1;
 		for (ParameterBinding binding : bindings) {
-			Object value = binding.getValue();
-			ExtendedType extendedType = value != null
-					? getAdapter().getExtendedTypes().getRegisteredType(value.getClass())
-					: getAdapter().getExtendedTypes().getDefaultType();
-			binding.setExtendedType(extendedType);
-			binding.setStatementPosition(i++);
 			dataNode.getAdapter().bindParameter(preparedStatement, binding);
 		}
 


Mime
View raw message