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.
Dirty read problem :
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.
- Dirty read problem.
- Repetable read problem.
- Phantom read problem.
- READ_UNCOMMITTED
- READ_COMMITTED
- REPETABLE_READ
- SERIALIZABLE
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.
- 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.
- 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.
- Local transaction :
When a single database is participating in the transactional operation then it is called local transaction. - Distributed transaction :
When two or more database are participating in the transaction operations then it is called as distributed transaction.
- Flat transactions : A simple transaction that perform one or more operations as a unit operation.
- Nested Transactions : as the word nested says one transaction under another transaction.
This topic is really cool and very useful
ReplyDelete------------
شركة عزل اسطح بمكة
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