001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.transaction.annotation; 018 019import org.springframework.transaction.TransactionDefinition; 020 021/** 022 * Enumeration that represents transaction isolation levels for use 023 * with the {@link Transactional} annotation, corresponding to the 024 * {@link TransactionDefinition} interface. 025 * 026 * @author Colin Sampaleanu 027 * @author Juergen Hoeller 028 * @since 1.2 029 */ 030public enum Isolation { 031 032 /** 033 * Use the default isolation level of the underlying datastore. 034 * All other levels correspond to the JDBC isolation levels. 035 * @see java.sql.Connection 036 */ 037 DEFAULT(TransactionDefinition.ISOLATION_DEFAULT), 038 039 /** 040 * A constant indicating that dirty reads, non-repeatable reads and phantom reads 041 * can occur. This level allows a row changed by one transaction to be read by 042 * another transaction before any changes in that row have been committed 043 * (a "dirty read"). If any of the changes are rolled back, the second 044 * transaction will have retrieved an invalid row. 045 * @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED 046 */ 047 READ_UNCOMMITTED(TransactionDefinition.ISOLATION_READ_UNCOMMITTED), 048 049 /** 050 * A constant indicating that dirty reads are prevented; non-repeatable reads 051 * and phantom reads can occur. This level only prohibits a transaction 052 * from reading a row with uncommitted changes in it. 053 * @see java.sql.Connection#TRANSACTION_READ_COMMITTED 054 */ 055 READ_COMMITTED(TransactionDefinition.ISOLATION_READ_COMMITTED), 056 057 /** 058 * A constant indicating that dirty reads and non-repeatable reads are 059 * prevented; phantom reads can occur. This level prohibits a transaction 060 * from reading a row with uncommitted changes in it, and it also prohibits 061 * the situation where one transaction reads a row, a second transaction 062 * alters the row, and the first transaction rereads the row, getting 063 * different values the second time (a "non-repeatable read"). 064 * @see java.sql.Connection#TRANSACTION_REPEATABLE_READ 065 */ 066 REPEATABLE_READ(TransactionDefinition.ISOLATION_REPEATABLE_READ), 067 068 /** 069 * A constant indicating that dirty reads, non-repeatable reads and phantom 070 * reads are prevented. This level includes the prohibitions in 071 * {@code ISOLATION_REPEATABLE_READ} and further prohibits the situation 072 * where one transaction reads all rows that satisfy a {@code WHERE} 073 * condition, a second transaction inserts a row that satisfies that 074 * {@code WHERE} condition, and the first transaction rereads for the 075 * same condition, retrieving the additional "phantom" row in the second read. 076 * @see java.sql.Connection#TRANSACTION_SERIALIZABLE 077 */ 078 SERIALIZABLE(TransactionDefinition.ISOLATION_SERIALIZABLE); 079 080 081 private final int value; 082 083 084 Isolation(int value) { 085 this.value = value; 086 } 087 088 public int value() { 089 return this.value; 090 } 091 092}