01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.transaction;
18:
19: /**
20: * Exception that represents a transaction failure caused by a heuristic
21: * decision on the side of the transaction coordinator.
22: *
23: * @author Rod Johnson
24: * @author Juergen Hoeller
25: * @since 17.03.2003
26: */
27: public class HeuristicCompletionException extends TransactionException {
28:
29: /**
30: * Values for the outcome state of a heuristically completed transaction.
31: */
32: public static final int STATE_UNKNOWN = 0;
33: public static final int STATE_COMMITTED = 1;
34: public static final int STATE_ROLLED_BACK = 2;
35: public static final int STATE_MIXED = 3;
36:
37: public static String getStateString(int state) {
38: switch (state) {
39: case STATE_COMMITTED:
40: return "committed";
41: case STATE_ROLLED_BACK:
42: return "rolled back";
43: case STATE_MIXED:
44: return "mixed";
45: default:
46: return "unknown";
47: }
48: }
49:
50: /**
51: * The outcome state of the transaction: have some or all resources been committed?
52: */
53: private int outcomeState = STATE_UNKNOWN;
54:
55: /**
56: * Constructor for HeuristicCompletionException.
57: * @param outcomeState the outcome state of the transaction
58: * @param cause the root cause from the transaction API in use
59: */
60: public HeuristicCompletionException(int outcomeState,
61: Throwable cause) {
62: super ("Heuristic completion: outcome state is "
63: + getStateString(outcomeState), cause);
64: this .outcomeState = outcomeState;
65: }
66:
67: /**
68: * Return the outcome state of the transaction state,
69: * as one of the constants in this class.
70: * @see #STATE_UNKNOWN
71: * @see #STATE_COMMITTED
72: * @see #STATE_ROLLED_BACK
73: * @see #STATE_MIXED
74: */
75: public int getOutcomeState() {
76: return outcomeState;
77: }
78:
79: }
|