Top Description Inners Fields Constructors Methods
org.springframework.jdbc.core

public Class PreparedStatementCreatorFactory

extends Object
Class Inheritance
Imports
java.sql.Connection, .PreparedStatement, .ResultSet, .SQLException, .Statement, .Types, java.util.ArrayList, .Arrays, .Collections, .HashSet, .List, .Set, org.springframework.dao.InvalidDataAccessApiUsageException, org.springframework.lang.Nullable

Helper class that efficiently creates multiple PreparedStatementCreator objects with different parameters based on an SQL statement and a single set of parameter declarations.
Authors
Rod Johnson, Thomas Risberg, Juergen Hoeller

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
PreparedStatementCreatorFactory.PreparedStatementCreatorImpl

PreparedStatementCreator implementation returned by this class.

Field Summary

Modifier and TypeField and Description
private List<SqlParameter>
declaredParameters

List of SqlParameter objects (may be null).

private String[]
private int
private boolean
private final String
sql

The SQL, which won't change when the parameters change.

private boolean

Constructor Summary

AccessConstructor and Description
public
PreparedStatementCreatorFactory(String
the SQL statement to execute
sql
)

Create a new factory.

public
PreparedStatementCreatorFactory(String
the SQL statement to execute
sql
,
int...
int array of JDBC types
types
)

Create a new factory with the given SQL and JDBC types.

public
PreparedStatementCreatorFactory(String
the SQL statement to execute
sql
,
List<SqlParameter>
list of SqlParameter objects
declaredParameters
)

Create a new factory with the given SQL and parameters.

Method Summary

Modifier and TypeMethod and Description
public void
addParameter(SqlParameter
the parameter to add to the list of declared parameters
param
)

Add a new declared parameter.

public final String
getSql()

Return the SQL statement to execute.

public PreparedStatementCreator
newPreparedStatementCreator(List<?>
list of parameters (may be null)
params
)

Return a new PreparedStatementCreator for the given parameters.

public PreparedStatementCreator
newPreparedStatementCreator(Object[]
the parameter array (may be null)
params
)

Return a new PreparedStatementCreator for the given parameters.

public PreparedStatementCreator
newPreparedStatementCreator(String
the actual SQL statement to use (if different from the factory's, for example because of named parameter expanding)
sqlToUse
,
Object[]
the parameter array (may be null)
params
)

Return a new PreparedStatementCreator for the given parameters.

public PreparedStatementSetter
newPreparedStatementSetter(List<?>
list of parameters (may be null)
params
)

Return a new PreparedStatementSetter for the given parameters.

public PreparedStatementSetter
newPreparedStatementSetter(Object[]
the parameter array (may be null)
params
)

Return a new PreparedStatementSetter for the given parameters.

public void
setGeneratedKeysColumnNames(String... names)

Set the column names of the auto-generated keys.

public void
setResultSetType(int
the ResultSet type
resultSetType
)

Set whether to use prepared statements that return a specific type of ResultSet.

public void
setReturnGeneratedKeys(boolean returnGeneratedKeys)

Set whether prepared statements should be capable of returning auto-generated keys.

public void
setUpdatableResults(boolean updatableResults)

Set whether to use prepared statements capable of returning updatable ResultSets.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

declaredParametersback to summary
private List<SqlParameter> declaredParameters

List of SqlParameter objects (may be null).

Annotations
@Nullable
generatedKeysColumnNamesback to summary
private String[] generatedKeysColumnNames
Annotations
@Nullable
resultSetTypeback to summary
private int resultSetType
returnGeneratedKeysback to summary
private boolean returnGeneratedKeys
sqlback to summary
private final String sql

The SQL, which won't change when the parameters change.

updatableResultsback to summary
private boolean updatableResults

Constructor Detail

PreparedStatementCreatorFactoryback to summary
public PreparedStatementCreatorFactory(String sql)

Create a new factory. Will need to add parameters via the addParameter method or have no parameters.

Parameters
sql:String

the SQL statement to execute

PreparedStatementCreatorFactoryback to summary
public PreparedStatementCreatorFactory(String sql, int... types)

Create a new factory with the given SQL and JDBC types.

Parameters
sql:String

the SQL statement to execute

types:int[]

int array of JDBC types

PreparedStatementCreatorFactoryback to summary
public PreparedStatementCreatorFactory(String sql, List<SqlParameter> declaredParameters)

Create a new factory with the given SQL and parameters.

Parameters
sql:String

the SQL statement to execute

declaredParameters:List<SqlParameter>

list of SqlParameter objects

Method Detail

addParameterback to summary
public void addParameter(SqlParameter param)

Add a new declared parameter.

Order of parameter addition is significant.

Parameters
param:SqlParameter

the parameter to add to the list of declared parameters

getSqlback to summary
public final String getSql()

Return the SQL statement to execute.

Since
5.1.3
newPreparedStatementCreatorback to summary
public PreparedStatementCreator newPreparedStatementCreator(List<?> params)

Return a new PreparedStatementCreator for the given parameters.

Parameters
params:List<?>

list of parameters (may be null)

newPreparedStatementCreatorback to summary
public PreparedStatementCreator newPreparedStatementCreator(Object[] params)

Return a new PreparedStatementCreator for the given parameters.

Parameters
params:Object[]

the parameter array (may be null)

newPreparedStatementCreatorback to summary
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object[] params)

Return a new PreparedStatementCreator for the given parameters.

Parameters
sqlToUse:String

the actual SQL statement to use (if different from the factory's, for example because of named parameter expanding)

params:Object[]

the parameter array (may be null)

newPreparedStatementSetterback to summary
public PreparedStatementSetter newPreparedStatementSetter(List<?> params)

Return a new PreparedStatementSetter for the given parameters.

Parameters
params:List<?>

list of parameters (may be null)

newPreparedStatementSetterback to summary
public PreparedStatementSetter newPreparedStatementSetter(Object[] params)

Return a new PreparedStatementSetter for the given parameters.

Parameters
params:Object[]

the parameter array (may be null)

setGeneratedKeysColumnNamesback to summary
public void setGeneratedKeysColumnNames(String... names)

Set the column names of the auto-generated keys.

setResultSetTypeback to summary
public void setResultSetType(int resultSetType)

Set whether to use prepared statements that return a specific type of ResultSet.

Parameters
resultSetType:int

the ResultSet type

See Also
java.sql.ResultSet#TYPE_FORWARD_ONLY, java.sql.ResultSet#TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet#TYPE_SCROLL_SENSITIVE
setReturnGeneratedKeysback to summary
public void setReturnGeneratedKeys(boolean returnGeneratedKeys)

Set whether prepared statements should be capable of returning auto-generated keys.

setUpdatableResultsback to summary
public void setUpdatableResults(boolean updatableResults)

Set whether to use prepared statements capable of returning updatable ResultSets.

org.springframework.jdbc.core back to summary

private Class PreparedStatementCreatorFactory.PreparedStatementCreatorImpl

extends Object
implements PreparedStatementCreator, PreparedStatementSetter, SqlProvider, ParameterDisposer
Class Inheritance
  • java.lang.Object
  • org.springframework.jdbc.core.PreparedStatementCreatorFactory.PreparedStatementCreatorImpl
All Implemented Interfaces
org.springframework.jdbc.core.ParameterDisposer, org.springframework.jdbc.core.SqlProvider, org.springframework.jdbc.core.PreparedStatementSetter, org.springframework.jdbc.core.PreparedStatementCreator

PreparedStatementCreator implementation returned by this class.

Field Summary

Modifier and TypeField and Description
private final String
private final List<?>

Constructor Summary

AccessConstructor and Description
public
public
PreparedStatementCreatorImpl(String actualSql, List<?> parameters)

Method Summary

Modifier and TypeMethod and Description
public void
cleanupParameters()

Implements org.springframework.jdbc.core.ParameterDisposer.cleanupParameters.

Close the resources allocated by parameters that the implementing object holds, for example in case of a DisposableSqlTypeValue (like an SqlLobValue).

public PreparedStatement
createPreparedStatement(Connection
the connection used to create statement
con
)

Implements org.springframework.jdbc.core.PreparedStatementCreator.createPreparedStatement.

Create a statement in this connection.

public String
getSql()

Implements org.springframework.jdbc.core.SqlProvider.getSql.

Return the SQL string for this object, i.e. typically the SQL used for creating statements.

public void
setValues(PreparedStatement
the PreparedStatement to invoke setter methods on
ps
)

Implements org.springframework.jdbc.core.PreparedStatementSetter.setValues.

Set parameter values on the given PreparedStatement.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

actualSqlback to summary
private final String actualSql
parametersback to summary
private final List<?> parameters

Constructor Detail

PreparedStatementCreatorImplback to summary
public PreparedStatementCreatorImpl(List<?> parameters)
PreparedStatementCreatorImplback to summary
public PreparedStatementCreatorImpl(String actualSql, List<?> parameters)

Method Detail

cleanupParametersback to summary
public void cleanupParameters()

Implements org.springframework.jdbc.core.ParameterDisposer.cleanupParameters.

Doc from org.springframework.jdbc.core.ParameterDisposer.cleanupParameters.

Close the resources allocated by parameters that the implementing object holds, for example in case of a DisposableSqlTypeValue (like an SqlLobValue).

Annotations
@Override
createPreparedStatementback to summary
public PreparedStatement createPreparedStatement(Connection con) throws SQLException

Implements org.springframework.jdbc.core.PreparedStatementCreator.createPreparedStatement.

Doc from org.springframework.jdbc.core.PreparedStatementCreator.createPreparedStatement.

Create a statement in this connection. Allows implementations to use PreparedStatements. The JdbcTemplate will close the created statement.

Parameters
con:Connection

the connection used to create statement

Returns:PreparedStatement

a prepared statement

Annotations
@Override
Exceptions
SQLException:
there is no need to catch SQLExceptions that may be thrown in the implementation of this method. The JdbcTemplate class will handle them.
getSqlback to summary
public String getSql()

Implements org.springframework.jdbc.core.SqlProvider.getSql.

Doc from org.springframework.jdbc.core.SqlProvider.getSql.

Return the SQL string for this object, i.e. typically the SQL used for creating statements.

Returns:String

the SQL string, or null if not available

Annotations
@Override
setValuesback to summary
public void setValues(PreparedStatement ps) throws SQLException

Implements org.springframework.jdbc.core.PreparedStatementSetter.setValues.

Doc from org.springframework.jdbc.core.PreparedStatementSetter.setValues.

Set parameter values on the given PreparedStatement.

Parameters
ps:PreparedStatement

the PreparedStatement to invoke setter methods on

Annotations
@Override
Exceptions
SQLException:
if an SQLException is encountered (i.e. there is no need to catch SQLException)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override