Package co.aikar.idb
Class DB
- java.lang.Object
-
- co.aikar.idb.DB
-
public final class DB extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose()Called in onDisable, destroys the Data source and nulls out references.static voidclose(long timeout, java.util.concurrent.TimeUnit unit)static booleancreateTransaction(TransactionCallback run)static voidcreateTransactionAsync(TransactionCallback run)static voidcreateTransactionAsync(TransactionCallback run, java.lang.Runnable onSuccess, java.lang.Runnable onFail)static java.lang.LongexecuteInsert(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 intexecuteUpdate(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 voidfatalError(java.lang.Exception e)static <T> TgetFirstColumn(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 DbRowgetFirstRow(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 DatabasegetGlobalDatabase()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 voidlogException(java.lang.Exception e)static voidlogException(java.lang.String message, java.lang.Exception e)static voidlogException(java.util.logging.Logger logger, java.util.logging.Level logLevel, java.lang.String message, java.lang.Exception e)static voidsetGlobalDatabase(Database database)
-
-
-
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 runparams- 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 runparams- 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.SQLExceptionUtility 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 runparams- 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 runparams- 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.SQLExceptionUtility 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 runparams- 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 runparams- 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.SQLExceptionUtility method for executing an update synchronously that does an insert, closes the statement, and returns the last insert ID.- Parameters:
query- Query to runparams- 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.SQLExceptionUtility method for executing an update synchronously, and then close the statement.- Parameters:
query- Query to runparams- 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 runparams- 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)
-
createTransaction
public static boolean createTransaction(TransactionCallback run)
-
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)
-
-