img
boolean isReadOnly();
String getName();
}
The simple and obvious methods of this interface are getTimeout(), which returns the time (in
seconds) in which the transaction must complete, and isReadOnly(), which indicates whether the
transaction is read-only. The transaction manager implementation can use this value to optimize the
execution and check to make sure that the transaction is performing only read operations. The
getName() method returns the name of the transaction.
The other two methods, getPropagationBehavior() and getIsolationLevel(), need to be discussed
in more detail. We begin with getIsolationLevel(), which controls what changes to the data other
transactions see. Table 13-1 lists the transaction isolation levels you can use and explains what changes
made in the current transaction other transactions can access.
Table 13-1. Transaction Isolation Levels
Isolation Level
Description
Default isolation level of the underlying
TransactionDefinition.ISOLATION_DEFAULT
datastore.
Lowest level of isolation; it is barely a transaction
TransactionDefinition.ISOLATION_READ_UNCOMMITTED
at all because it allows this transaction to see
data modified by other uncommitted
transactions.
Default level in most databases; it ensures that
TransactionDefinition.ISOLATION_READ_COMMITTED
other transactions are not able to read data that
has not been committed by other transactions.
However, the data that was read by one
transaction can be updated by other
transactions.
Stricter than ISOLATION_READ_COMMITED; it
TransactionDefinition.ISOLATION_REPEATABLE_READ
ensures that once you select data, you can select
at least the same set again. However, if other
transactions insert new data, you can still select
the newly inserted data.
The most expensive and reliable isolation level;
TransactionDefinition.ISOLATION_SERIALIZABLE
all transactions are treated as if they were
executed one after another.
Choosing the appropriate isolation level is very important for the consistency of the data, but
making these choices can have a great impact on performance. The highest isolation level,
TransactionDefinition.ISOLATION_SERIALIZABLE, is particularly expensive to maintain.
The getPropagationBehavior() method specifies what happens to a transactional call depending on
whether there is an active transaction. Table 13-2 describes the values for this method.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home