Package com.dieselpoint.norm
Class Transaction
java.lang.Object
com.dieselpoint.norm.Transaction
- All Implemented Interfaces:
Closeable,AutoCloseable
Represents a database transaction. Create it using Transaction trans =
Database.startTransation(), pass it to the query object using
.transaction(trans), and then call trans.commit() or trans.rollback().
Some things to note: commit() and rollback() also call close() on the connection, so this class cannot be reused after the transaction is committed or rolled back.
This is just a convenience class. If the implementation is too restrictive, then you can manage your own transactions by calling Database.getConnection() and operate on the Connection directly.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This simply calls .commit();voidcommit()longmaxLatency(long millis) sets the maximum acceptable latency for this transaction.voidrollback()
-
Method Details
-
commit
public void commit() -
rollback
public void rollback() -
getConnection
-
close
This simply calls .commit();- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getDatabase
-
maxLatency
sets the maximum acceptable latency for this transaction. Must be called beforecommit().
If latency of the query exceeds the threshold then theLatencyAlerterthat have been added to theDatabasewill be called in order.- Parameters:
millis- maximum number of milliseconds that a query can take to execute before an alert will be generated- Returns:
this, to enable maxLatency to be chained, a latrans.maxLatency("Ten People Transaction", 50).commit()
-
getMaxLatencyMillis
public long getMaxLatencyMillis()
-