Transaction is the process of performing multiple database operations as one unit with all nothing criteria.
I:e when all the database operations in the unit are successful then transaction is successful and should be committed. When any one database operation in the unit are failed then transaction are failed and should be rolled back.

When you implement transaction property in your application it guarantees ACID properties.
A- Atomicity
C- Consistency
I- Isolation
D- Durability

Atomicity : It will give you a guarantee that the whole work will be performed as a unit. If one part of transaction fails then entire transaction fails.

Consistency : Consistency is about ensuring that any transaction will bring the database from one valid state to another.

Isolation : Many transaction may run concurrently. These concurrently running multiple transaction may disturb other transaction that is multiple transaction should run isolately.

Case A : Consider the case where multiple transaction running concurrently and using multiple rows of account table.
tx1 -> 101
tx2 -> 102
tx3 -> 103

1. withdraw from 101
2. withdraw from 102
3. withdraw from 103

Case B : Consider the case where multiple transaction running concurrently and using single account row of account table.
acc no: 99

1. transfer(withdraw)
2. bank teller(withdraw(deposite))
3. loan EMI(withdraw)
in case B you may get some problem which is called as transnational concurrency problems.

  1. Dirty read problem.
  2. Repetable read problem.
  3. Phantom read problem. 
To avoid these problems, you have to apply one of the following required transactional isolation levels.

  1. READ_UNCOMMITTED
  2. READ_COMMITTED
  3. REPETABLE_READ
  4. SERIALIZABLE
Durability : Yoyr enterprise data should be available for long time as long as your enterprise is running. You have to protect your data from crashes, failures, you have to implements your proper backup and recovery mechanism and proper loging mechanism.

Dirty read problem :

  • When transaction reads the dirty value(modified but not committed) then you may get some inconsistent result.
  • To avoid dirty read you have to lock the column(cell).
  • To lock the column you have to apply isolation level called READ-COMMITTED.
Repetable read problem :

  • When a transaction is reading the same row repeatedly, you may get different set of values in different reads. this kind of problem is called repeatable read problem.
  • To avoid repeatable read problem you have to lock the row.
  • To lock the row you have to apply isolation level called REPEATABLE-READ.
Phantom read problem :

  • When a transaction is reading the set of row repeatedly you may get different set of rows in different reads this kind of problem is called phantom read problem. 
  • To avoid phantom read you have to lock the entire table.
  • To lock the table you have to apply isolation level called SERIALIZABLE.
Types Of Transaction :

  1. Local transaction :
    When a single database is participating in the transactional operation then it is called local transaction.
  2. Distributed transaction :
    When two or more database are participating in the transaction operations then it is called as distributed transaction.
Types Of Transaction :

  1. Flat transactions : A simple transaction that perform one or more operations as a unit operation.
  2. Nested Transactions : as the word nested says one transaction under another transaction.


2 comments:

  1. This topic is really cool and very useful
    ------------
    شركة عزل اسطح بمكة

    ReplyDelete
  2. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java EE Online Training Students.

    ReplyDelete

Blog Archive

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic