Version 4.10.0

hirondelle.web4j.database
Enum TxIsolationLevel

Object
  extended by Enum<TxIsolationLevel>
      extended by hirondelle.web4j.database.TxIsolationLevel
All Implemented Interfaces:
Serializable, Comparable<TxIsolationLevel>

public enum TxIsolationLevel
extends Enum<TxIsolationLevel>

Type-safe enumeration for transaction isolation levels.

For more information on transaction isolation levels, see Connection and the wikipedia article.

See TxTemplate, which is closely related to this class.

Permitted Values

In order of decreasing strictness (and increasing performance), the levels are :

In addition, this class includes another item called DATABASE_DEFAULT. It indicates to the WEB4J data layer that, unless instructed otherwise, the default isolation level defined by the database instance is to be used.

Differences In The Top 3 Levels

It is important to understand that the top 3 levels listed above differ only in one principal respect : behavior for any re-SELECTs performed in a transaction. If no re-SELECT is performed in a given transaction, then the there is no difference in the behavior of the top three levels (except for performance).

If a SELECT is repeated in a given transaction, it may see a different ResultSet, since some second transaction may have committed changes to the underlying data. Three questions can be asked of the second ResultSet, and each isolation level responds to these three questions in a different way :

Level 1. Can a new record appear? 2. Can an old record disappear? 3. Can an old record change?
SERIALIZABLENeverNeverNever
REPEATABLE_READPossiblyNeverNever
READ_COMMITTEDPossiblyPossiblyPossibly

(Note : 1 is called a phantom read, while both 2 and 3 are called a non-repeatable read.)

Configuration In web.xml

When no external Connection is passed by the application, then the WEB4J data layer will use an internal Connection set to the isolation level configured in web.xml.

General Guidelines

Support For Some Popular Databases

(Taken from SQL in a Nutshell, by Kline, 2004. Please confirm with your database documentation).

  DB2 MySQL Oracle PostgreSQL SQL Server
SERIALIZABLE Y Y Y Y Y
REPEATABLE_READ Y Y* N N Y
READ_COMMITTED Y Y Y* Y* Y*
READ_UNCOMMITTED Y Y N N Y
∗ Database Default


Enum Constant Summary
DATABASE_DEFAULT
           
READ_COMMITTED
           
READ_UNCOMMITTED
           
REPEATABLE_READ
           
SERIALIZABLE
           
 
Method Summary
 int getInt()
          Return the same underlying int value used by Connection to identify the isolation level.
static void set(TxIsolationLevel aLevel, Connection aConnection)
          Set a particular isolation level for aConnection.
 String toString()
          Return one of the permitted values, including 'DATABASE_DEFAULT'.
static TxIsolationLevel valueOf(String name)
          Returns the enum constant of this type with the specified name.
static TxIsolationLevel[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

SERIALIZABLE

public static final TxIsolationLevel SERIALIZABLE

REPEATABLE_READ

public static final TxIsolationLevel REPEATABLE_READ

READ_COMMITTED

public static final TxIsolationLevel READ_COMMITTED

READ_UNCOMMITTED

public static final TxIsolationLevel READ_UNCOMMITTED

DATABASE_DEFAULT

public static final TxIsolationLevel DATABASE_DEFAULT
Method Detail

values

public static TxIsolationLevel[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (TxIsolationLevel c : TxIsolationLevel.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static TxIsolationLevel valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

getInt

public int getInt()
Return the same underlying int value used by Connection to identify the isolation level.

For DATABASE_DEFAULT, return -1.


toString

public String toString()
Return one of the permitted values, including 'DATABASE_DEFAULT'.

Overrides:
toString in class Enum<TxIsolationLevel>

set

public static void set(TxIsolationLevel aLevel,
                       Connection aConnection)
Set a particular isolation level for aConnection.

This method exists because database support for isolation levels varies widely. If any error occurs because aLevel is not supported, then the error will be logged at a SEVERE level, but the application will continue to run. This policy treats isolation levels as important, but non-critical. Porting an application to a database which does not support all levels will not cause an application to fail. The transaction will simply execute at the database's default isolation level.

Passing in the special value DATABASE_DEFAULT will cause a no-operation.


Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.