KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > store > InDoubtTransaction


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.store;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.message.Message;
10
11 public class InDoubtTransaction {
12     
13     public static final int IN_DOUBT = 0, COMMIT = 1, ROLLBACK = 2;
14     
15     // TODO 2-phase-commit: document sql statements and metadata table
16

17     private LogFile log;
18     private int sessionId;
19     private int pos;
20     private String JavaDoc transaction;
21     private int blocks;
22     private int state;
23
24     public InDoubtTransaction(LogFile log, int sessionId, int pos, String JavaDoc transaction, int blocks) {
25         this.log = log;
26         this.sessionId = sessionId;
27         this.pos = pos;
28         this.transaction = transaction;
29         this.blocks = blocks;
30         this.state = IN_DOUBT;
31     }
32     
33     public void setState(int state) throws SQLException JavaDoc {
34         switch(state) {
35         case COMMIT:
36             log.updatePreparedCommit(true, pos, sessionId, blocks);
37             break;
38         case ROLLBACK:
39             log.updatePreparedCommit(false, pos, sessionId, blocks);
40             break;
41         default:
42             throw Message.getInternalError("state="+state);
43         }
44         this.state = state;
45     }
46     
47     public String JavaDoc getState() {
48         switch(state) {
49         case IN_DOUBT:
50             return "IN_DOUBT";
51         case COMMIT:
52             return "COMMIT";
53         case ROLLBACK:
54             return "ROLLBACK";
55         default:
56             throw Message.getInternalError("state="+state);
57         }
58     }
59
60     public int getPos() {
61         return pos;
62     }
63
64     public int getSessionId() {
65         return sessionId;
66     }
67
68     public String JavaDoc getTransaction() {
69         return transaction;
70     }
71
72 }
73
Popular Tags