分布式事务管理

南航航班号sno,日期sdate,国航航班号zno,日期zdate,姓名uname,身份证号uid,用户账号uno,电商账号bno

根代理ROOT

begin transcation;
	input(sno, sdate, zno, zdate, uname, uid, uno, bno);
	EXEC SQL 
	SELECT sold, capacity, price INTO temp1, temp2, temp3
	FROM Flight-S 
	WHERE Fno = Sno AND Date = sdate;
	
	If temp1 == temp2 then
		output("no free sets in S");
		Abort;
	Else
		EXEC SQL UPDATE Flight
		SET sold = sold + 1
		WHERE Fno = Sno AND Date = sdate;
		EXEC SQL INSERT INTO Customer-S(Cid, Cname, Fno, CDate)
		VALUES(uid, uname, sno, sdate);
		
	Create AGENT1;
	Send(AGENT1, zno, zdate, uid, uname);
	Receive(AGENT1, t3);
	sum = temp3 + t3;
	
	EXEC SQL SELECT Amount INTO temp4
	FROM U-account
	WHERE Uno = uno;
	
	If temp4 < sum then
        Output("money not enough");
        Abort;
    Else
    	EXEC SQL UPDATE U_account 
    	SET Amount = Amount-sum;
    	
    	Create AGENT2;
    	Send(AGENT2, bno, sum);
    	Commit;
End;

子代理AGENT1

Receive(ROOT, zno, zdate, uid, uname);
EXEC SQL SELECT sold, Capacity, Price
	INTO +1, +2, +3
	FROM FLight-2
	WHERE Fno = zno AND Date = zdate;
	
	If t1 == t2 then
		Output("no free seats");
		Abort;
	Else
		EXEC SQL UPDATE Flight-z 
		SET sold = sold + 1;
		WHERE Fno = zno AND Date = zdate;
		
		EXEC SQL INSERT INTO Customer-Z(Cid, Cname, Fno, CDate)
			VALUES(uid, uname, zno, zdate);
		Send(ROOT, t3);

子代理AGENT2

Receive(ROOT, bno, sum);
EXEC SQL UPDATE B-account SET Amount = Amount + sum;
WHERE Bno = bno;
posted @ 2024-01-07 23:21  清澈的澈  阅读(7)  评论(0编辑  收藏  举报