01: /*
02: * $Id: AbstractXAResourceManager.java 8077 2007-08-27 20:15:25Z aperepel $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.util.xa;
12:
13: import java.util.HashMap;
14: import java.util.Map;
15:
16: import javax.transaction.xa.Xid;
17:
18: public abstract class AbstractXAResourceManager extends
19: AbstractResourceManager {
20:
21: protected Map suspendedContexts = new HashMap();
22: protected Map activeContexts = new HashMap();
23:
24: public AbstractXAResourceManager() {
25: super ();
26: }
27:
28: protected boolean includeBranchInXid() {
29: return true;
30: }
31:
32: AbstractTransactionContext getTransactionalResource(Xid xid) {
33: AbstractTransactionContext context = getActiveTransactionalResource(xid);
34: if (context != null) {
35: return context;
36: } else {
37: return getSuspendedTransactionalResource(xid);
38: }
39: }
40:
41: AbstractTransactionContext getActiveTransactionalResource(Xid xid) {
42: return (AbstractTransactionContext) activeContexts.get(xid);
43: }
44:
45: AbstractTransactionContext getSuspendedTransactionalResource(Xid xid) {
46: return (AbstractTransactionContext) suspendedContexts.get(xid);
47: }
48:
49: void addActiveTransactionalResource(Xid xid,
50: AbstractTransactionContext context) {
51: activeContexts.put(xid, context);
52: }
53:
54: void addSuspendedTransactionalResource(Xid xid,
55: AbstractTransactionContext context) {
56: suspendedContexts.put(xid, context);
57: }
58:
59: void removeActiveTransactionalResource(Xid xid) {
60: activeContexts.remove(xid);
61: }
62:
63: void removeSuspendedTransactionalResource(Xid xid) {
64: suspendedContexts.remove(xid);
65: }
66:
67: }
|