View Javadoc

1   /*
2    * $Id: VMTransactionFactory.java 22701 2011-08-19 07:18:40Z mike.schilling $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.vm;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.transaction.Transaction;
15  import org.mule.api.transaction.TransactionException;
16  import org.mule.api.transaction.TransactionFactory;
17  
18  public class VMTransactionFactory implements TransactionFactory
19  {
20      public static TransactionFactory factoryDelegate = new VMTransactionFactoryDelegate();
21  
22      public Transaction beginTransaction(MuleContext muleContext) throws TransactionException
23      {
24          return factoryDelegate.beginTransaction(muleContext);
25      }
26  
27      public boolean isTransacted()
28      {
29          return factoryDelegate.isTransacted();
30      }
31  
32      /**
33       * sets the transaction factory to be used to create VM transactions
34       */
35      public static void setFactoryDelegate(TransactionFactory factoryDelegate)
36      {
37          VMTransactionFactory.factoryDelegate = factoryDelegate;
38      }
39  
40      /**
41       * Create normal VM transactions
42       */
43      static class VMTransactionFactoryDelegate implements TransactionFactory
44      {
45          public Transaction beginTransaction(MuleContext muleContext) throws TransactionException
46          {
47              VMTransaction tx = new VMTransaction(muleContext);
48              tx.begin();
49              return tx;
50          }
51  
52          public boolean isTransacted()
53          {
54              return true;
55          }
56      }
57  
58  }