-
Notifications
You must be signed in to change notification settings - Fork 22
Query parameter types
Zsolt Herpai edited this page Aug 7, 2017
·
4 revisions
Queries accept the following types as parameters:
- standard jdbc supported types (like Integer, Long, String, BigDecimal, java.sql.Date, primitives, ...)
- java.time types
- any custom types - requires custom ParamSetters
Eg:
query
.update("UPDATE CUSTOMER SET DEADLINE = ?, UPDATED = ?")
.params(LocalDate.of(2015, Month.MARCH, 5), Instant.now())
.run();
Support for more types - eg value objects - can be implemented using the ParamSetter interface and can be configured with FluentJdbcBuilder:
Map<Class, ParamSetter> paramSetters = ...
FluentJdbc fluentJdbc = new FluentJdbcBuilder()
.paramSetters(paramSetters)
... // other configuration
.build();
ParamSetter uuidParamSetter = (param, preparedStatement, i) -> {
preparedStatement.setString(i, param.toString());
}
Map<Class, ParamSetter> paramSetters = new HashMap<>();
paramSetters.put(UUID.class, uuidParamSetter);
... // add any other setters
FluentJdbc fluentJdbc = new FluentJdbcBuilder()
.paramSetters(paramSetters)
... // other configuration
.build();
The Query API initialized by this FluentJdbc instance will support the UUID class
query.update("UPDATE CUSTOMER SET CUSTOMER_KEY = ?").params(UUID.randomUUID).run();