01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.log;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.message.Message;
11:
12: /**
13: * Represents an in-doubt transaction (a transaction in the prepare phase).
14: */
15: public class InDoubtTransaction {
16:
17: public static final int IN_DOUBT = 0, COMMIT = 1, ROLLBACK = 2;
18:
19: // TODO 2-phase-commit: document sql statements and metadata table
20:
21: private LogFile log;
22: private int sessionId;
23: private int pos;
24: private String transaction;
25: private int blocks;
26: private int state;
27:
28: public InDoubtTransaction(LogFile log, int sessionId, int pos,
29: String transaction, int blocks) {
30: this .log = log;
31: this .sessionId = sessionId;
32: this .pos = pos;
33: this .transaction = transaction;
34: this .blocks = blocks;
35: this .state = IN_DOUBT;
36: }
37:
38: public void setState(int state) throws SQLException {
39: switch (state) {
40: case COMMIT:
41: log.updatePreparedCommit(true, pos, sessionId, blocks);
42: break;
43: case ROLLBACK:
44: log.updatePreparedCommit(false, pos, sessionId, blocks);
45: break;
46: default:
47: throw Message.getInternalError("state=" + state);
48: }
49: this .state = state;
50: }
51:
52: public String getState() {
53: switch (state) {
54: case IN_DOUBT:
55: return "IN_DOUBT";
56: case COMMIT:
57: return "COMMIT";
58: case ROLLBACK:
59: return "ROLLBACK";
60: default:
61: throw Message.getInternalError("state=" + state);
62: }
63: }
64:
65: public int getPos() {
66: return pos;
67: }
68:
69: public int getSessionId() {
70: return sessionId;
71: }
72:
73: public String getTransaction() {
74: return transaction;
75: }
76:
77: }
|