70 likes | 98 Views
Transactions. Example: Application development framework (in class) Applying Transactions to applications ACID Test Object Transactions Command Pattern (handout). ACID Test. Atomic: Indivisble unit of operation. If a single operation fails, the whole transaction fails.
E N D
Transactions • Example: Application development framework (in class) • Applying Transactions to applications • ACID Test • Object Transactions • Command Pattern (handout)
ACID Test • Atomic: • Indivisble unit of operation. If a single operation fails, the whole transaction fails. • Ensures that the state of the system remains valid at all times • Completed with a “commit” or “rollback” in databases • Network atomicity requires 2 phase commit.
ACID Test • Consistency: • Must ensure that all commands within a transaction conform to the constraints placed on the application. • Data must remain in a consistent state.
ACID Test • Isolation: • Every transaction has a consistent view of the system regardless of other, concurrent transactions. • Concurrency issues are often dealt with using locks • Optimistic locking • Pessimistic locking • Locking can lead to starvation and deadlock.
ACID Test • Durability: • Once a transaction has been completed, it's effects remain in effect even in the event of a system failure. • Durability is often achieved through the use of transaction logs. • Other methods include mirroring or replication
Object Transactions • Most databases support transactions. • Several SQL statements can be grouped together and executed as a unit. • Transactions can be committed or rolledback. • Database transactions usually involve changes to multiple tables. • Object transactions work on groups of objects rather than groups of tables. • There exist many frameworks which support object transaction models • JTA – Java Transaction API • CORBA's OTS (Object Transaction Service)
Command Pattern • ACID Transactions can be implemented using the Command design pattern. • Most command objects have an execute and undo method. • Execute is part of commit process • Undo is part of rollback process • The command must contain enough information so that it can complete the transaction or revert the transaction • If the command is half completed and an error occurs, it must undo whatever state changes have already been completed.