getFirstColumnAsync(@Language("SQL") @NotNull String query, @NotNull Object... params) {
return globalDatabase.getFirstColumnAsync(query, 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.
*/
- public static List getFirstColumnResults(@Language("SQL") String query, Object... params) throws SQLException {
+ public static List getFirstColumnResults(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
return globalDatabase.getFirstColumnResults(query, 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.
*/
- public static CompletableFuture> getFirstColumnResultsAsync(@Language("SQL") String query, Object... params) {
+ public static CompletableFuture> getFirstColumnResultsAsync(@Language("SQL") @NotNull String query, @NotNull Object... params) {
return globalDatabase.getFirstColumnResultsAsync(query, 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.
*
* @param query The query to run
* @param params The parameters to execute the statement with
* @return List of DbRow of your results (HashMap with template return type)
*/
- public static List getResults(@Language("SQL") String query, Object... params) throws SQLException {
+ public static List getResults(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
return globalDatabase.getResults(query, 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.
*
* @param query The query to run
* @param params The parameters to execute the statement with
* @return List of DbRow of your results (HashMap with template return type)
*/
- public static CompletableFuture> getResultsAsync(@Language("SQL") String query, Object... params) {
+ public static CompletableFuture> getResultsAsync(@Language("SQL") @NotNull String query, @NotNull Object... params) {
return globalDatabase.getResultsAsync(query, params);
}
@@ -158,9 +165,10 @@ public static CompletableFuture> getResultsAsync(@Language("SQL") St
* @param params Params to execute the statement with.
* @return Inserted Row Id.
*/
- public static Long executeInsert(@Language("SQL") String query, Object... params) throws SQLException {
+ public static Long executeInsert(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
return globalDatabase.executeInsert(query, params);
}
+
/**
* Utility method for executing an update synchronously, and then close the statement.
*
@@ -168,7 +176,7 @@ public static Long executeInsert(@Language("SQL") String query, Object... params
* @param params Params to execute the statement with.
* @return Number of rows modified.
*/
- public static int executeUpdate(@Language("SQL") String query, Object... params) throws SQLException {
+ public static int executeUpdate(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
return globalDatabase.executeUpdate(query, params);
}
@@ -178,38 +186,39 @@ public static int executeUpdate(@Language("SQL") String query, Object... params)
* @param query Query to run
* @param params Params to execute the update with
*/
- public static CompletableFuture executeUpdateAsync(@Language("SQL") String query, final Object... params) {
+ public static CompletableFuture executeUpdateAsync(@Language("SQL") String query, @NotNull final Object... params) {
return globalDatabase.executeUpdateAsync(query, params);
}
- private synchronized static CompletableFuture dispatchAsync(Callable task) {
+ private synchronized static CompletableFuture dispatchAsync(@NotNull Callable task) {
return globalDatabase.dispatchAsync(task);
}
- public static void createTransactionAsync(TransactionCallback run) {
+ public static void createTransactionAsync(@NotNull TransactionCallback run) {
globalDatabase.createTransactionAsync(run, null, null);
}
- public static void createTransactionAsync(TransactionCallback run, Runnable onSuccess, Runnable onFail) {
+ public static void createTransactionAsync(@NotNull TransactionCallback run, Runnable onSuccess, Runnable onFail) {
globalDatabase.createTransactionAsync(run, onSuccess, onFail);
}
- public static boolean createTransaction(TransactionCallback run) {
+ public static boolean createTransaction(@NotNull TransactionCallback run) {
return globalDatabase.createTransaction(run);
}
- public static void logException(Exception e) {
+ public static void logException(@NotNull Exception e) {
globalDatabase.logException(e.getMessage(), e);
}
- public static void logException(String message, Exception e) {
+
+ public static void logException(@NotNull String message, @NotNull Exception e) {
globalDatabase.logException(message, e);
}
- public static void fatalError(Exception e) {
+ public static void fatalError(@NotNull Exception e) {
globalDatabase.fatalError(e);
}
- public static void logException(Logger logger, Level logLevel, String message, Exception e) {
+ public static void logException(@NotNull Logger logger, @NotNull Level logLevel, @NotNull String message, Exception e) {
logger.log(logLevel, message);
if (e != null) {
diff --git a/core/src/main/java/co/aikar/idb/Database.java b/core/src/main/java/co/aikar/idb/Database.java
index 79f22d3..f20a234 100644
--- a/core/src/main/java/co/aikar/idb/Database.java
+++ b/core/src/main/java/co/aikar/idb/Database.java
@@ -1,8 +1,9 @@
package co.aikar.idb;
import org.intellij.lang.annotations.Language;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
-import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -25,19 +26,20 @@ default void close() {
/**
* Called in onDisable, destroys the Data source and nulls out references.
*/
- void close(long timeout, TimeUnit unit);
+ void close(long timeout, @NotNull TimeUnit unit);
- CompletableFuture dispatchAsync(Callable task);
+ CompletableFuture dispatchAsync(@NotNull Callable task);
/**
* Get a JDBC Connection
*/
+ @Nullable
Connection getConnection() throws SQLException;
/**
* Create a Timings object
*/
- DatabaseTiming timings(String name);
+ DatabaseTiming timings(@NotNull String name);
/**
* Get the Logger
@@ -49,11 +51,11 @@ default void close() {
*/
DatabaseOptions getOptions();
- default void fatalError(Exception e) {
+ default void fatalError(@NotNull Exception e) {
getOptions().onFatalError.accept(e);
}
- default void closeConnection(Connection conn) throws SQLException {
+ default void closeConnection(@NotNull Connection conn) throws SQLException {
conn.close();
}
@@ -71,7 +73,7 @@ default DbStatement createStatement() throws SQLException {
*
* YOU MUST MANUALLY CLOSE THIS STATEMENT IN A finally {} BLOCK!
*/
- default DbStatement query(@Language("SQL") String query) throws SQLException {
+ default DbStatement query(@Language("SQL") @NotNull String query) throws SQLException {
DbStatement stm = new DbStatement(this);
try {
stm.query(query);
@@ -87,7 +89,7 @@ default DbStatement query(@Language("SQL") String query) throws SQLException {
*
* YOU MUST MANUALLY CLOSE THIS STATEMENT IN A finally {} BLOCK!
*/
- default CompletableFuture queryAsync(@Language("SQL") String query) {
+ default CompletableFuture queryAsync(@Language("SQL") @NotNull String query) {
return dispatchAsync(() -> new DbStatement(this).query(query));
}
@@ -99,7 +101,7 @@ default CompletableFuture queryAsync(@Language("SQL") String query)
* @param params The parameters to execute the statement with
* @return DbRow of your results (HashMap with template return type)
*/
- default DbRow getFirstRow(@Language("SQL") String query, Object... params) throws SQLException {
+ default DbRow getFirstRow(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
try (DbStatement statement = query(query)) {
statement.execute(params);
return statement.getNextRow();
@@ -114,7 +116,7 @@ default DbRow getFirstRow(@Language("SQL") String query, Object... params) throw
* @param params The parameters to execute the statement with
* @return DbRow of your results (HashMap with template return type)
*/
- default CompletableFuture getFirstRowAsync(@Language("SQL") String query, Object... params) {
+ default CompletableFuture getFirstRowAsync(@Language("SQL") @NotNull String query, @NotNull Object... params) {
return dispatchAsync(() -> getFirstRow(query, params));
}
@@ -126,7 +128,7 @@ default CompletableFuture getFirstRowAsync(@Language("SQL") String query,
* @param params The parameters to execute the statement with
* @return DbRow of your results (HashMap with template return type)
*/
- default T getFirstColumn(@Language("SQL") String query, Object... params) throws SQLException {
+ default T getFirstColumn(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
try (DbStatement statement = query(query)) {
statement.execute(params);
return statement.getFirstColumn();
@@ -141,7 +143,7 @@ default T getFirstColumn(@Language("SQL") String query, Object... params) th
* @param params The parameters to execute the statement with
* @return DbRow of your results (HashMap with template return type)
*/
- default CompletableFuture getFirstColumnAsync(@Language("SQL") String query, Object... params) {
+ default CompletableFuture getFirstColumnAsync(@Language("SQL") @NotNull String query, @NotNull Object... params) {
return dispatchAsync(() -> getFirstColumn(query, params));
}
@@ -150,7 +152,7 @@ default CompletableFuture getFirstColumnAsync(@Language("SQL") String que
*
* Meant for single queries that will not use the statement multiple times.
*/
- default List getFirstColumnResults(@Language("SQL") String query, Object... params) throws SQLException {
+ default List getFirstColumnResults(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
List dbRows = new ArrayList<>();
T result;
try (DbStatement statement = query(query)) {
@@ -167,7 +169,7 @@ default List getFirstColumnResults(@Language("SQL") String query, Object.
*
* Meant for single queries that will not use the statement multiple times.
*/
- default CompletableFuture> getFirstColumnResultsAsync(@Language("SQL") String query, Object... params) {
+ default CompletableFuture> getFirstColumnResultsAsync(@Language("SQL") @NotNull String query, @NotNull Object... params) {
return dispatchAsync(() -> getFirstColumnResults(query, params));
}
@@ -180,7 +182,7 @@ default CompletableFuture> getFirstColumnResultsAsync(@Language("SQL
* @param params The parameters to execute the statement with
* @return List of DbRow of your results (HashMap with template return type)
*/
- default List getResults(@Language("SQL") String query, Object... params) throws SQLException {
+ default List getResults(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
try (DbStatement statement = query(query)) {
statement.execute(params);
return statement.getResults();
@@ -196,7 +198,7 @@ default List getResults(@Language("SQL") String query, Object... params)
* @param params The parameters to execute the statement with
* @return List of DbRow of your results (HashMap with template return type)
*/
- default CompletableFuture> getResultsAsync(@Language("SQL") String query, Object... params) {
+ default CompletableFuture> getResultsAsync(@Language("SQL") @NotNull String query, @NotNull Object... params) {
return dispatchAsync(() -> getResults(query, params));
}
@@ -208,7 +210,8 @@ default CompletableFuture> getResultsAsync(@Language("SQL") String q
* @param params Params to execute the statement with.
* @return Inserted Row Id.
*/
- default Long executeInsert(@Language("SQL") String query, Object... params) throws SQLException {
+ @Nullable
+ default Long executeInsert(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
try (DbStatement statement = query(query)) {
int i = statement.executeUpdate(params);
if (i > 0) {
@@ -225,7 +228,7 @@ default Long executeInsert(@Language("SQL") String query, Object... params) thro
* @param params Params to execute the statement with.
* @return Number of rows modified.
*/
- default int executeUpdate(@Language("SQL") String query, Object... params) throws SQLException {
+ default int executeUpdate(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
try (DbStatement statement = query(query)) {
return statement.executeUpdate(params);
}
@@ -237,15 +240,16 @@ default int executeUpdate(@Language("SQL") String query, Object... params) throw
* @param query Query to run
* @param params Params to execute the update with
*/
- default CompletableFuture executeUpdateAsync(@Language("SQL") String query, final Object... params) {
+ default CompletableFuture executeUpdateAsync(@Language("SQL") @NotNull String query, @NotNull final Object... params) {
return dispatchAsync(() -> executeUpdate(query, params));
}
- default void createTransactionAsync(TransactionCallback run) {
+ @Nullable
+ default void createTransactionAsync(@NotNull TransactionCallback run) {
createTransactionAsync(run, null, null);
}
- default void createTransactionAsync(TransactionCallback run, Runnable onSuccess, Runnable onFail) {
+ default void createTransactionAsync(@NotNull TransactionCallback run, Runnable onSuccess, Runnable onFail) {
dispatchAsync(() -> {
if (!createTransaction(run)) {
if (onFail != null) {
@@ -258,7 +262,7 @@ default void createTransactionAsync(TransactionCallback run, Runnable onSuccess,
});
}
- default boolean createTransaction(TransactionCallback run) {
+ default boolean createTransaction(@NotNull TransactionCallback run) {
try (DbStatement stm = new DbStatement(this)) {
try {
stm.startTransaction();
@@ -279,13 +283,11 @@ default boolean createTransaction(TransactionCallback run) {
return false;
}
- default void logException(String message, Exception e) {
+ default void logException(@NotNull String message, @NotNull Exception e) {
DB.logException(getLogger(), Level.SEVERE, message, e);
}
- default void logException(Exception e) {
+ default void logException(@NotNull Exception e) {
DB.logException(getLogger(), Level.SEVERE, e.getMessage(), e);
}
-
-
}
diff --git a/core/src/main/java/co/aikar/idb/DatabaseOptions.java b/core/src/main/java/co/aikar/idb/DatabaseOptions.java
index 4cd94b0..113047c 100644
--- a/core/src/main/java/co/aikar/idb/DatabaseOptions.java
+++ b/core/src/main/java/co/aikar/idb/DatabaseOptions.java
@@ -2,7 +2,7 @@
import lombok.Builder;
import lombok.Data;
-import lombok.NonNull;
+import org.jetbrains.annotations.NotNull;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
@@ -15,11 +15,11 @@ public class DatabaseOptions {
/**
* JDBC DSN to connect to
*/
- @NonNull String dsn;
+ @NotNull String dsn;
/**
* JDBC Classname of the Driver name to use
*/
- @NonNull String driverClassName;
+ @NotNull String driverClassName;
/**
* Class name of DataSource to use
*/
@@ -43,15 +43,14 @@ public class DatabaseOptions {
@Builder.Default TimingsProvider timingsProvider = (name, parent) -> NULL_TIMING;
@Builder.Default Consumer onFatalError = DB::logException;
@Builder.Default Consumer onDatabaseConnectionFailure = DB::logException;
-
-
+
String user;
String pass;
Logger logger;
ExecutorService executor;
public static class DatabaseOptionsBuilder {
- public DatabaseOptionsBuilder mysql(@NonNull String user, @NonNull String pass, @NonNull String db, @NonNull String hostAndPort) {
+ public DatabaseOptionsBuilder mysql(@NotNull String user, @NotNull String pass, @NotNull String db, @NotNull String hostAndPort) {
if (hostAndPort == null) {
hostAndPort = "localhost:3306";
}
@@ -72,7 +71,7 @@ public DatabaseOptionsBuilder mysql(@NonNull String user, @NonNull String pass,
return this;
}
- public DatabaseOptionsBuilder sqlite(@NonNull String fileName) {
+ public DatabaseOptionsBuilder sqlite(@NotNull String fileName) {
if (defaultIsolationLevel == null) defaultIsolationLevel = "TRANSACTION_SERIALIZABLE";
if (dataSourceClassName == null) tryDataSourceClassName("org.sqlite.SQLiteDataSource");
@@ -87,7 +86,7 @@ public DatabaseOptionsBuilder sqlite(@NonNull String fileName) {
/**
* Tries the specified JDBC driverClassName, and uses it if it is valid. Does nothing if a Driver is already set
*/
- public DatabaseOptionsBuilder tryDriverClassName(@NonNull String className) {
+ public DatabaseOptionsBuilder tryDriverClassName(@NotNull String className) {
try {
driverClassName(className);
} catch (Exception ignored) {}
@@ -98,14 +97,14 @@ public DatabaseOptionsBuilder tryDriverClassName(@NonNull String className) {
/**
* Tries the specified JDBC DataSource, and uses it if it is valid. Does nothing if a DataSource is already set
*/
- public DatabaseOptionsBuilder tryDataSourceClassName(@NonNull String className) {
+ public DatabaseOptionsBuilder tryDataSourceClassName(@NotNull String className) {
try {
dataSourceClassName(className);
} catch (Exception ignored) {}
return this;
}
- public DatabaseOptionsBuilder driverClassName(@NonNull String className) {
+ public DatabaseOptionsBuilder driverClassName(@NotNull String className) {
try {
Class.forName(className).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
@@ -115,7 +114,7 @@ public DatabaseOptionsBuilder driverClassName(@NonNull String className) {
return this;
}
- public DatabaseOptionsBuilder dataSourceClassName(@NonNull String className) {
+ public DatabaseOptionsBuilder dataSourceClassName(@NotNull String className) {
try {
Class.forName(className);
} catch (ClassNotFoundException e) {
diff --git a/core/src/main/java/co/aikar/idb/DbRow.java b/core/src/main/java/co/aikar/idb/DbRow.java
index 07fe02d..df8b504 100644
--- a/core/src/main/java/co/aikar/idb/DbRow.java
+++ b/core/src/main/java/co/aikar/idb/DbRow.java
@@ -23,6 +23,8 @@
package co.aikar.idb;
+import org.jetbrains.annotations.NotNull;
+
import java.util.HashMap;
/**
@@ -40,7 +42,7 @@ public class DbRow extends HashMap {
* @param column
* @return Object of the matching type of the result.
*/
- public T get(String column) {
+ public T get(@NotNull String column) {
return (T) super.get(column);
}
/**
@@ -53,7 +55,7 @@ public T get(String column) {
* @param column
* @return Object of the matching type of the result.
*/
- public T get(String column, T def) {
+ public T get(@NotNull String column, @NotNull T def) {
T res = (T) super.get(column);
if (res == null) {
return def;
@@ -61,59 +63,59 @@ public T get(String column, T def) {
return res;
}
- public Long getLong(String column) {
+ public Long getLong(@NotNull String column) {
return get(column);
}
- public Long getLong(String column, Number def) {
+ public Long getLong(@NotNull String column, @NotNull Number def) {
return get(column, def).longValue();
}
- public Integer getInt(String column) {
+ public Integer getInt(@NotNull String column) {
return ((Number) get(column)).intValue();
}
- public Integer getInt(String column, Number def) {
+ public Integer getInt(@NotNull String column, @NotNull Number def) {
return get(column, def).intValue();
}
- public Float getFloat(String column) {
+ public Float getFloat(@NotNull String column) {
return ((Number) get(column)).floatValue();
}
- public Float getFloat(String column, Number def) {
+ public Float getFloat(@NotNull String column, @NotNull Number def) {
return get(column, def).floatValue();
}
- public Double getDbl(String column) {
+ public Double getDbl(@NotNull String column) {
return ((Number) get(column)).doubleValue();
}
- public Double getDbl(String column, Number def) {
+ public Double getDbl(@NotNull String column, @NotNull Number def) {
return get(column, def).doubleValue();
}
- public String getString(String column) {
+ public String getString(@NotNull String column) {
return get(column);
}
- public String getString(String column, String def) {
+ public String getString(@NotNull String column, @NotNull String def) {
return get(column, def);
}
- public Boolean getBoolean(String column) {
+ public Boolean getBoolean(@NotNull String column) {
return get(column);
}
- public Boolean getBoolean(String column, Boolean def) {
+ public Boolean getBoolean(@NotNull String column, @NotNull Boolean def) {
return get(column, def);
}
- public Byte getByte(String column) {
+ public Byte getByte(@NotNull String column) {
return get(column);
}
- public Byte getByte(String column, Byte def) {
+ public Byte getByte(@NotNull String column, @NotNull Byte def) {
return get(column, def);
}
@@ -127,7 +129,7 @@ public Byte getByte(String column, Byte def) {
* @param column
* @return Object of the matching type of the result.
*/
- public T remove(String column) {
+ public T remove(@NotNull String column) {
return (T) super.remove(column);
}
@@ -141,7 +143,7 @@ public T remove(String column) {
* @param column
* @return Object of the matching type of the result.
*/
- public T remove(String column, T def) {
+ public T remove(@NotNull String column, @NotNull T def) {
T res = (T) super.remove(column);
if (res == null) {
return def;
diff --git a/core/src/main/java/co/aikar/idb/DbStatement.java b/core/src/main/java/co/aikar/idb/DbStatement.java
index afb94d7..2599acd 100644
--- a/core/src/main/java/co/aikar/idb/DbStatement.java
+++ b/core/src/main/java/co/aikar/idb/DbStatement.java
@@ -25,13 +25,10 @@
import org.intellij.lang.annotations.Language;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
@@ -69,7 +66,8 @@ public class DbStatement implements AutoCloseable {
public DbStatement() throws SQLException {
this(DB.getGlobalDatabase());
}
- public DbStatement(Database db) throws SQLException {
+
+ public DbStatement(@NotNull Database db) throws SQLException {
this.db = db;
dbConn = db.getConnection();
if (dbConn == null) {
@@ -102,7 +100,7 @@ public void commit() throws SQLException {
}
}
- private synchronized void runEvents(List> runnables) {
+ private synchronized void runEvents(@NotNull List> runnables) {
runnables.forEach(run -> {
try {
run.accept(this);
@@ -115,7 +113,7 @@ private synchronized void runEvents(List> runnables) {
}
/**
- * Rollsback a pending transaction on this connection.
+ * Rollback a pending transaction on this connection.
*/
public synchronized void rollback() throws SQLException {
if (!isDirty) {
@@ -137,9 +135,8 @@ public boolean inTransaction() {
* When this connection is rolled back, run this method.
* If not in a transaction, the method will run immediately after the next executeUpdate.
* It will not run on non update execute queries when not in a transaction
- *
*/
- public synchronized void onCommit(Consumer run) {
+ public synchronized void onCommit(@NotNull Consumer run) {
synchronized (this.onCommit) {
this.onCommit.add(run);
}
@@ -149,9 +146,8 @@ public synchronized void onCommit(Consumer run) {
* When this connection is rolled back, run this method.
* If not in a transaction, the method will run if the next executeUpdate has an error.
* No guarantee is made about the state of the connection when this runnable is called.
- *
*/
- public synchronized void onRollback(Consumer run) {
+ public synchronized void onRollback(@NotNull Consumer run) {
synchronized (this.onRollback) {
this.onRollback.add(run);
}
@@ -160,7 +156,7 @@ public synchronized void onRollback(Consumer run) {
/**
* Initiates a new prepared statement on this connection.
*/
- public DbStatement query(@Language("SQL") String query) throws SQLException {
+ public DbStatement query(@Language("SQL") @NotNull String query) throws SQLException {
this.query = query;
try (DatabaseTiming ignored = db.timings("query: " + query)) {
closeStatement();
@@ -178,7 +174,7 @@ public DbStatement query(@Language("SQL") String query) throws SQLException {
/**
* Helper method to query, execute and getResults
*/
- public ArrayList executeQueryGetResults(@Language("SQL") String query, Object... params) throws SQLException {
+ public ArrayList executeQueryGetResults(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
this.query(query);
this.execute(params);
return getResults();
@@ -187,7 +183,7 @@ public ArrayList executeQueryGetResults(@Language("SQL") String query, Ob
/**
* Helper method to query and execute update
*/
- public int executeUpdateQuery(@Language("SQL") String query, Object... params) throws SQLException {
+ public int executeUpdateQuery(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
this.query(query);
return this.executeUpdate(params);
}
@@ -195,7 +191,7 @@ public int executeUpdateQuery(@Language("SQL") String query, Object... params) t
/**
* Helper method to query, execute and get first row
*/
- public DbRow executeQueryGetFirstRow(@Language("SQL") String query, Object... params) throws SQLException {
+ public DbRow executeQueryGetFirstRow(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
this.query(query);
this.execute(params);
return this.getNextRow();
@@ -204,7 +200,7 @@ public DbRow executeQueryGetFirstRow(@Language("SQL") String query, Object... pa
/**
* Helper to query, execute and get first column
*/
- public T executeQueryGetFirstColumn(@Language("SQL") String query, Object... params) throws SQLException {
+ public T executeQueryGetFirstColumn(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
this.query(query);
this.execute(params);
return this.getFirstColumn();
@@ -213,7 +209,7 @@ public T executeQueryGetFirstColumn(@Language("SQL") String query, Object...
/**
* Helper to query, execute and get first column of all results
*/
- public List executeQueryGetFirstColumnResults(@Language("SQL") String query, Object... params) throws SQLException {
+ public List executeQueryGetFirstColumnResults(@Language("SQL") @NotNull String query, @NotNull Object... params) throws SQLException {
this.query(query);
this.execute(params);
List dbRows = new ArrayList<>();
@@ -229,7 +225,7 @@ public List executeQueryGetFirstColumnResults(@Language("SQL") String que
*
* @param params Array of Objects to use for each parameter.
*/
- private void prepareExecute(Object... params) throws SQLException {
+ private void prepareExecute(@NotNull Object... params) throws SQLException {
try (DatabaseTiming ignored = db.timings("prepareExecute: " + query)) {
closeResult();
if (preparedStatement == null) {
@@ -245,7 +241,7 @@ private void prepareExecute(Object... params) throws SQLException {
/**
* Execute an update query with the supplied parameters
*/
- public int executeUpdate(Object... params) throws SQLException {
+ public int executeUpdate(@NotNull Object... params) throws SQLException {
try (DatabaseTiming ignored = db.timings("executeUpdate: " + query)) {
try {
prepareExecute(params);
@@ -267,7 +263,7 @@ public int executeUpdate(Object... params) throws SQLException {
/**
* Executes the prepared statement with the supplied parameters.
*/
- public DbStatement execute(Object... params) throws SQLException {
+ public DbStatement execute(@NotNull Object... params) throws SQLException {
try (DatabaseTiming ignored = db.timings("execute: " + query)) {
try {
prepareExecute(params);
@@ -293,6 +289,7 @@ public DbStatement execute(Object... params) throws SQLException {
*
* @return Long
*/
+ @Nullable
public Long getLastInsertId() throws SQLException {
try (DatabaseTiming ignored = db.timings("getLastInsertId")) {
try (ResultSet genKeys = preparedStatement.getGeneratedKeys()) {
@@ -311,6 +308,7 @@ public Long getLastInsertId() throws SQLException {
/**
* Gets all results as an array of DbRow
*/
+ @Nullable
public ArrayList getResults() throws SQLException {
if (resultSet == null) {
return null;
@@ -330,6 +328,7 @@ public ArrayList getResults() throws SQLException {
*
* @return DbRow containing a hashmap of the columns
*/
+ @Nullable
public DbRow getNextRow() throws SQLException {
if (resultSet == null) {
return null;
@@ -346,6 +345,7 @@ public DbRow getNextRow() throws SQLException {
return null;
}
+ @Nullable
public T getFirstColumn() throws SQLException {
ResultSet resultSet = getNextResultSet();
if (resultSet != null) {
@@ -354,9 +354,11 @@ public T getFirstColumn() throws SQLException {
}
return null;
}
+
/**
* Util method to get the next result set and close it when done.
*/
+ @Nullable
private ResultSet getNextResultSet() throws SQLException {
if (resultSet != null && resultSet.next()) {
return resultSet;
@@ -365,12 +367,14 @@ private ResultSet getNextResultSet() throws SQLException {
return null;
}
}
+
private void closeResult() throws SQLException {
if (resultSet != null) {
resultSet.close();
resultSet = null;
}
}
+
private void closeStatement() throws SQLException {
closeResult();
if (preparedStatement != null) {
@@ -384,7 +388,6 @@ private void closeStatement() throws SQLException {
*/
public void close() {
try (DatabaseTiming ignored = db.timings("close")) {
-
try {
closeStatement();
if (dbConn != null) {
diff --git a/core/src/main/java/co/aikar/idb/HikariPooledDatabase.java b/core/src/main/java/co/aikar/idb/HikariPooledDatabase.java
index fd9cde1..98a6fd6 100644
--- a/core/src/main/java/co/aikar/idb/HikariPooledDatabase.java
+++ b/core/src/main/java/co/aikar/idb/HikariPooledDatabase.java
@@ -2,16 +2,14 @@
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
+import org.jetbrains.annotations.NotNull;
-import java.sql.Connection;
-import java.sql.SQLException;
import java.util.Map;
-import java.util.concurrent.TimeUnit;
public class HikariPooledDatabase extends BaseDatabase {
private final PooledDatabaseOptions poolOptions;
- public HikariPooledDatabase(PooledDatabaseOptions poolOptions) {
+ public HikariPooledDatabase(@NotNull PooledDatabaseOptions poolOptions) {
super(poolOptions.options);
this.poolOptions = poolOptions;
DatabaseOptions options = poolOptions.options;
@@ -26,6 +24,7 @@ public HikariPooledDatabase(PooledDatabaseOptions poolOptions) {
if (options.user != null) {
config.addDataSourceProperty("user", options.user);
}
+
if (options.pass != null) {
config.addDataSourceProperty("password", options.pass);
}
@@ -42,6 +41,7 @@ public HikariPooledDatabase(PooledDatabaseOptions poolOptions) {
config.addDataSourceProperty("elideSetAutoCommits", true);
config.addDataSourceProperty("alwaysSendSetIsolation", false);
}
+
if (poolOptions.dataSourceProperties != null) {
for (Map.Entry entry : poolOptions.dataSourceProperties.entrySet()) {
config.addDataSourceProperty(entry.getKey(), entry.getValue());
diff --git a/core/src/main/java/co/aikar/idb/PooledDatabaseOptions.java b/core/src/main/java/co/aikar/idb/PooledDatabaseOptions.java
index efda8c7..7d7b526 100644
--- a/core/src/main/java/co/aikar/idb/PooledDatabaseOptions.java
+++ b/core/src/main/java/co/aikar/idb/PooledDatabaseOptions.java
@@ -2,7 +2,7 @@
import lombok.Builder;
import lombok.Data;
-import lombok.NonNull;
+import org.jetbrains.annotations.NotNull;
import java.util.Map;
@@ -12,7 +12,7 @@ public class PooledDatabaseOptions {
@Builder.Default int minIdleConnections = 3;
@Builder.Default int maxConnections = 5;
Map dataSourceProperties;
- @NonNull DatabaseOptions options;
+ @NotNull DatabaseOptions options;
public static class PooledDatabaseOptionsBuilder {
public HikariPooledDatabase createHikariDatabase() {
diff --git a/core/src/main/java/co/aikar/idb/TimingsProvider.java b/core/src/main/java/co/aikar/idb/TimingsProvider.java
index 59607b8..7eabe1e 100644
--- a/core/src/main/java/co/aikar/idb/TimingsProvider.java
+++ b/core/src/main/java/co/aikar/idb/TimingsProvider.java
@@ -1,18 +1,20 @@
package co.aikar.idb;
+import org.jetbrains.annotations.NotNull;
+
public interface TimingsProvider {
- default DatabaseTiming ofStart(String name) {
+ default DatabaseTiming ofStart(@NotNull String name) {
return this.ofStart(name, null);
}
- default DatabaseTiming ofStart(String name, DatabaseTiming parent) {
+ default DatabaseTiming ofStart(@NotNull String name, DatabaseTiming parent) {
return this.of(name, parent).startTiming();
}
- default DatabaseTiming of(String name) {
+ default DatabaseTiming of(@NotNull String name) {
return this.of(name, null);
}
- DatabaseTiming of(String name, DatabaseTiming parent);
+ DatabaseTiming of(@NotNull String name, DatabaseTiming parent);
}
diff --git a/core/src/main/java/co/aikar/idb/TransactionCallback.java b/core/src/main/java/co/aikar/idb/TransactionCallback.java
index 7f34ae4..57000b1 100644
--- a/core/src/main/java/co/aikar/idb/TransactionCallback.java
+++ b/core/src/main/java/co/aikar/idb/TransactionCallback.java
@@ -1,15 +1,16 @@
package co.aikar.idb;
import lombok.SneakyThrows;
+import org.jetbrains.annotations.NotNull;
import java.sql.SQLException;
import java.util.function.Function;
public interface TransactionCallback extends Function {
@Override @SneakyThrows
- default Boolean apply(DbStatement dbStatement) {
+ default Boolean apply(@NotNull DbStatement dbStatement) {
return this.runTransaction(dbStatement);
}
- Boolean runTransaction(DbStatement stm) throws SQLException;
+ Boolean runTransaction(@NotNull DbStatement stm) throws SQLException;
}