Polishing (includes varargs for selected setters)

This commit is contained in:
Juergen Hoeller
2014-08-11 22:12:26 +02:00
parent 6639320e8e
commit 36918d6bb7
44 changed files with 482 additions and 490 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -48,7 +48,7 @@ public class PreparedStatementCreatorFactory {
/** The SQL, which won't change when the parameters change */
private final String sql;
/** List of SqlParameter objects. May not be {@code null}. */
/** List of SqlParameter objects (may not be {@code null}) */
private final List<SqlParameter> declaredParameters;
private int resultSetType = ResultSet.TYPE_FORWARD_ONLY;
@@ -76,7 +76,7 @@ public class PreparedStatementCreatorFactory {
* @param sql SQL to execute
* @param types int array of JDBC types
*/
public PreparedStatementCreatorFactory(String sql, int[] types) {
public PreparedStatementCreatorFactory(String sql, int... types) {
this.sql = sql;
this.declaredParameters = SqlParameter.sqlTypesToAnonymousParameterList(types);
}
@@ -130,7 +130,7 @@ public class PreparedStatementCreatorFactory {
/**
* Set the column names of the auto-generated keys.
*/
public void setGeneratedKeysColumnNames(String[] names) {
public void setGeneratedKeysColumnNames(String... names) {
this.generatedKeysColumnNames = names;
}
@@ -194,13 +194,13 @@ public class PreparedStatementCreatorFactory {
private final String actualSql;
private final List parameters;
private final List<?> parameters;
public PreparedStatementCreatorImpl(List<?> parameters) {
this(sql, parameters);
}
public PreparedStatementCreatorImpl(String actualSql, List parameters) {
public PreparedStatementCreatorImpl(String actualSql, List<?> parameters) {
this.actualSql = actualSql;
Assert.notNull(parameters, "Parameters List must not be null");
this.parameters = parameters;
@@ -281,7 +281,7 @@ public class PreparedStatementCreatorFactory {
declaredParameter = declaredParameters.get(i);
}
if (in instanceof Collection && declaredParameter.getSqlType() != Types.ARRAY) {
Collection entries = (Collection) in;
Collection<?> entries = (Collection<?>) in;
for (Object entry : entries) {
if (entry instanceof Object[]) {
Object[] valueArray = ((Object[])entry);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -177,7 +177,7 @@ public class SqlParameter {
* Convert a list of JDBC types, as defined in {@code java.sql.Types},
* to a List of SqlParameter objects as used in this package.
*/
public static List<SqlParameter> sqlTypesToAnonymousParameterList(int[] types) {
public static List<SqlParameter> sqlTypesToAnonymousParameterList(int... types) {
List<SqlParameter> result = new LinkedList<SqlParameter>();
if (types != null) {
for (int type : types) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2014 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.
@@ -22,7 +22,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
@@ -239,7 +238,7 @@ public class TableMetaDataContext {
List<Object> values = new ArrayList<Object>();
// for parameter source lookups we need to provide caseinsensitive lookup support since the
// database metadata is not necessarily providing case sensitive column names
Map caseInsensitiveParameterNames =
Map<String, String> caseInsensitiveParameterNames =
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource);
for (String column : this.tableColumns) {
if (parameterSource.hasValue(column)) {
@@ -259,7 +258,7 @@ public class TableMetaDataContext {
if (caseInsensitiveParameterNames.containsKey(lowerCaseName)) {
values.add(
SqlParameterSourceUtils.getTypedValue(parameterSource,
(String) caseInsensitiveParameterNames.get(lowerCaseName)));
caseInsensitiveParameterNames.get(lowerCaseName)));
}
else {
values.add(null);
@@ -292,7 +291,7 @@ public class TableMetaDataContext {
* Build the insert string based on configuration and metadata information
* @return the insert string to be used
*/
public String createInsertString(String[] generatedKeyNames) {
public String createInsertString(String... generatedKeyNames) {
HashSet<String> keys = new HashSet<String>(generatedKeyNames.length);
for (String key : generatedKeyNames) {
keys.add(key.toUpperCase());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -179,21 +179,6 @@ public abstract class AbstractJdbcInsert {
return Collections.unmodifiableList(this.declaredColumns);
}
/**
* Get the names of any generated keys
*/
public String[] getGeneratedKeyNames() {
return this.generatedKeyNames;
}
/**
* Set the names of any generated keys
*/
public void setGeneratedKeyNames(String[] generatedKeyNames) {
checkIfConfigurationModificationIsAllowed();
this.generatedKeyNames = generatedKeyNames;
}
/**
* Specify the name of a single generated key column
*/
@@ -203,14 +188,31 @@ public abstract class AbstractJdbcInsert {
}
/**
* Specify whether the parameter metadata for the call should be used. The default is true.
* Set the names of any generated keys
*/
public void setGeneratedKeyNames(String... generatedKeyNames) {
checkIfConfigurationModificationIsAllowed();
this.generatedKeyNames = generatedKeyNames;
}
/**
* Get the names of any generated keys
*/
public String[] getGeneratedKeyNames() {
return this.generatedKeyNames;
}
/**
* Specify whether the parameter metadata for the call should be used.
* The default is {@code true}.
*/
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) {
this.tableMetaDataContext.setAccessTableColumnMetaData(accessTableColumnMetaData);
}
/**
* Specify whether the default for including synonyms should be changed. The default is false.
* Specify whether the default for including synonyms should be changed.
* The default is {@code false}.
*/
public void setOverrideIncludeSynonymsDefault(boolean override) {
this.tableMetaDataContext.setOverrideIncludeSynonymsDefault(override);
@@ -311,7 +313,7 @@ public abstract class AbstractJdbcInsert {
}
/**
* Method to check whether we are allowd to make any configuration changes at this time.
* Method to check whether we are allowed to make any configuration changes at this time.
* If the class has been compiled, then no further changes to the configuration are allowed.
*/
protected void checkIfConfigurationModificationIsAllowed() {
@@ -449,12 +451,12 @@ public abstract class AbstractJdbcInsert {
"The getGeneratedKeys feature is not supported by this database");
}
if (getGeneratedKeyNames().length < 1) {
throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specificed. " +
throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specified. " +
"Using the generated keys features requires specifying the name(s) of the generated column(s)");
}
if (getGeneratedKeyNames().length > 1) {
throw new InvalidDataAccessApiUsageException(
"Current database only supports retreiving the key for a single column. There are " +
"Current database only supports retrieving the key for a single column. There are " +
getGeneratedKeyNames().length + " columns specified: " + Arrays.asList(getGeneratedKeyNames()));
}
// This is a hack to be able to get the generated key from a database that doesn't support
@@ -542,10 +544,10 @@ public abstract class AbstractJdbcInsert {
* @param batch array of Maps with parameter names and values to be used in batch insert
* @return array of number of rows affected
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
protected int[] doExecuteBatch(Map<String, Object>[] batch) {
checkCompiled();
List<Object>[] batchValues = new ArrayList[batch.length];
List[] batchValues = new ArrayList[batch.length];
int i = 0;
for (Map<String, Object> args : batch) {
List<Object> values = matchInParameterValuesWithInsertColumns(args);
@@ -559,10 +561,10 @@ public abstract class AbstractJdbcInsert {
* @param batch array of SqlParameterSource with parameter names and values to be used in insert
* @return array of number of rows affected
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
protected int[] doExecuteBatch(SqlParameterSource[] batch) {
checkCompiled();
List<Object>[] batchValues = new ArrayList[batch.length];
List[] batchValues = new ArrayList[batch.length];
int i = 0;
for (SqlParameterSource parameterSource : batch) {
List<Object> values = matchInParameterValuesWithInsertColumns(parameterSource);
@@ -611,9 +613,9 @@ public abstract class AbstractJdbcInsert {
}
/**
* Match the provided in parameter values with regitered parameters and parameters defined
* Match the provided in parameter values with registered parameters and parameters defined
* via metadata processing.
* @param parameterSource the parameter vakues provided as a {@link SqlParameterSource}
* @param parameterSource the parameter values provided as a {@link SqlParameterSource}
* @return Map with parameter names and values
*/
protected List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -210,7 +210,7 @@ public abstract class RdbmsOperation implements InitializingBean {
* Set the column names of the auto-generated keys.
* @see java.sql.Connection#prepareStatement(String, String[])
*/
public void setGeneratedKeysColumnNames(String[] names) {
public void setGeneratedKeysColumnNames(String... names) {
if (isCompiled()) {
throw new InvalidDataAccessApiUsageException(
"The column names for the generated keys must be set before the operation is compiled");
@@ -400,7 +400,7 @@ public abstract class RdbmsOperation implements InitializingBean {
*/
protected void validateNamedParameters(Map<String, ?> parameters) throws InvalidDataAccessApiUsageException {
checkCompiled();
Map paramsToUse = (parameters != null ? parameters : Collections.emptyMap());
Map<String, ?> paramsToUse = (parameters != null ? parameters : Collections.<String, Object> emptyMap());
int declaredInParameters = 0;
for (SqlParameter param : this.declaredParameters) {
if (param.isInputValueProvided()) {