public interface SqlTemplate<I,R>
SQL templates are useful for interacting with a relational database.
SQL templates execute queries using named instead of positional parameters. Query execution is parameterized
by a map of string to objects instead of a Tuple
. The default source of parameters is a
simple map, a user defined mapping can be used instead given it maps the source to such a map.
SQL template default results are Row
, a user defined mapping can be used instead, mapping the
result set Row
to a RowSet
of the mapped type.
Modifier and Type | Method and Description |
---|---|
<U> SqlTemplate<I,SqlResult<U>> |
collecting(java.util.stream.Collector<Row,?,U> collector)
Set a collector that will process the output and produce a custom result.
|
Future<R> |
execute(I params)
Like
execute(Object, Handler) but returns a Future of the asynchronous result |
void |
execute(I parameters,
Handler<AsyncResult<R>> handler)
Execute the query with the
parameters |
Future<R> |
executeBatch(List<I> batch)
Like
executeBatch(List, Handler) but returns a Future of the asynchronous result |
void |
executeBatch(List<I> batch,
Handler<AsyncResult<R>> handler)
Execute a batch query with the
batch . |
static SqlTemplate<Map<String,Object>,RowSet<Row>> |
forQuery(SqlClient client,
String template)
Create an SQL template for query purpose consuming map parameters and returning
Row . |
static SqlTemplate<Map<String,Object>,SqlResult<Void>> |
forUpdate(SqlClient client,
String template)
Create an SQL template for query purpose consuming map parameters and returning void.
|
default <T> SqlTemplate<T,R> |
mapFrom(Class<T> type)
Set a parameters user defined class mapping.
|
<T> SqlTemplate<T,R> |
mapFrom(TupleMapper<T> mapper)
Set a parameters user defined mapping function.
|
<U> SqlTemplate<I,RowSet<U>> |
mapTo(Class<U> type)
Set a row user defined mapping function.
|
<U> SqlTemplate<I,RowSet<U>> |
mapTo(RowMapper<U> mapper)
Set a row user defined mapping function.
|
static SqlTemplate<Map<String,Object>,RowSet<Row>> forQuery(SqlClient client, String template)
Row
.client
- the wrapped SQL clienttemplate
- the template query stringstatic SqlTemplate<Map<String,Object>,SqlResult<Void>> forUpdate(SqlClient client, String template)
client
- the wrapped SQL clienttemplate
- the template update string<T> SqlTemplate<T,R> mapFrom(TupleMapper<T> mapper)
At query execution, the mapper
is called to map the parameters object
to a Tuple
that configures the prepared query.
mapper
- the mapping functiondefault <T> SqlTemplate<T,R> mapFrom(Class<T> type)
At query execution, the parameters object is is mapped to a Map<String, Object>
that
configures the prepared query.
This feature relies on JsonObject.mapFrom(java.lang.Object)
feature. This likely requires
to use Jackson databind in the project.
type
- the mapping type<U> SqlTemplate<I,RowSet<U>> mapTo(RowMapper<U> mapper)
When the query execution completes, the mapper
function is called to map the resulting
rows to objects.
mapper
- the mapping function<U> SqlTemplate<I,RowSet<U>> mapTo(Class<U> type)
When the query execution completes, resulting rows are mapped to type
instances.
This feature relies on JsonObject.mapFrom(java.lang.Object)
feature. This likely requires
to use Jackson databind in the project.
type
- the mapping type<U> SqlTemplate<I,SqlResult<U>> collecting(java.util.stream.Collector<Row,?,U> collector)
collector
- the collectorvoid execute(I parameters, Handler<AsyncResult<R>> handler)
parameters
parameters
- the query parametershandler
- the result handlerFuture<R> execute(I params)
execute(Object, Handler)
but returns a Future
of the asynchronous resultvoid executeBatch(List<I> batch, Handler<AsyncResult<R>> handler)
batch
.
Each item in the batch is mapped to a tuple.
batch
- the batchhandler
- the result handlerFuture<R> executeBatch(List<I> batch)
executeBatch(List, Handler)
but returns a Future
of the asynchronous resultCopyright © 2023 Eclipse. All rights reserved.