



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of transactions, their processing, and isolation levels in the context of java enterprise edition (ejb). The author discusses the concept of a transaction, its atomicity, consistency, isolation, and durability. The document also covers flat and nested transactional processing, transaction attributes, and programmatic transactions using usertransaction interface. Additionally, it explains the different isolation levels and their impact on read and write operations.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




2006-10-
© Dr. Ye Wu
2
-^
Atomictiy – A transaction will be treated as a single unit of work
-^
Consistency – Guarantee that the transaction will leave the systemor data in a consistent state.
-^
Isolation – Data that a transaction accesses will not be affected byany changes make by other transactions until the first transactioncompletes
-^
Durability – When a transaction is committed, any changes to datathat is make must be recorded in permanent storage.
2006-10-
© Dr. Ye Wu
3
TransactionExecuting
TransactionCommitted TransactionRolled Back
Abort
2006-10-
© Dr. Ye Wu
4
TransactionExecuting
TransactionCommitted
OK Abort
Perform One or more Smaller grained Transactions
TransactionRolled Back
2006-10-
© Dr. Ye Wu
5
Programmatic transactions
Declarative transactions (Container managedtransactions)
Client-Initiated Transactions
2006-10-
© Dr. Ye Wu
6
-^
Supports – specified method will use a transaction if one is alreadyavailable. Otherwise no transaction.
-^
Required – specified method must always run within a transaction
-^
RequiresNew – specified method must always run within its owntransaction
-^
Mandatory – specified method must be invoked within the contextof a pre-existing transaction
-^
NotSupported – the method should not be run within a transaction
-^
Never -
2006-10-
© Dr. Ye Wu
7
Required – when the code needs to change thevalue of some data
Supports – when the code needs to read data froma data source
NotSupported – Communicating with resourcesthat do not support transactional processing
2006-10-
© Dr. Ye Wu
8
-^
Maintaining transactional state across multiplemethods in a stateful session bean.
-^
Providing transactional behavior for a resourcethat doesn’t provide transactional processing
-^
Java Transaction Service(JTS) – System level
-^
Java Transaction API(JTA) – Application level
2006-10-
© Dr. Ye Wu
13
Customer customer =
entityManager.find(Customer.
class
,id);
System.
out
.println(custom
er.getFirstName() + " "+customer.getLastName());
entityManager.refresh(cust omer); System.
out
.println(customer.ge
tFirstName() + " "+customer.getLastName());
Customer customer =
entityManager.find(Customer.
class
,id);
customer.setFirstName(fir stName);
customer.setLastName(las tName);
2006-10-
© Dr. Ye Wu
14
System.
out
.println(custom
er.getFirstName() + " "+customer.getLastName());
out
.println(customer.ge
tFirstName() + " "+customer.getLastName());
cust.setFirstName(fName);
cust.setLastName(lName);
2006-10-
© Dr. Ye Wu
15
System.
out
.println(custom
er.getFirstName() + " "+customer.getLastName());
out
.println(customer.ge
tFirstName() + " "+customer.getLastName());
cust.setFirstName(fName);
cust.setLastName(lName);
EJB3.0 Default
2006-10-
© Dr. Ye Wu
16
System.
out
.println(custome
r.getFirstName() + " "+customer.getLastName());
R2: System.
out
.println(customer.ge
tFirstName() + " "+customer.getLastName());
cust.setFirstName(fName);
cust.setLastName(lName);
2006-10-
© Dr. Ye Wu
17
System.
out
.println(custome
r.getFirstName() + " "+customer.getLastName());
R2: System.
out
.println(customer.ge
tFirstName() + " "+customer.getLastName());
cust.setFirstName(fName);
cust.setLastName(lName);
EJB3.0 READ Lock
2006-10-
© Dr. Ye Wu
18
System.
out
.println(custom
er.getFirstName() + " "+customer.getLastName());
out
.println(customer.ge
tFirstName() + " "+customer.getLastName());
cust.setFirstName(fName);
cust.setLastName(lName);
EJB3.0 WRITE Lock
2006-10-
© Dr. Ye Wu
19
Optimistic LockingA model takes an optimistic approach to locking the entity.i.e. it assumes there is a good chance that the transaction inwhich changes are made to an entity will be the only onethat actually changes the entity during that interval.
Pessimistic LockingA model that eagerly obtain a lock on the resource beforeoperating on it.
2006-10-
© Dr. Ye Wu
20
@Entitypublic class Customer implements Serializable {
@Versionprivate long version;public long getVersion() {
return version;
}public void setVersion(long version) {
this.version = version;
} }