Interface DatabaseAPI

All Known Implementing Classes:
DatabaseEngineJDBCImpl

public interface DatabaseAPI
The primary interface to the database. It conceptually represents an SQLite database that can have connections opened on it.
Author:
Donal Fellows
  • Method Details

    • getConnection

      Get a connection. This connection is thread-bound and pooled; it must not be passed to other threads. They should get their own connections instead. The connection has auto-commit disabled; use the transaction() method instead.
      Returns:
      A configured initialised connection to the database.
    • isHistoricalDBAvailable

      boolean isHistoricalDBAvailable()
      Whether the historical data DB is available. If it isn't, you can't move any data to longer-term storage, but ordinary operations should be fine.
      Returns:
      Whether the historical data DB is available.
    • getHistoricalConnection

      @MustBeClosed DatabaseAPI.Connection getHistoricalConnection()
      Get a connection to the historical database, similar to the above.
      Returns:
      A configured initialised connection to the historical database.
    • executeVoid

      void executeVoid​(boolean lockForWriting, DatabaseAPI.Connected operation)
      A connection manager and transaction runner. If the operation completes normally (and this isn't a nested use), the transaction commits. If an exception is thrown, the transaction is rolled back. The connection is closed up in any case.
      Parameters:
      lockForWriting - Whether to lock for writing. Multiple read locks can be held at once, but only one write lock. Locks cannot be upgraded (because that causes deadlocks).
      operation - The operation to run
      Throws:
      RuntimeException - If something goes wrong with the database access or the contained code.
    • executeVoid

      default void executeVoid​(DatabaseAPI.Connected operation)
      A connection manager and transaction runner. If the operation completes normally (and this isn't a nested use), the transaction commits. If an exception is thrown, the transaction is rolled back. The connection is closed up in any case. This uses a write lock.
      Parameters:
      operation - The operation to run
      Throws:
      RuntimeException - If something goes wrong with the database access or the contained code.
    • execute

      <T> T execute​(boolean lockForWriting, DatabaseAPI.ConnectedWithResult<T> operation)
      A connection manager and transaction runner. If the operation completes normally (and this isn't a nested use), the transaction commits. If an exception is thrown, the transaction is rolled back. The connection is closed up in any case.
      Type Parameters:
      T - The type of the result of operation
      Parameters:
      lockForWriting - Whether to lock for writing. Multiple read locks can be held at once, but only one write lock. Locks cannot be upgraded (because that causes deadlocks).
      operation - The operation to run
      Returns:
      the value returned by operation
      Throws:
      RuntimeException - If something other than database access goes wrong with the contained code.
    • execute

      default <T> T execute​(DatabaseAPI.ConnectedWithResult<T> operation)
      A connection manager and transaction runner. If the operation completes normally (and this isn't a nested use), the transaction commits. If an exception is thrown, the transaction is rolled back. The connection is closed up in any case. This uses a write lock.
      Type Parameters:
      T - The type of the result of operation
      Parameters:
      operation - The operation to run
      Returns:
      the value returned by operation
      Throws:
      RuntimeException - If something other than database access goes wrong with the contained code.