summaryrefslogtreecommitdiff
path: root/spring-jdbc/src/main
diff options
context:
space:
mode:
authorEmmanuel Bourg <ebourg@apache.org>2019-01-01 11:22:29 +0100
committerEmmanuel Bourg <ebourg@apache.org>2019-01-01 11:22:29 +0100
commitd2188a36ffbb40643baa12f9a68494774552563f (patch)
treebe7118bd87b5b0960603ccda439d474261fbd69d /spring-jdbc/src/main
parentcb53abe54064010cd788530c7a882ecebb88afcd (diff)
New upstream version 4.3.21
Diffstat (limited to 'spring-jdbc/src/main')
-rw-r--r--spring-jdbc/src/main/java/org/springframework/jdbc/core/BatchUpdateUtils.java13
-rw-r--r--spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java3
-rw-r--r--spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java8
-rw-r--r--spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java11
-rw-r--r--spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java16
-rw-r--r--spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java8
-rw-r--r--spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java31
7 files changed, 46 insertions, 44 deletions
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BatchUpdateUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BatchUpdateUtils.java
index d18099a6..d1546a9d 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/BatchUpdateUtils.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/BatchUpdateUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,24 +25,29 @@ import java.util.List;
* Mainly for internal use within the framework.
*
* @author Thomas Risberg
+ * @author Juergen Hoeller
* @since 3.0
*/
public abstract class BatchUpdateUtils {
public static int[] executeBatchUpdate(
- String sql, final List<Object[]> batchValues, final int[] columnTypes, JdbcOperations jdbcOperations) {
+ String sql, final List<Object[]> batchArgs, final int[] columnTypes, JdbcOperations jdbcOperations) {
+
+ if (batchArgs.isEmpty()) {
+ return new int[0];
+ }
return jdbcOperations.batchUpdate(
sql,
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
- Object[] values = batchValues.get(i);
+ Object[] values = batchArgs.get(i);
setStatementParameters(values, ps, columnTypes);
}
@Override
public int getBatchSize() {
- return batchValues.size();
+ return batchArgs.size();
}
});
}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
index acd1c034..64aa2a82 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -914,6 +914,7 @@ public interface JdbcOperations {
* @param pss ParameterizedPreparedStatementSetter to use
* @return an array containing for each batch another array containing the numbers of rows affected
* by each update in the batch
+ * @since 3.1
*/
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
index 6a2bc943..6f97a196 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1018,11 +1018,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
public int[][] doInPreparedStatement(PreparedStatement ps) throws SQLException {
List<int[]> rowsAffected = new ArrayList<int[]>();
try {
- boolean batchSupported = true;
- if (!JdbcUtils.supportsBatchUpdates(ps.getConnection())) {
- batchSupported = false;
- logger.warn("JDBC Driver does not support Batch updates; resorting to single statement execution");
- }
+ boolean batchSupported = JdbcUtils.supportsBatchUpdates(ps.getConnection());
int n = 0;
for (T obj : batchArgs) {
pss.setValues(ps, obj);
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java
index cffc7a85..4430e05b 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterBatchUpdateUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,15 +28,16 @@ import org.springframework.jdbc.core.JdbcOperations;
* Mainly for internal use within the framework.
*
* @author Thomas Risberg
+ * @author Juergen Hoeller
* @since 3.0
*/
public class NamedParameterBatchUpdateUtils extends BatchUpdateUtils {
- public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql,
- final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
+ public static int[] executeBatchUpdateWithNamedParameters(
+ final ParsedSql parsedSql, final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
- if (batchArgs.length <= 0) {
- return new int[] {0};
+ if (batchArgs.length == 0) {
+ return new int[0];
}
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java
index 41a526fb..43d49c87 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterUtils.java
@@ -99,25 +99,25 @@ public abstract class NamedParameterUtils {
char c = statement[i];
if (c == ':' || c == '&') {
int j = i + 1;
- if (j < statement.length && statement[j] == ':' && c == ':') {
+ if (c == ':' && j < statement.length && statement[j] == ':') {
// Postgres-style "::" casting operator should be skipped
i = i + 2;
continue;
}
String parameter = null;
- if (j < statement.length && c == ':' && statement[j] == '{') {
+ if (c == ':' && j < statement.length && statement[j] == '{') {
// :{x} style parameter
- while (j < statement.length && statement[j] != '}') {
+ while (statement[j] != '}') {
j++;
+ if (j >= statement.length) {
+ throw new InvalidDataAccessApiUsageException("Non-terminated named parameter declaration " +
+ "at position " + i + " in statement: " + sql);
+ }
if (statement[j] == ':' || statement[j] == '{') {
throw new InvalidDataAccessApiUsageException("Parameter name contains invalid character '" +
statement[j] + "' at position " + i + " in statement: " + sql);
}
}
- if (j >= statement.length) {
- throw new InvalidDataAccessApiUsageException(
- "Non-terminated named parameter declaration at position " + i + " in statement: " + sql);
- }
if (j - i > 2) {
parameter = sql.substring(i + 2, j);
namedParameterCount = addNewNamedParameter(namedParameters, namedParameterCount, parameter);
@@ -190,7 +190,7 @@ public abstract class NamedParameterUtils {
}
/**
- * Skip over comments and quoted names present in an SQL statement
+ * Skip over comments and quoted names present in an SQL statement.
* @param statement character array containing SQL statement
* @param position current position of statement
* @return next position to process after any comments or quotes are skipped
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java
index b6ad500c..e285f1b4 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2017 the original author or authors.
+ * Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ import org.springframework.util.Assert;
* arguments. Subclasses should be JavaBeans, allowing easy configuration.
*
* <p>This class and subclasses throw runtime exceptions, defined in the
- * <codeorg.springframework.dao package</code> (and as thrown by the
+ * {@code org.springframework.dao} package (and as thrown by the
* {@code org.springframework.jdbc.core} package, which the classes
* in this package use under the hood to perform raw JDBC operations).
*
@@ -71,7 +71,7 @@ public abstract class RdbmsOperation implements InitializingBean {
private boolean returnGeneratedKeys = false;
- private String[] generatedKeysColumnNames = null;
+ private String[] generatedKeysColumnNames;
private String sql;
@@ -282,7 +282,7 @@ public abstract class RdbmsOperation implements InitializingBean {
* Add one or more declared parameters. Used for configuring this operation
* when used in a bean factory. Each parameter will specify SQL type and (optionally)
* the parameter's name.
- * @param parameters Array containing the declared {@link SqlParameter} objects
+ * @param parameters an array containing the declared {@link SqlParameter} objects
* @see #declaredParameters
*/
public void setParameters(SqlParameter... parameters) {
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java
index ee70d608..eb0d58ff 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,31 +39,30 @@ import org.springframework.jdbc.core.SqlParameter;
public abstract class SqlCall extends RdbmsOperation {
/**
- * Object enabling us to create CallableStatementCreators
- * efficiently, based on this class's declared parameters.
- */
- private CallableStatementCreatorFactory callableStatementFactory;
-
- /**
* Flag used to indicate that this call is for a function and to
* use the {? = call get_invoice_count(?)} syntax.
*/
private boolean function = false;
/**
- * Flag used to indicate that the sql for this call should be used exactly as it is
- * defined. No need to add the escape syntax and parameter place holders.
+ * Flag used to indicate that the sql for this call should be used exactly as
+ * it is defined. No need to add the escape syntax and parameter place holders.
*/
private boolean sqlReadyForUse = false;
/**
* Call string as defined in java.sql.CallableStatement.
- * String of form {call add_invoice(?, ?, ?)}
- * or {? = call get_invoice_count(?)} if isFunction is set to true
- * Updated after each parameter is added.
+ * String of form {call add_invoice(?, ?, ?)} or {? = call get_invoice_count(?)}
+ * if isFunction is set to true. Updated after each parameter is added.
*/
private String callString;
+ /**
+ * Object enabling us to create CallableStatementCreators
+ * efficiently, based on this class's declared parameters.
+ */
+ private CallableStatementCreatorFactory callableStatementFactory;
+
/**
* Constructor to allow use as a JavaBean.
@@ -79,8 +78,8 @@ public abstract class SqlCall extends RdbmsOperation {
/**
* Create a new SqlCall object with SQL, but without parameters.
* Must add parameters or settle with none.
- * @param ds DataSource to obtain connections from
- * @param sql SQL to execute
+ * @param ds the DataSource to obtain connections from
+ * @param sql the SQL to execute
*/
public SqlCall(DataSource ds, String sql) {
setDataSource(ds);
@@ -99,7 +98,7 @@ public abstract class SqlCall extends RdbmsOperation {
* Return whether this call is for a function.
*/
public boolean isFunction() {
- return function;
+ return this.function;
}
/**
@@ -113,7 +112,7 @@ public abstract class SqlCall extends RdbmsOperation {
* Return whether the SQL can be used as is.
*/
public boolean isSqlReadyForUse() {
- return sqlReadyForUse;
+ return this.sqlReadyForUse;
}