Package co.aikar.idb

Class DB


  • public final class DB
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void close()
      Called in onDisable, destroys the Data source and nulls out references.
      static void close​(long timeout, java.util.concurrent.TimeUnit unit)  
      static boolean createTransaction​(TransactionCallback run)  
      static void createTransactionAsync​(TransactionCallback run)  
      static void createTransactionAsync​(TransactionCallback run, java.lang.Runnable onSuccess, java.lang.Runnable onFail)  
      static 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.
      static int executeUpdate​(java.lang.String query, java.lang.Object... params)
      Utility method for executing an update synchronously, and then close the statement.
      static 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.
      static void fatalError​(java.lang.Exception e)  
      static <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.
      static <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.
      static <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.
      static <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.
      static DbRow getFirstRow​(java.lang.String query, java.lang.Object... params)
      Utility method to execute a query and retrieve the first row, then close statement.
      static 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.
      static Database getGlobalDatabase()  
      static 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.
      static 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.
      static void logException​(java.lang.Exception e)  
      static void logException​(java.lang.String message, java.lang.Exception e)  
      static void logException​(java.util.logging.Logger logger, java.util.logging.Level logLevel, java.lang.String message, java.lang.Exception e)  
      static void setGlobalDatabase​(Database database)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getGlobalDatabase

        public static Database getGlobalDatabase()
      • setGlobalDatabase

        public static void setGlobalDatabase​(Database database)
      • close

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

        public static void close​(long timeout,
                                 java.util.concurrent.TimeUnit unit)
      • getFirstRow

        public static 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

        public static 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

        public static <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

        public static <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

        public static <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

        public static <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

        public static 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

        public static 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

        public static 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

        public static 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

        public static 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

        public static void createTransactionAsync​(TransactionCallback run)
      • createTransactionAsync

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

        public static void logException​(java.lang.Exception e)
      • logException

        public static void logException​(java.lang.String message,
                                        java.lang.Exception e)
      • fatalError

        public static void fatalError​(java.lang.Exception e)
      • logException

        public static void logException​(java.util.logging.Logger logger,
                                        java.util.logging.Level logLevel,
                                        java.lang.String message,
                                        java.lang.Exception e)