Package org.springframework.jdbc.core
Class PreparedStatementCreatorFactory
java.lang.Object
org.springframework.jdbc.core.PreparedStatementCreatorFactory
Helper class that efficiently creates multiple
PreparedStatementCreator
objects with different parameters based on an SQL statement and a single
set of parameter declarations.- Author:
- Rod Johnson, Thomas Risberg, Juergen Hoeller
-
Constructor Summary
ConstructorDescriptionCreate a new factory.PreparedStatementCreatorFactory
(String sql, int... types) Create a new factory with the given SQL and JDBC types.PreparedStatementCreatorFactory
(String sql, List<SqlParameter> declaredParameters) Create a new factory with the given SQL and parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addParameter
(SqlParameter param) Add a new declared parameter.final String
getSql()
Return the SQL statement to execute.newPreparedStatementCreator
(Object[] params) Return a new PreparedStatementCreator for the given parameters.newPreparedStatementCreator
(String sqlToUse, Object[] params) Return a new PreparedStatementCreator for the given parameters.newPreparedStatementCreator
(List<?> params) Return a new PreparedStatementCreator for the given parameters.newPreparedStatementSetter
(Object[] params) Return a new PreparedStatementSetter for the given parameters.newPreparedStatementSetter
(List<?> params) Return a new PreparedStatementSetter for the given parameters.void
setGeneratedKeysColumnNames
(String... names) Set the column names of the auto-generated keys.void
setResultSetType
(int resultSetType) Set whether to use prepared statements that return a specific type of ResultSet.void
setReturnGeneratedKeys
(boolean returnGeneratedKeys) Set whether prepared statements should be capable of returning auto-generated keys.void
setUpdatableResults
(boolean updatableResults) Set whether to use prepared statements capable of returning updatable ResultSets.
-
Constructor Details
-
PreparedStatementCreatorFactory
Create a new factory. Will need to add parameters via theaddParameter(org.springframework.jdbc.core.SqlParameter)
method or have no parameters.- Parameters:
sql
- the SQL statement to execute
-
PreparedStatementCreatorFactory
Create a new factory with the given SQL and JDBC types.- Parameters:
sql
- the SQL statement to executetypes
- int array of JDBC types
-
PreparedStatementCreatorFactory
Create a new factory with the given SQL and parameters.- Parameters:
sql
- the SQL statement to executedeclaredParameters
- list ofSqlParameter
objects
-
-
Method Details
-
getSql
Return the SQL statement to execute.- Since:
- 5.1.3
-
addParameter
Add a new declared parameter.Order of parameter addition is significant.
- Parameters:
param
- the parameter to add to the list of declared parameters
-
setResultSetType
public void setResultSetType(int resultSetType) Set whether to use prepared statements that return a specific type of ResultSet.- Parameters:
resultSetType
- the ResultSet type- See Also:
-
setUpdatableResults
public void setUpdatableResults(boolean updatableResults) Set whether to use prepared statements capable of returning updatable ResultSets. -
setReturnGeneratedKeys
public void setReturnGeneratedKeys(boolean returnGeneratedKeys) Set whether prepared statements should be capable of returning auto-generated keys. -
setGeneratedKeysColumnNames
Set the column names of the auto-generated keys. -
newPreparedStatementSetter
Return a new PreparedStatementSetter for the given parameters.- Parameters:
params
- list of parameters (may benull
)
-
newPreparedStatementSetter
Return a new PreparedStatementSetter for the given parameters.- Parameters:
params
- the parameter array (may benull
)
-
newPreparedStatementCreator
Return a new PreparedStatementCreator for the given parameters.- Parameters:
params
- list of parameters (may benull
)
-
newPreparedStatementCreator
Return a new PreparedStatementCreator for the given parameters.- Parameters:
params
- the parameter array (may benull
)
-
newPreparedStatementCreator
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, @Nullable Object[] params) Return a new PreparedStatementCreator for the given parameters.- Parameters:
sqlToUse
- the actual SQL statement to use (if different from the factory's, for example because of named parameter expanding)params
- the parameter array (may benull
)
-