Interface ISql

All Superinterfaces:
AutoCloseable, dev.demeng.pluginbase.terminable.Terminable
All Known Implementing Classes:
Sql

public interface ISql extends dev.demeng.pluginbase.terminable.Terminable
  • Field Summary

    Fields inherited from interface dev.demeng.pluginbase.terminable.Terminable

    EMPTY
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull BatchBuilder
    batch(@NotNull String statement)
    Gets a BatchBuilder for the provided statement.
    default void
    execute(@NotNull String statement)
    Executes a database statement with no preparation.
    void
    execute(@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.
    void
    executeBatch(@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 Connection
    Gets a connection from the datasource.
    @NotNull com.zaxxer.hikari.HikariDataSource
    Gets 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>
    query(@NotNull String query, @NotNull be.bendem.sqlstreams.util.SqlFunction<ResultSet,R> handler)
    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.SqlStream
    Gets a SqlStream instance for this ISql.

    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

      @NotNull @NotNull Connection getConnection() throws SQLException
      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 a SqlStream instance for this ISql.
      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

      default void execute(@Language("SQL") @NotNull @NotNull String statement)
      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 executed
      preparer - 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 executed
      preparer - 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 SQLException or in the case of no data being returned, or the handler evaluating to null, this method will return an Optional.empty() object.

      Type Parameters:
      R - The returned type
      Parameters:
      query - The query to be executed
      handler - 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 SQLException or in the case of no data being returned, or the handler evaluating to null, this method will return an Optional.empty() object.

      Type Parameters:
      R - The returned type
      Parameters:
      query - The query to be executed
      handler - 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 SQLException or in the case of no data being returned, or the handler evaluating to null, this method will return an Optional.empty() object.

      Type Parameters:
      R - The returned type
      Parameters:
      query - The query to be executed
      preparer - The preparation used for this statement
      handler - 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 SQLException or in the case of no data being returned, or the handler evaluating to null, this method will return an Optional.empty() object.

      Type Parameters:
      R - The returned type
      Parameters:
      query - The query to be executed
      preparer - The preparation used for this statement
      handler - 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 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)

      Parameters:
      builder - The builder to be used.
      Returns:
      A Promise of an asynchronous batched database execution
      See Also:
    • executeBatch

      void executeBatch(@NotNull @NotNull BatchBuilder builder)
      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 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)

      Parameters:
      builder - The builder to be used.
      See Also:
    • batch

      @NotNull @NotNull BatchBuilder batch(@Language("SQL") @NotNull @NotNull String statement)
      Gets a BatchBuilder for the provided statement.
      Parameters:
      statement - the statement to prepare for batching.
      Returns:
      a BatchBuilder