Skip to content

IDB API

Daniel Ennis edited this page Mar 14, 2018 · 1 revision

DbRow

The DbRow class is simply a HashMap with return type inferring get() method, and defaults.

Type expectant get methods are also included. If you use the wrong left hand type for a method, a cast exception will occur.

Please consult with your JDBC Drivers ResultSet.getObject() documentation.

/*VALID: */   Long myLong      = row.get("someUnsignedIntColumn");
/*INVALID: */ String myString  = row.get("someUnsignedIntColumn");
public class DbRow extends HashMap<String, Object> {
  T get(String column);
  T get(String column, T def);
  Long getLong(String column);
  Long getLong(String column, Number def);
  Integer getInt(String column);
  Integer getInt(String column, Number def);
  Float getFloat(String column);
  Float getFloat(String column, Number def);
  Double getDbl(String column);
  Double getDbl(String column, Number def);
  String getString(String column);
  String getString(String column, String def);
}

DB.getFirstRow(query, params)

Execute a query and retrieve the first row. You should ensure result will only return 1 row for maximum performance.

DB.getFirstRowAsync(query, params)

Execute a query and retrieve the first row, and pass it to the returned Future asynchronously. You should ensure result will only return 1 row for maximum performance.

DB.getFirstColumn(query, params)

Execute a query and retrieve the first column of the first row. You should ensure result will only return 1 row for maximum performance.

DB.getFirstColumnAsync(query, params)

Execute a query and retrieve the first column of the first row. You should ensure result will only return 1 row for maximum performance.

DB.getFirstColumnResults(query, params)

Execute a query and retrieve first column of all results as a list synchronously.

DB.getFirstColumnResultsAsync(query, params)

Execute a query and retrieve first column of all results asynchronously, passing them to a Future.

DB.getResults(query, params)

Execute a query and retrieve all results synchronously.

DB.getResultsAsync(query, params)

Execute a query and retrieve all results asynchronously, passing them to a Future.

DB.executeInsert(query, params)

Execute an update synchronously that does an insert, and returns the last insert ID.

DB.executeUpdate(query, params)

Execute an update synchronously.

DB.executeUpdateAsync(String query, final Object... params)

Execute an update statement asynchronously

DB.createTransaction(TransactionCallback run)

Creates and executes a Transaction asynchronously. If this Callback throws an exception, or returns false, the transaction will be automatically rolled back.

If the callback returns true, the transaction will be committed. You may manually commit/rollback in the transaction yourself, and the result will be ignored. Automatic commit/rollback only occurs if the transaction is in a dirty state.

DB.createTransactionAsync(TransactionCallback run)

DB.createTransactionAsync(TransactionCallback run, Runnable onSuccess, Runnable onFail)

Same as DB.createTransaction(TransactionCallback run), but executed asynchronously.

Additionally, you may supply onSuccess and onFail Runnables to be executed based on the result of if the transaction returned true/false.

If you manually commit in the transaction, the return value will still dictate whether onSuccess or onFail should be executed.

The onSuccess/onFail will be executed asynchronously.

You can’t perform that action at this time.