01: /*
02: * $Id: VMTransaction.java 10489 2008-01-23 17:53:38Z dfeist $
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.transport.vm;
12:
13: import org.mule.api.MuleContext;
14: import org.mule.api.transaction.TransactionException;
15: import org.mule.config.i18n.CoreMessages;
16: import org.mule.transaction.AbstractSingleResourceTransaction;
17: import org.mule.transaction.IllegalTransactionStateException;
18: import org.mule.util.queue.QueueManager;
19: import org.mule.util.queue.QueueSession;
20: import org.mule.util.xa.ResourceManagerException;
21:
22: public class VMTransaction extends AbstractSingleResourceTransaction {
23:
24: public VMTransaction(MuleContext muleContext)
25: throws TransactionException {
26: QueueManager qm = muleContext.getQueueManager();
27: QueueSession qs = qm.getQueueSession();
28: bindResource(qm, qs);
29: }
30:
31: public void bindResource(Object key, Object resource)
32: throws TransactionException {
33: if (!(key instanceof QueueManager)
34: || !(resource instanceof QueueSession)) {
35: throw new IllegalTransactionStateException(
36: CoreMessages
37: .transactionCanOnlyBindToResources("QueueManager/QueueSession"));
38: }
39: super .bindResource(key, resource);
40: }
41:
42: protected void doBegin() throws TransactionException {
43: try {
44: ((QueueSession) resource).begin();
45: } catch (ResourceManagerException e) {
46: throw new TransactionException(CoreMessages
47: .cannotStartTransaction("VMTransaction"), e);
48: }
49: }
50:
51: protected void doCommit() throws TransactionException {
52: try {
53: ((QueueSession) resource).commit();
54: } catch (ResourceManagerException e) {
55: throw new TransactionException(CoreMessages
56: .transactionCommitFailed(), e);
57: }
58: }
59:
60: protected void doRollback() throws TransactionException {
61: try {
62: ((QueueSession) resource).rollback();
63: } catch (ResourceManagerException e) {
64: throw new TransactionException(CoreMessages
65: .transactionRollbackFailed(), e);
66: }
67: }
68:
69: }
|