Package co.aikar.idb

Interface Database

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void close()
      Called in onDisable, destroys the Data source and nulls out references.
      void close​(long timeout, java.util.concurrent.TimeUnit unit)
      Called in onDisable, destroys the Data source and nulls out references.
      default void closeConnection​(java.sql.Connection conn)  
      default DbStatement createStatement()
      Initiates a new DbStatement
      default boolean createTransaction​(TransactionCallback run)  
      default void createTransactionAsync​(TransactionCallback run)  
      default void createTransactionAsync​(TransactionCallback run, java.lang.Runnable onSuccess, java.lang.Runnable onFail)  
      <T> java.util.concurrent.CompletableFuture<T> dispatchAsync​(java.util.concurrent.Callable<T> task)  
      default java.lang.Long executeInsert​(java.lang.String query, java.lang.Object... params)
      Utility method for executing an update synchronously that does an insert, closes the statement, and returns the last insert ID.
      default int executeUpdate​(java.lang.String query, java.lang.Object... params)
      Utility method for executing an update synchronously, and then close the statement.
      default java.util.concurrent.CompletableFuture<java.lang.Integer> executeUpdateAsync​(java.lang.String query, java.lang.Object... params)
      Utility method to execute an update statement asynchronously and close the connection.
      default void fatalError​(java.lang.Exception e)  
      java.sql.Connection getConnection()
      Get a JDBC Connection
      default <T> T getFirstColumn​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve the first column of the first row, then close statement.
      default <T> java.util.concurrent.CompletableFuture<T> getFirstColumnAsync​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve the first column of the first row, then close statement.
      default <T> java.util.List<T> getFirstColumnResults​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve first column of all results, then close statement.
      default <T> java.util.concurrent.CompletableFuture<java.util.List<T>> getFirstColumnResultsAsync​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve first column of all results, then close statement.
      default DbRow getFirstRow​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve the first row, then close statement.
      default java.util.concurrent.CompletableFuture<DbRow> getFirstRowAsync​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve the first row, then close statement.
      java.util.logging.Logger getLogger()
      Get the Logger
      DatabaseOptions getOptions()
      Get the options object
      default java.util.List<DbRow> getResults​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve all results, then close statement.
      default java.util.concurrent.CompletableFuture<java.util.List<DbRow>> getResultsAsync​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve all results, then close statement.
      default void logException​(java.lang.Exception e)  
      default void logException​(java.lang.String message, java.lang.Exception e)  
      default DbStatement query​(java.lang.String query)
      Initiates a new DbStatement and prepares the first query.
      default java.util.concurrent.CompletableFuture<DbStatement> queryAsync​(java.lang.String query)
      Initiates a new DbStatement and prepares the first query.
      DatabaseTiming timings​(java.lang.String name)
      Create a Timings object
    • Method Detail

      • close

        default void close()
        Called in onDisable, destroys the Data source and nulls out references.
      • close

        void close​(long timeout,
                   java.util.concurrent.TimeUnit unit)
        Called in onDisable, destroys the Data source and nulls out references.
      • dispatchAsync

        <T> java.util.concurrent.CompletableFuture<T> dispatchAsync​(java.util.concurrent.Callable<T> task)
      • getConnection

        java.sql.Connection getConnection()
                                   throws java.sql.SQLException
        Get a JDBC Connection
        Throws:
        java.sql.SQLException
      • timings

        DatabaseTiming timings​(java.lang.String name)
        Create a Timings object
      • getLogger

        java.util.logging.Logger getLogger()
        Get the Logger
      • fatalError

        default void fatalError​(java.lang.Exception e)
      • closeConnection

        default void closeConnection​(java.sql.Connection conn)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • createStatement

        default DbStatement createStatement()
                                     throws java.sql.SQLException
        Initiates a new DbStatement

        YOU MUST MANUALLY CLOSE THIS STATEMENT IN A finally {} BLOCK!

        Throws:
        java.sql.SQLException
      • query

        default DbStatement query​(java.lang.String query)
                           throws java.sql.SQLException
        Initiates a new DbStatement and prepares the first query.

        YOU MUST MANUALLY CLOSE THIS STATEMENT IN A finally {} BLOCK!

        Throws:
        java.sql.SQLException
      • queryAsync

        default java.util.concurrent.CompletableFuture<DbStatement> queryAsync​(java.lang.String query)
        Initiates a new DbStatement and prepares the first query.

        YOU MUST MANUALLY CLOSE THIS STATEMENT IN A finally {} BLOCK!

      • getFirstRow

        default DbRow getFirstRow​(java.lang.String query,
                                  java.lang.Object... params)
                           throws java.sql.SQLException
        Utility method to execute a query and retrieve the first row, then close statement. You should ensure result will only return 1 row for maximum performance.
        Parameters:
        query - The query to run
        params - The parameters to execute the statement with
        Returns:
        DbRow of your results (HashMap with template return type)
        Throws:
        java.sql.SQLException
      • getFirstRowAsync

        default java.util.concurrent.CompletableFuture<DbRow> getFirstRowAsync​(java.lang.String query,
                                                                               java.lang.Object... params)
        Utility method to execute a query and retrieve the first row, then close statement. You should ensure result will only return 1 row for maximum performance.
        Parameters:
        query - The query to run
        params - The parameters to execute the statement with
        Returns:
        DbRow of your results (HashMap with template return type)
      • getFirstColumn

        default <T> T getFirstColumn​(java.lang.String query,
                                     java.lang.Object... params)
                              throws java.sql.SQLException
        Utility method to execute a query and retrieve the first column of the first row, then close statement. You should ensure result will only return 1 row for maximum performance.
        Parameters:
        query - The query to run
        params - The parameters to execute the statement with
        Returns:
        DbRow of your results (HashMap with template return type)
        Throws:
        java.sql.SQLException
      • getFirstColumnAsync

        default <T> java.util.concurrent.CompletableFuture<T> getFirstColumnAsync​(java.lang.String query,
                                                                                  java.lang.Object... params)
        Utility method to execute a query and retrieve the first column of the first row, then close statement. You should ensure result will only return 1 row for maximum performance.
        Parameters:
        query - The query to run
        params - The parameters to execute the statement with
        Returns:
        DbRow of your results (HashMap with template return type)
      • getFirstColumnResults

        default <T> java.util.List<T> getFirstColumnResults​(java.lang.String query,
                                                            java.lang.Object... params)
                                                     throws java.sql.SQLException
        Utility method to execute a query and retrieve first column of all results, then close statement.

        Meant for single queries that will not use the statement multiple times.

        Throws:
        java.sql.SQLException
      • getFirstColumnResultsAsync

        default <T> java.util.concurrent.CompletableFuture<java.util.List<T>> getFirstColumnResultsAsync​(java.lang.String query,
                                                                                                         java.lang.Object... params)
        Utility method to execute a query and retrieve first column of all results, then close statement.

        Meant for single queries that will not use the statement multiple times.

      • getResults

        default java.util.List<DbRow> getResults​(java.lang.String query,
                                                 java.lang.Object... params)
                                          throws java.sql.SQLException
        Utility method to execute a query and retrieve all results, then close statement.

        Meant for single queries that will not use the statement multiple times.

        Parameters:
        query - The query to run
        params - The parameters to execute the statement with
        Returns:
        List of DbRow of your results (HashMap with template return type)
        Throws:
        java.sql.SQLException
      • getResultsAsync

        default java.util.concurrent.CompletableFuture<java.util.List<DbRow>> getResultsAsync​(java.lang.String query,
                                                                                              java.lang.Object... params)
        Utility method to execute a query and retrieve all results, then close statement.

        Meant for single queries that will not use the statement multiple times.

        Parameters:
        query - The query to run
        params - The parameters to execute the statement with
        Returns:
        List of DbRow of your results (HashMap with template return type)
      • executeInsert

        default java.lang.Long executeInsert​(java.lang.String query,
                                             java.lang.Object... params)
                                      throws java.sql.SQLException
        Utility method for executing an update synchronously that does an insert, closes the statement, and returns the last insert ID.
        Parameters:
        query - Query to run
        params - Params to execute the statement with.
        Returns:
        Inserted Row Id.
        Throws:
        java.sql.SQLException
      • executeUpdate

        default int executeUpdate​(java.lang.String query,
                                  java.lang.Object... params)
                           throws java.sql.SQLException
        Utility method for executing an update synchronously, and then close the statement.
        Parameters:
        query - Query to run
        params - Params to execute the statement with.
        Returns:
        Number of rows modified.
        Throws:
        java.sql.SQLException
      • executeUpdateAsync

        default java.util.concurrent.CompletableFuture<java.lang.Integer> executeUpdateAsync​(java.lang.String query,
                                                                                             java.lang.Object... params)
        Utility method to execute an update statement asynchronously and close the connection.
        Parameters:
        query - Query to run
        params - Params to execute the update with
      • createTransactionAsync

        default void createTransactionAsync​(TransactionCallback run,
                                            java.lang.Runnable onSuccess,
                                            java.lang.Runnable onFail)
      • logException

        default void logException​(java.lang.String message,
                                  java.lang.Exception e)
      • logException

        default void logException​(java.lang.Exception e)