public interface Sql
extends me.lucko.helper.terminable.Terminable
| Modifier and Type | Method and Description |
|---|---|
BatchBuilder |
batch(String statement)
Gets a
BatchBuilder for the provided statement. |
default void |
execute(String statement)
Executes a database statement with no preparation.
|
void |
execute(String statement,
be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer)
Executes a database statement with preparation.
|
default me.lucko.helper.promise.Promise<Void> |
executeAsync(String statement)
Executes a database statement with no preparation.
|
default me.lucko.helper.promise.Promise<Void> |
executeAsync(String statement,
be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer)
Executes a database statement with preparation.
|
void |
executeBatch(BatchBuilder builder)
Executes a batched database execution.
|
default me.lucko.helper.promise.Promise<Void> |
executeBatchAsync(BatchBuilder builder)
Executes a batched database execution.
|
Connection |
getConnection()
Gets a connection from the datasource.
|
com.zaxxer.hikari.HikariDataSource |
getHikari()
Gets the Hikari instance backing the datasource
|
<R> Optional<R> |
query(String query,
be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer,
be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
Executes a database query with preparation.
|
default <R> Optional<R> |
query(String query,
be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
Executes a database query with no preparation.
|
default <R> me.lucko.helper.promise.Promise<Optional<R>> |
queryAsync(String query,
be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer,
be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
Executes a database query with preparation.
|
default <R> me.lucko.helper.promise.Promise<Optional<R>> |
queryAsync(String query,
be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
Executes a database query with no preparation.
|
be.bendem.sqlstreams.SqlStream |
stream()
Gets a
SqlStream instance for this Sql. |
@Nonnull com.zaxxer.hikari.HikariDataSource getHikari()
@Nonnull Connection getConnection() throws SQLException
The connection should be returned once it has been used.
SQLException@Nonnull be.bendem.sqlstreams.SqlStream stream()
SqlStream instance for this Sql.@Nonnull default me.lucko.helper.promise.Promise<Void> executeAsync(@Nonnull String statement)
This will be executed on an asynchronous thread.
statement - the statement to be executedto perform this action synchronouslydefault void execute(@Nonnull String statement)
This will be executed on whichever thread it's called from.
statement - the statement to be executedto perform the same action asynchronously@Nonnull default me.lucko.helper.promise.Promise<Void> executeAsync(@Nonnull String statement, @Nonnull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer)
This will be executed on an asynchronous thread.
statement - the statement to be executedpreparer - the preparation used for this statementto perform this action synchronouslyvoid execute(@Nonnull String statement, @Nonnull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer)
This will be executed on whichever thread it's called from.
statement - the statement to be executedpreparer - the preparation used for this statementto perform this action asynchronouslydefault <R> me.lucko.helper.promise.Promise<Optional<R>> queryAsync(@Nonnull String query, @Nonnull be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
This will be executed on an asynchronous thread.
In the case of a SQLException or in the case of
no data being returned, or the handler evaluating to null,
this method will return an Optional.empty() object.
R - the returned typequery - the query to be executedhandler - the handler for the data returned by the queryto perform this query synchronouslydefault <R> Optional<R> query(@Nonnull String query, @Nonnull be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
This will be executed on whichever thread it's called from.
In the case of a SQLException or in the case of
no data being returned, or the handler evaluating to null,
this method will return an Optional.empty() object.
R - the returned typequery - the query to be executedhandler - the handler for the data returned by the queryto perform this query asynchronouslydefault <R> me.lucko.helper.promise.Promise<Optional<R>> queryAsync(@Nonnull String query, @Nonnull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer, @Nonnull be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
This will be executed on an asynchronous thread.
In the case of a SQLException or in the case of
no data being returned, or the handler evaluating to null,
this method will return an Optional.empty() object.
R - the returned typequery - the query to be executedpreparer - the preparation used for this statementhandler - the handler for the data returned by the queryto perform this query synchronously<R> Optional<R> query(@Nonnull String query, @Nonnull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer, @Nonnull be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
This will be executed on whichever thread it's called from.
In the case of a SQLException or in the case of
no data being returned, or the handler evaluating to null,
this method will return an Optional.empty() object.
R - the returned typequery - the query to be executedpreparer - the preparation used for this statementhandler - the handler for the data returned by the queryto perform this query asynchronouslydefault me.lucko.helper.promise.Promise<Void> executeBatchAsync(@Nonnull BatchBuilder builder)
This will be executed on an asynchronous thread.
Note that proper implementations of this method should determine
if the provided BatchBuilder is actually worth of being a
batched statement. For instance, a BatchBuilder with only one
handler can safely be referred to executeAsync(String, SqlConsumer)
builder - the builder to be used.to perform this action synchronouslyvoid executeBatch(@Nonnull BatchBuilder builder)
This will be executed on whichever thread it's called from.
Note that proper implementations of this method should determine
if the provided BatchBuilder is actually worth of being a
batched statement. For instance, a BatchBuilder with only one
handler can safely be referred to execute(String, SqlConsumer)
builder - the builder to be used.to perform this action asynchronouslyBatchBuilder batch(@Nonnull String statement)
BatchBuilder for the provided statement.statement - the statement to prepare for batching.Copyright © 2019. All rights reserved.