Class DatabaseAwareBean.AbstractSQL
java.lang.Object
uk.ac.manchester.spinnaker.alloc.db.DatabaseAwareBean.AbstractSQL
- All Implemented Interfaces:
- AutoCloseable
- Enclosing class:
- DatabaseAwareBean
Encapsulation of a connection. Can either do the management itself or use
 a connection managed outside; the difference is important mainly during
 testing as tests often use in-memory DBs.
- Author:
- Donal Fellows
- 
Field SummaryFields
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedManage a connection ourselves.protectedUse an existing connection.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()final voidtransaction(DatabaseAPI.Transacted action) A nestable transaction runner.final <T> Ttransaction(DatabaseAPI.TransactedWithResult<T> action) A nestable transaction runner.final <T> TtransactionRead(DatabaseAPI.TransactedWithResult<T> action) A nestable transaction runner.
- 
Field Details- 
connThe connection.
 
- 
- 
Constructor Details- 
AbstractSQLprotected AbstractSQL()Manage a connection ourselves.
- 
AbstractSQLUse an existing connection. Caller looks after its management.- Parameters:
- conn- The connection to piggy-back onto.
 
 
- 
- 
Method Details- 
transactionA nestable transaction runner. If theactioncompletes normally (and this isn't a nested use), the transaction commits. If a runtime exception is thrown, the transaction is rolled back (and the exception flows through). A write lock is used.- Type Parameters:
- T- The type of the result of- action
- Parameters:
- action- The code to run inside the transaction.
- Returns:
- Whatever the actionreturns.
 
- 
transactionReadA nestable transaction runner. If theactioncompletes normally (and this isn't a nested use), the transaction commits. If a runtime exception is thrown, the transaction is rolled back (and the exception flows through). A read lock is used; multiple read locks may be held at once, but noUPDATEs may be performed as locks cannot be safely upgraded.- Type Parameters:
- T- The type of the result of- action
- Parameters:
- action- The code to run inside the transaction.
- Returns:
- Whatever the actionreturns.
 
- 
transactionA nestable transaction runner. If theactioncompletes normally (and this isn't a nested use), the transaction commits. If a runtime exception is thrown, the transaction is rolled back (and the exception flows through). A write lock is used.- Parameters:
- action- The code to run inside the transaction.
 
- 
getConnection- Returns:
- The encapsulated connection.
 
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
 
 
-