To understand isolations level better, lets review the main colitions that may happend in concurrent
environment:
- lost update - A second transaction writes a second value of a data on top of a first value written by a first concurrent transaction, and the first value is lost to other transactions running concurrently which need, by their precedence, to read the first value.
- dirty read - insert or update data by transaction that will be rollbacked further
- non-repeatable read - first transaction read data, then read them again and the same data is modified
- phantom reads - on the second read in transaction, new data is appearing
So, now that's easy to describe isolation levels with the following table:
Isolation level | JDBC equivalent | Dirty reads | Non-repeatable reads | Phantoms | Lost update |
---|---|---|---|---|---|
None | TRANSACTION_NONE | may occur | may occur | may occur | may occur |
Read Uncommitted | TRANSACTION_READ_UNCOMMITTED | may occur | may occur | may occur | - |
Read Committed | TRANSACTION_READ_COMMITTED | - | may occur | may occur | - |
Repeatable Read | TRANSACTION_REPEATABLE_READ | - | - | may occur | - |
Serializible | TRANSACTION_SERIALIZABLE | - | - | - | - |
In Java world you can set up any of them on JDBC driver, however there is not guarantee that this level will be applied! Test your database programmatically using the supportsTransactionIsolationLevel() method in java.sql.DatabaseMetaData to be sure.
RDBMSs are supporting isolation levels according to the following table:
Isolation level | MySQL (InnoDb) | Oracle | DB2 | H2 | Postgres |
Read Uncommitted | + | - | + | + | + |
Read Committed | + | + | + | + | + |
Repeatable Read | + | + | + | - | + |
Serializible | + | + | + | + | + |
More about transactions in MySQL
More about transactions in Oracle
More about transaction isolation level in IBM DB2
More about transaction in H2
More about transactions in Postgres
Немає коментарів:
Дописати коментар