Class DatabaseEngineJDBCImpl

java.lang.Object
uk.ac.manchester.spinnaker.alloc.db.DatabaseEngineJDBCImpl
All Implemented Interfaces:
DatabaseAPI

@Service
@Primary
public class DatabaseEngineJDBCImpl
extends Object
implements DatabaseAPI
Implementation of the DatabaseAPI that uses JDBC to talk to MySQL.
  • Constructor Details

  • Method Details

    • getConnection

      public DatabaseAPI.Connection getConnection()
      Description copied from interface: DatabaseAPI
      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.
      Specified by:
      getConnection in interface DatabaseAPI
      Returns:
      A configured initialised connection to the database.
    • isHistoricalDBAvailable

      public boolean isHistoricalDBAvailable()
      Description copied from interface: DatabaseAPI
      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.
      Specified by:
      isHistoricalDBAvailable in interface DatabaseAPI
      Returns:
      Whether the historical data DB is available.
    • getHistoricalConnection

      public DatabaseAPI.Connection getHistoricalConnection()
      Description copied from interface: DatabaseAPI
      Get a connection to the historical database, similar to the above.
      Specified by:
      getHistoricalConnection in interface DatabaseAPI
      Returns:
      A configured initialised connection to the historical database.
    • executeVoid

      public void executeVoid​(boolean lockForWriting, DatabaseAPI.Connected operation)
      Description copied from interface: DatabaseAPI
      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.
      Specified by:
      executeVoid in interface DatabaseAPI
      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
    • execute

      public <T> T execute​(boolean lockForWriting, DatabaseAPI.ConnectedWithResult<T> operation)
      Description copied from interface: DatabaseAPI
      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.
      Specified by:
      execute in interface DatabaseAPI
      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