From fb3696bc72ce7bcbf17a5188b7fec1c5b690ad23 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 2 Oct 2006 06:08:44 +0000 Subject: Add support SNAPSHOT isolation level. --- src/main/java/com/amazon/carbonado/IsolationLevel.java | 13 +++++++++++++ .../java/com/amazon/carbonado/OptimisticLockException.java | 2 ++ .../java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java | 6 ++++++ 3 files changed, 21 insertions(+) (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/IsolationLevel.java b/src/main/java/com/amazon/carbonado/IsolationLevel.java index 5f963b2..7571205 100644 --- a/src/main/java/com/amazon/carbonado/IsolationLevel.java +++ b/src/main/java/com/amazon/carbonado/IsolationLevel.java @@ -26,6 +26,7 @@ package com.amazon.carbonado; *
  • {@link #READ_UNCOMMITTED} *
  • {@link #READ_COMMITTED} *
  • {@link #REPEATABLE_READ} + *
  • {@link #SNAPSHOT} *
  • {@link #SERIALIZABLE} * * @@ -35,6 +36,11 @@ package com.amazon.carbonado; * iteration. It releases locks during iteration rather than holding on to them * until the transaction exits. * + *

    {@code SNAPSHOT} isolation is special in that it uses multiversion + * concurrency control (MVCC). A commit may fail with an {@link + * OptimisticLockException}. Few repositories are expected to support this + * level, however. + * * @author Brian S O'Neill * @see Repository#enterTransaction(IsolationLevel) * @see Transaction @@ -71,6 +77,13 @@ public enum IsolationLevel { */ REPEATABLE_READ, + /** + * Indicates that dirty reads, non-repeatable reads and phantom reads are + * prevented. Commits can still fail however, as snapshot isolation avoids + * using locks. + */ + SNAPSHOT, + /** * Indicates that dirty reads, non-repeatable reads and phantom reads are * prevented. Phantoms are records returned as a result of a search, but diff --git a/src/main/java/com/amazon/carbonado/OptimisticLockException.java b/src/main/java/com/amazon/carbonado/OptimisticLockException.java index 2a782d1..b4a43de 100644 --- a/src/main/java/com/amazon/carbonado/OptimisticLockException.java +++ b/src/main/java/com/amazon/carbonado/OptimisticLockException.java @@ -21,6 +21,8 @@ package com.amazon.carbonado; /** * An OptimisticLockException is thrown if the {@link Repository} is using * optimistic locking for concurrency control, and lock aquisition failed. + * This exception may also be thrown if multiversion concurrency control (MVCC) + * is being used and the commit fails. * * @author Brian S O'Neill */ diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java index 6e53354..97be915 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java @@ -92,6 +92,9 @@ public class JDBCRepository return Connection.TRANSACTION_READ_COMMITTED; case REPEATABLE_READ: return Connection.TRANSACTION_REPEATABLE_READ; + case SNAPSHOT: + // TODO: not accurate for all databases. + return Connection.TRANSACTION_SERIALIZABLE; case SERIALIZABLE: return Connection.TRANSACTION_SERIALIZABLE; } @@ -117,6 +120,9 @@ public class JDBCRepository case REPEATABLE_READ: desiredLevel = IsolationLevel.SERIALIZABLE; break; + case SNAPSHOT: + desiredLevel = IsolationLevel.SERIALIZABLE; + break; case SERIALIZABLE: default: return null; } -- cgit v1.2.3