Interface PreparedStatementBinder
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Contract for binding parameters to SQL prepared statements.
A production-ready concrete implementation is available via the following static methods:
How to acquire an instance: // With out-of-the-box defaults
PreparedStatementBinder default = PreparedStatementBinder.withDefaultConfiguration();
// Customized
PreparedStatementBinder custom = PreparedStatementBinder.withCustomParameterBinders(List.of(...));
Or, implement your own: PreparedStatementBinder myImpl = new PreparedStatementBinder() {
@Override
<T> void bindParameter(
@Nonnull StatementContext<T> statementContext,
@Nonnull PreparedStatement preparedStatement,
@Nonnull Integer parameterIndex,
@Nonnull Object parameter
) throws SQLException {
// TODO: your own code that binds the parameter at the specified index to the PreparedStatement
}
};
- Since:
- 1.0.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescription<T> void
bindParameter
(StatementContext<T> statementContext, PreparedStatement preparedStatement, Integer parameterIndex, Object parameter) Binds a single parameter to a SQL prepared statement.static PreparedStatementBinder
withCustomParameterBinders
(List<CustomParameterBinder> customParameterBinders) Acquires a concrete implementation of this interface, specifying "surgical" per-type custom parameter binders.static PreparedStatementBinder
Acquires a concrete implementation of this interface with out-of-the-box defaults.
-
Method Details
-
bindParameter
<T> void bindParameter(@Nonnull StatementContext<T> statementContext, @Nonnull PreparedStatement preparedStatement, @Nonnull Integer parameterIndex, @Nonnull Object parameter) throws SQLException Binds a single parameter to a SQL prepared statement.This function is only invoked when
parameter
is non-null.- Parameters:
statementContext
- current SQL contextpreparedStatement
- the prepared statement to bind toparameterIndex
- the index of the parameter we are bindingparameter
- the parameter we are binding to thePreparedStatement
, if any- Throws:
SQLException
- if an error occurs during binding
-
withDefaultConfiguration
Acquires a concrete implementation of this interface with out-of-the-box defaults.The returned instance is thread-safe.
- Returns:
- a concrete implementation of this interface with out-of-the-box defaults
-
withCustomParameterBinders
@Nonnull static PreparedStatementBinder withCustomParameterBinders(@Nonnull List<CustomParameterBinder> customParameterBinders) Acquires a concrete implementation of this interface, specifying "surgical" per-type custom parameter binders.The returned instance is thread-safe.
- Parameters:
customParameterBinders
- the "surgical" per-type custom parameter binders- Returns:
- a concrete implementation of this interface
-