cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: CAY-2364 Wrong logging in SQLTemplate
Date Mon, 02 Oct 2017 11:34:18 GMT
Repository: cayenne
Updated Branches:
  refs/heads/STABLE-4.0 01e7586a4 -> ef5a86c18


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/ef5a86c1
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/ef5a86c1
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/ef5a86c1

Branch: refs/heads/STABLE-4.0
Commit: ef5a86c18bfc32c4ce854596101a5c3b42271fcb
Parents: 01e7586
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Mon Oct 2 14:33:47 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Mon Oct 2 14:33:47 2017 +0300

----------------------------------------------------------------------
 .../cayenne/access/jdbc/SQLTemplateAction.java  | 37 +++++++++++---------
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  8 +++++
 2 files changed, 29 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/ef5a86c1/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 8d9cf65..1dfb1a8 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
@@ -25,7 +25,6 @@ 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;
@@ -51,7 +50,6 @@ import org.apache.cayenne.query.QueryMetadata;
 import org.apache.cayenne.query.SQLAction;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.util.Util;
-import org.apache.commons.collections.IteratorUtils;
 
 /**
  * Implements a strategy for execution of SQLTemplates.
@@ -125,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 {
 
 		SQLStatement compiled = dataNode.getSqlTemplateProcessor().processTemplate(template,
 				query.getPositionalParams());
 
+		bindExtendedTypes(compiled.getBindings());
 		if (loggable) {
 			dataNode.getJdbcEventLogger().logQuery(compiled.getSql(), compiled.getBindings());
 		}
@@ -150,11 +161,12 @@ public class SQLTemplateAction implements SQLAction {
 		// for now supporting deprecated batch parameters...
 		@SuppressWarnings("unchecked")
 		Iterator<Map<String, ?>> it = (size > 0) ? query.parametersIterator()
-				: IteratorUtils.singletonIterator(Collections.emptyMap());
+				: (Iterator)Collections.singleton(Collections.emptyMap()).iterator();
 		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());
@@ -303,12 +315,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;
@@ -334,14 +346,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);
 		}
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/ef5a86c1/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 12df4b4..0adaf89 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -8,6 +8,14 @@ To browse individual bug reports check out project issue tracker:
 https://issues.apache.org/jira/browse/CAY
 
 ----------------------------------
+Release: 4.0.B3
+Date:
+----------------------------------
+Bug Fixes:
+
+CAY-2364 Wrong logging in SQLTemplate
+
+----------------------------------
 Release: 4.0.B2
 Date:
 ----------------------------------


Mime
View raw message