From 3038f03fee6164d9648bd77609d98bd7ad1b8016 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 11 Aug 2014 22:32:03 +0200 Subject: [PATCH] Polishing (cherry picked from commit 4db258b) --- .../jdbc/core/simple/AbstractJdbcCall.java | 88 ++++++++++--------- .../jdbc/core/simple/AbstractJdbcInsert.java | 32 +++---- 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java index 12e1dbd85ef..299629cc5e5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java @@ -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. @@ -53,6 +53,9 @@ public abstract class AbstractJdbcCall { /** Lower-level class used to execute SQL */ private final JdbcTemplate jdbcTemplate; + /** Context used to retrieve and manage database metadata */ + private final CallMetaDataContext callMetaDataContext = new CallMetaDataContext(); + /** List of SqlParameter objects */ private final List declaredParameters = new ArrayList(); @@ -66,12 +69,9 @@ public abstract class AbstractJdbcCall { */ private boolean compiled = false; - /** the generated string used for call statement */ + /** The generated string used for call statement */ private String callString; - /** context used to retrieve and manage database metadata */ - private CallMetaDataContext callMetaDataContext = new CallMetaDataContext(); - /** * Object enabling us to create CallableStatementCreators * efficiently, based on this class's declared parameters. @@ -103,13 +103,6 @@ public abstract class AbstractJdbcCall { return this.jdbcTemplate; } - /** - * Get the {@link CallableStatementCreatorFactory} being used - */ - protected CallableStatementCreatorFactory getCallableStatementFactory() { - return this.callableStatementFactory; - } - /** * Set the name of the stored procedure. */ @@ -153,7 +146,7 @@ public abstract class AbstractJdbcCall { } /** - * Set the schema name to use, + * Set the schema name to use. */ public void setSchemaName(String schemaName) { this.callMetaDataContext.setSchemaName(schemaName); @@ -183,8 +176,8 @@ public abstract class AbstractJdbcCall { /** * Specify whether the call requires a rerurn value. */ - public void setReturnValueRequired(boolean b) { - this.callMetaDataContext.setReturnValueRequired(b); + public void setReturnValueRequired(boolean returnValueRequired) { + this.callMetaDataContext.setReturnValueRequired(returnValueRequired); } /** @@ -194,6 +187,28 @@ public abstract class AbstractJdbcCall { return this.callMetaDataContext.isReturnValueRequired(); } + /** + * Specify whether the parameter metadata for the call should be used. The default is true. + */ + public void setAccessCallParameterMetaData(boolean accessCallParameterMetaData) { + this.callMetaDataContext.setAccessCallParameterMetaData(accessCallParameterMetaData); + } + + /** + * Get the call string that should be used based on parameters and meta data. + */ + public String getCallString() { + return this.callString; + } + + /** + * Get the {@link CallableStatementCreatorFactory} being used + */ + protected CallableStatementCreatorFactory getCallableStatementFactory() { + return this.callableStatementFactory; + } + + /** * Add a declared parameter to the list of parameters for the call. * Only parameters declared as {@code SqlParameter} and {@code SqlInOutParameter} @@ -235,20 +250,6 @@ public abstract class AbstractJdbcCall { addDeclaredRowMapper(parameterName, (RowMapper) rowMapper); } - /** - * Get the call string that should be used based on parameters and meta data. - */ - public String getCallString() { - return this.callString; - } - - /** - * Specify whether the parameter metadata for the call should be used. The default is true. - */ - public void setAccessCallParameterMetaData(boolean accessCallParameterMetaData) { - this.callMetaDataContext.setAccessCallParameterMetaData(accessCallParameterMetaData); - } - //------------------------------------------------------------------------- // Methods handling compilation issues @@ -375,18 +376,21 @@ public abstract class AbstractJdbcCall { /** * Method to perform the actual call processing */ - private Map executeCallInternal(Map params) { - CallableStatementCreator csc = getCallableStatementFactory().newCallableStatementCreator(params); + private Map executeCallInternal(Map args) { + CallableStatementCreator csc = getCallableStatementFactory().newCallableStatementCreator(args); if (logger.isDebugEnabled()) { - logger.debug("The following parameters are used for call " + getCallString() + " with: " + params); + logger.debug("The following parameters are used for call " + getCallString() + " with " + args); int i = 1; - for (SqlParameter p : getCallParameters()) { - logger.debug(i++ + ": " + p.getName() + " SQL Type "+ p.getSqlType() + " Type Name " + p.getTypeName() + " " + p.getClass().getName()); + for (SqlParameter param : getCallParameters()) { + logger.debug(i + ": " + param.getName() + ", SQL type "+ param.getSqlType() + ", type name " + + param.getTypeName() + ", parameter class [" + param.getClass().getName() + "]"); + i++; } } return getJdbcTemplate().call(csc, getCallParameters()); } + /** * Get the name of a single out parameter or return value. * Used for functions or procedures with one out parameter. @@ -395,6 +399,14 @@ public abstract class AbstractJdbcCall { return this.callMetaDataContext.getScalarOutParameterName(); } + /** + * Get a List of all the call parameters to be used for call. This includes any parameters added + * based on meta data processing. + */ + protected List getCallParameters() { + return this.callMetaDataContext.getCallParameters(); + } + /** * Match the provided in parameter values with registered parameters and * parameters defined via metadata processing. @@ -425,12 +437,4 @@ public abstract class AbstractJdbcCall { return this.callMetaDataContext.matchInParameterValuesWithCallParameters(args); } - /** - * Get a List of all the call parameters to be used for call. This includes any parameters added - * based on meta data processing. - */ - protected List getCallParameters() { - return this.callMetaDataContext.getCallParameters(); - } - } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java index c459ffe5e0e..055b86f3ccd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java @@ -73,6 +73,9 @@ public abstract class AbstractJdbcInsert { /** List of columns objects to be used in insert statement */ private final List declaredColumns = new ArrayList(); + /** The names of the columns holding the generated key */ + private String[] generatedKeyNames = new String[0]; + /** * Has this operation been compiled? Compilation means at least checking * that a DataSource or JdbcTemplate has been provided, but subclasses @@ -86,9 +89,6 @@ public abstract class AbstractJdbcInsert { /** The SQL type information for the insert columns */ private int[] insertTypes; - /** The names of the columns holding the generated key */ - private String[] generatedKeyNames = new String[0]; - /** * Constructor for sublasses to delegate to for setting the DataSource. @@ -119,7 +119,7 @@ public abstract class AbstractJdbcInsert { } /** - * Set the name of the table for this insert + * Set the name of the table for this insert. */ public void setTableName(String tableName) { checkIfConfigurationModificationIsAllowed(); @@ -127,14 +127,14 @@ public abstract class AbstractJdbcInsert { } /** - * Get the name of the table for this insert + * Get the name of the table for this insert. */ public String getTableName() { return this.tableMetaDataContext.getTableName(); } /** - * Set the name of the schema for this insert + * Set the name of the schema for this insert. */ public void setSchemaName(String schemaName) { checkIfConfigurationModificationIsAllowed(); @@ -142,14 +142,14 @@ public abstract class AbstractJdbcInsert { } /** - * Get the name of the schema for this insert + * Get the name of the schema for this insert. */ public String getSchemaName() { return this.tableMetaDataContext.getSchemaName(); } /** - * Set the name of the catalog for this insert + * Set the name of the catalog for this insert. */ public void setCatalogName(String catalogName) { checkIfConfigurationModificationIsAllowed(); @@ -157,14 +157,14 @@ public abstract class AbstractJdbcInsert { } /** - * Get the name of the catalog for this insert + * Get the name of the catalog for this insert. */ public String getCatalogName() { return this.tableMetaDataContext.getCatalogName(); } /** - * Set the names of the columns to be used + * Set the names of the columns to be used. */ public void setColumnNames(List columnNames) { checkIfConfigurationModificationIsAllowed(); @@ -173,14 +173,14 @@ public abstract class AbstractJdbcInsert { } /** - * Get the names of the columns used + * Get the names of the columns used. */ public List getColumnNames() { return Collections.unmodifiableList(this.declaredColumns); } /** - * Specify the name of a single generated key column + * Specify the name of a single generated key column. */ public void setGeneratedKeyName(String generatedKeyName) { checkIfConfigurationModificationIsAllowed(); @@ -188,7 +188,7 @@ public abstract class AbstractJdbcInsert { } /** - * Set the names of any generated keys + * Set the names of any generated keys. */ public void setGeneratedKeyNames(String... generatedKeyNames) { checkIfConfigurationModificationIsAllowed(); @@ -196,7 +196,7 @@ public abstract class AbstractJdbcInsert { } /** - * Get the names of any generated keys + * Get the names of any generated keys. */ public String[] getGeneratedKeyNames() { return this.generatedKeyNames; @@ -226,14 +226,14 @@ public abstract class AbstractJdbcInsert { } /** - * Get the insert string to be used + * Get the insert string to be used. */ public String getInsertString() { return this.insertString; } /** - * Get the array of {@link java.sql.Types} to be used for insert + * Get the array of {@link java.sql.Types} to be used for insert. */ public int[] getInsertTypes() { return this.insertTypes;