Transactions
-
Level 0: Prevent other transactions from changing data that has already been modified by an uncommitted transaction.
Other transactions can read uncommitted data resulting in “dirty reads”.
-
Level 1: Prevents dirty reads. (Default on many RDBMS)
-
Level 2: prevents non-repeatable reads.
-
Level 3: Data read by one transaction is valid until the end of that transaction, preventing phantom rows.
-
Transaction unsupported: Connection.TRANSACTION_NONE
-
Level 2: Connection.TRANSACTION_SERIALIZABL
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-
See
Connection.TRANSACTION_READ_COMMITTED
andsetTransactionIsolation
. -
Note: Setting will become effective when starting next transaction.
No. 13
Isolation level 1 vs. 2
Q: |
What is the difference between Isolation level 1 and two? |
||||||||||||||||||||||||||||||
A: |
Consider the following schedule being prohibited in isolation level 1:
Isolation level 2 will prohibit successfully committed intermediate results as well:
Note that the second “read X” operation in transaction A will access successfully committed data presumably different to its first “read X” result. This is compatible with isolation level 1 since no “dirty” data is being involved. Isolation level 2 prevents this behaviour. |
No. 14
JDBC™ and transactions
Q: |
|
A: |
A connection's default state is The JDBC™ API does not provide a
“start transaction” equivalent. Instead
transactions are being started implicitly and last until Grouping two or more SQL statements into a transaction in turn requires:
|
No. 15
Aborted transactions
Q: |
In the previous exercise we mentioned the possibility of a transaction aborts being issued by a database server. Which responsibility arises for an application programmer? TipHow may an implementation become aware of an «abort transaction» event? |
A: |
On aborting a transaction a database server will cause
the corresponding JDBC™ client to throw a
|