Upload
phani
View
215
Download
1
Embed Size (px)
DESCRIPTION
klm
Citation preview
Transaction management inJDBCint fundtransfer(source account no.,destination account no.,amount);{b1=getBal(destination_account_no);b2=getBal(source_account_no);b2=b2-amount;b1=b1+amount;s1=update account set bal=b1,!"ere accont_no=destination _account_no.s2=update account set bal=b2 !"ere account-no=source_account_no;e#ecute(s1);Ye#ecute(s2);X $ccount %&n t"e abo'e scenario !e are doing t!o database operation (pdating account table one record and anot"er is alsoupdating account table anot"er record. !e "a'e to assume fund transfer operation is completed successfull) onl)!"en t"ese t!o operation are successfull) but !e can get t"e problem in t"e abo'e scenario some times.$ssumet"at 1stupdatestatement ise#ecutedsuccessfull)andduetosomeregion(*et!or+failure,gate!a)failure, database ser'er bus), database ser'er cras"ed ) second operation is failed . ,"is gi'es )ou t"e inconsistentresult .Region for problem----- B) default auto commit is true !it" all t"e database collections. i.e. !it" one connection.if )ou submit one .uer) to t"e database engine t"ere !ill be e#ecuted and immediatel) commit !ill be issued,!it"one connection !"en )ou submit multiple .uer) t"e commit !ill be issue multiple times. Solution ---- ,o sol'e t"e abo'e discuss problem )ou can use ,ransaction. ,ransaction is not"ing but performingmultiple databaseoperation "as one unit !it" all /not"ing 0 all or not"ing preposition. !"en all t"e operations . int"e transaction (unit)are successful t"en transaction is successfull) and an) one operation in t"e unit is failedt"en transaction is failed.1"en t"e transaction is successfull) )ou "a'e to issue commit and !"en t"e transaction is failed )ou "a'e toissue 2ollbac+ !"en )ou manage t"e transaction properl) ,transaction guarantee $3&4 propert)$ $tomicit)33onsistenc)& &solation4 4urabilit) Type of transaction --------- Based on t"e number of resources in'ol'ing in t"e transaction )ou can di'ide t"e transaction into t!o parts----------- 5ocal ,ransaction 4istributed ,ransactionLocal Transaction -------- !"en onl) one resource is in'ol'ing in t"e transaction t"en it is called as local transaction.NOTE ---- resource can be a database or database_connection. 64B3 support local ,ransaction.Distributed Transaction ------ !"en multiple resources are in'ol'ing in t"e transaction t"en it is called distributed transaction .64B3 dont support 4istributed ,ransaction .You can manage the transaction with one of the following technology and framework------ 64B3 7ibernate 86BLocal Transaction 9pring:ou can manage t"e 4istributed ,ransaction !it" t"e "elp of 86B and 9pring.D.T 4.,D.T 4.,Mysl $cc_no acc_t)pe acc_name bal 11 9$ $ 1;+12 9$B