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.-
Nested Class Summary
Nested classes/interfaces inherited from interface uk.ac.manchester.spinnaker.alloc.db.DatabaseAPI
DatabaseAPI.Connected, DatabaseAPI.ConnectedWithResult<T>, DatabaseAPI.Connection, DatabaseAPI.Query, DatabaseAPI.RowMapper<T>, DatabaseAPI.StatementCommon, DatabaseAPI.Transacted, DatabaseAPI.TransactedWithResult<T>, DatabaseAPI.Update
-
Constructor Summary
Constructors Constructor Description DatabaseEngineJDBCImpl(JdbcTemplate jdbcTemplate, JdbcTemplate tombstoneJdbcTemplate, PlatformTransactionManager transactionManager)
Create a new JDBC Database API. -
Method Summary
Modifier and Type Method Description <T> T
execute(boolean lockForWriting, DatabaseAPI.ConnectedWithResult<T> operation)
A connection manager and transaction runner.void
executeVoid(boolean lockForWriting, DatabaseAPI.Connected operation)
A connection manager and transaction runner.DatabaseAPI.Connection
getConnection()
Get a connection.DatabaseAPI.Connection
getHistoricalConnection()
Get a connection to the historical database, similar to the above.boolean
isHistoricalDBAvailable()
Whether the historical data DB is available.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.manchester.spinnaker.alloc.db.DatabaseAPI
execute, executeVoid
-
Constructor Details
-
DatabaseEngineJDBCImpl
@Autowired public DatabaseEngineJDBCImpl(@Qualifier("mainDatabase") JdbcTemplate jdbcTemplate, @Qualifier("historicalDatabase") JdbcTemplate tombstoneJdbcTemplate, @Qualifier("mainTransactionManager") PlatformTransactionManager transactionManager)Create a new JDBC Database API.- Parameters:
jdbcTemplate
- The connection to the main database.tombstoneJdbcTemplate
- The connection to the historical database.transactionManager
- The transaction manager.
-
-
Method Details
-
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 thetransaction()
method instead.- Specified by:
getConnection
in interfaceDatabaseAPI
- 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 interfaceDatabaseAPI
- Returns:
- Whether the historical data DB is available.
-
getHistoricalConnection
Description copied from interface:DatabaseAPI
Get a connection to the historical database, similar to the above.- Specified by:
getHistoricalConnection
in interfaceDatabaseAPI
- Returns:
- A configured initialised connection to the historical database.
-
executeVoid
Description copied from interface:DatabaseAPI
A connection manager and transaction runner. If theoperation
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 interfaceDatabaseAPI
- 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
Description copied from interface:DatabaseAPI
A connection manager and transaction runner. If theoperation
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 interfaceDatabaseAPI
- Type Parameters:
T
- The type of the result ofoperation
- 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
-