public class HelperSql extends Object implements Sql
| Constructor and Description |
|---|
HelperSql(DatabaseCredentials credentials) |
| Modifier and Type | Method and Description |
|---|---|
BatchBuilder |
batch(String statement)
Gets a
BatchBuilder for the provided statement. |
void |
close() |
void |
execute(String statement,
be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer)
Executes a database statement with preparation.
|
void |
executeBatch(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.
|
be.bendem.sqlstreams.SqlStream |
stream()
Gets a
SqlStream instance for this Sql. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexecute, executeAsync, executeAsync, executeBatchAsync, query, queryAsync, queryAsyncpublic HelperSql(@Nonnull DatabaseCredentials credentials)
@Nonnull public com.zaxxer.hikari.HikariDataSource getHikari()
Sql@Nonnull public Connection getConnection() throws SQLException
SqlThe connection should be returned once it has been used.
getConnection in interface SqlSQLException@Nonnull public be.bendem.sqlstreams.SqlStream stream()
SqlSqlStream instance for this Sql.public void execute(@Nonnull String statement, @Nonnull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer)
SqlThis will be executed on whichever thread it's called from.
execute in interface Sqlstatement - the statement to be executedpreparer - the preparation used for this statementto perform this action asynchronouslypublic <R> Optional<R> query(@Nonnull String query, @Nonnull be.bendem.sqlstreams.util.SqlConsumer<PreparedStatement> preparer, @Nonnull be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
SqlThis 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.
query in interface SqlR - 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 asynchronouslypublic void executeBatch(@Nonnull BatchBuilder builder)
SqlThis 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 Sql.execute(String, SqlConsumer)
executeBatch in interface Sqlbuilder - the builder to be used.to perform this action asynchronouslypublic BatchBuilder batch(@Nonnull String statement)
SqlBatchBuilder for the provided statement.public void close()
close in interface AutoCloseableclose in interface me.lucko.helper.terminable.TerminableCopyright © 2019. All rights reserved.