Interface ISql
- All Superinterfaces:
AutoCloseable,dev.demeng.pluginbase.terminable.Terminable
- All Known Implementing Classes:
Sql
-
Field Summary
Fields inherited from interface dev.demeng.pluginbase.terminable.Terminable
EMPTY -
Method Summary
Modifier and TypeMethodDescription@NotNull BatchBuilderGets aBatchBuilderfor the provided statement.default voidExecutes a database statement with no preparation.voidexecute(@NotNull String statement, @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer) Executes a database statement with preparation.default @NotNull dev.demeng.pluginbase.promise.Promise<Void>executeAsync(@NotNull String statement) Executes a database statement with no preparation.default @NotNull dev.demeng.pluginbase.promise.Promise<Void>executeAsync(@NotNull String statement, @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer) Executes a database statement with preparation.voidexecuteBatch(@NotNull BatchBuilder builder) Executes a batched database execution.default @NotNull dev.demeng.pluginbase.promise.Promise<Void>executeBatchAsync(@NotNull BatchBuilder builder) Executes a batched database execution.@NotNull ConnectionGets a connection from the datasource.@NotNull com.zaxxer.hikari.HikariDataSourceGets the Hikari instance backing the datasource.<R> @NotNull Optional<R>query(@NotNull String query, @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer, @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet, R> handler) Executes a database query with preparation.default <R> @NotNull Optional<R>Executes a database query with no preparation.default <R> @NotNull dev.demeng.pluginbase.promise.Promise<Optional<R>>queryAsync(@NotNull String query, @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer, @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet, R> handler) Executes a database query with preparation.default <R> @NotNull dev.demeng.pluginbase.promise.Promise<Optional<R>>queryAsync(@NotNull String query, @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet, R> handler) Executes a database query with no preparation.@NotNull be.bendem.sqlstreams.SqlStreamstream()Gets aSqlStreaminstance for thisISql.Methods inherited from interface dev.demeng.pluginbase.terminable.Terminable
bindWith, close, closeAndReportException, closeSilently, isClosed
-
Method Details
-
getHikari
@NotNull @NotNull com.zaxxer.hikari.HikariDataSource getHikari()Gets the Hikari instance backing the datasource.- Returns:
- The hikari instance
-
getConnection
Gets a connection from the datasource.The connection should be returned once it has been used.
- Returns:
- A connection
- Throws:
SQLException
-
stream
@NotNull @NotNull be.bendem.sqlstreams.SqlStream stream()Gets aSqlStreaminstance for thisISql.- Returns:
- An instance of the stream library for this connection
-
executeAsync
@NotNull default @NotNull dev.demeng.pluginbase.promise.Promise<Void> executeAsync(@Language("SQL") @NotNull @NotNull String statement) Executes a database statement with no preparation.This will be executed on an asynchronous thread.
- Parameters:
statement- The statement to be executed- Returns:
- A Promise of an asynchronous database execution
- See Also:
-
execute
Executes a database statement with no preparation.This will be executed on whichever thread it's called from.
- Parameters:
statement- The statement to be executed- See Also:
-
executeAsync
@NotNull default @NotNull dev.demeng.pluginbase.promise.Promise<Void> executeAsync(@Language("SQL") @NotNull @NotNull String statement, @NotNull @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer) Executes a database statement with preparation.This will be executed on an asynchronous thread.
- Parameters:
statement- The statement to be executedpreparer- The preparation used for this statement- Returns:
- A Promise of an asynchronous database execution
- See Also:
-
execute
void execute(@Language("SQL") @NotNull @NotNull String statement, @NotNull @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer) Executes a database statement with preparation.This will be executed on whichever thread it's called from.
- Parameters:
statement- The statement to be executedpreparer- The preparation used for this statement- See Also:
-
queryAsync
@NotNull default <R> @NotNull dev.demeng.pluginbase.promise.Promise<Optional<R>> queryAsync(@Language("SQL") @NotNull @NotNull String query, @NotNull @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet, R> handler) Executes a database query with no preparation.This will be executed on an asynchronous thread.
In the case of a
SQLExceptionor in the case of no data being returned, or the handler evaluating to null, this method will return anOptional.empty()object.- Type Parameters:
R- The returned type- Parameters:
query- The query to be executedhandler- The handler for the data returned by the query- Returns:
- A Promise of an asynchronous database query
- See Also:
-
query
@NotNull default <R> @NotNull Optional<R> query(@Language("SQL") @NotNull @NotNull String query, @NotNull @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet, R> handler) Executes a database query with no preparation.This will be executed on whichever thread it's called from.
In the case of a
SQLExceptionor in the case of no data being returned, or the handler evaluating to null, this method will return anOptional.empty()object.- Type Parameters:
R- The returned type- Parameters:
query- The query to be executedhandler- The handler for the data returned by the query- Returns:
- The results of the database query
- See Also:
-
queryAsync
@NotNull default <R> @NotNull dev.demeng.pluginbase.promise.Promise<Optional<R>> queryAsync(@Language("SQL") @NotNull @NotNull String query, @NotNull @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer, @NotNull @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet, R> handler) Executes a database query with preparation.This will be executed on an asynchronous thread.
In the case of a
SQLExceptionor in the case of no data being returned, or the handler evaluating to null, this method will return anOptional.empty()object.- Type Parameters:
R- The returned type- Parameters:
query- The query to be executedpreparer- The preparation used for this statementhandler- The handler for the data returned by the query- Returns:
- A Promise of an asynchronous database query
- See Also:
-
query
@NotNull <R> @NotNull Optional<R> query(@Language("SQL") @NotNull @NotNull String query, @NotNull @NotNull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer, @NotNull @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet, R> handler) Executes a database query with preparation.This will be executed on whichever thread it's called from.
In the case of a
SQLExceptionor in the case of no data being returned, or the handler evaluating to null, this method will return anOptional.empty()object.- Type Parameters:
R- The returned type- Parameters:
query- The query to be executedpreparer- The preparation used for this statementhandler- The handler for the data returned by the query- Returns:
- The results of the database query
- See Also:
-
executeBatchAsync
@NotNull default @NotNull dev.demeng.pluginbase.promise.Promise<Void> executeBatchAsync(@NotNull @NotNull BatchBuilder builder) Executes a batched database execution.This will be executed on an asynchronous thread.
Note that proper implementations of this method should determine if the provided
BatchBuilderis actually worth of being a batched statement. For instance, a BatchBuilder with only one handler can safely be referred toexecuteAsync(String, SqlConsumer)- Parameters:
builder- The builder to be used.- Returns:
- A Promise of an asynchronous batched database execution
- See Also:
-
executeBatch
Executes a batched database execution.This will be executed on whichever thread it's called from.
Note that proper implementations of this method should determine if the provided
BatchBuilderis actually worth of being a batched statement. For instance, a BatchBuilder with only one handler can safely be referred toexecute(String, SqlConsumer)- Parameters:
builder- The builder to be used.- See Also:
-
batch
Gets aBatchBuilderfor the provided statement.- Parameters:
statement- the statement to prepare for batching.- Returns:
- a BatchBuilder
-