View Javadoc

1   /*
2    *   Copyright (c) 2009 The JOMC Project. All rights reserved.
3    *
4    *   Redistribution and use in source and binary forms, with or without
5    *   modification, are permitted provided that the following conditions
6    *   are met:
7    *
8    *     o Redistributions of source code must retain the above copyright
9    *       notice, this list of conditions and the following disclaimer.
10   *
11   *     o Redistributions in binary form must reproduce the above copyright
12   *       notice, this list of conditions and the following disclaimer in
13   *       the documentation and/or other materials provided with the
14   *       distribution.
15   *
16   *   THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
17   *   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18   *   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19   *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
20   *   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21   *   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22   *   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23   *   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24   *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25   *   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26   *   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   *
28   *   $Id: XAPoolHelper.java 1647 2010-03-19 22:49:14Z schulte2005 $
29   *
30   */
31  package org.jomc.standalone.ri.naming.support;
32  
33  import javax.naming.Context;
34  import javax.naming.NamingException;
35  import javax.transaction.TransactionManager;
36  import org.enhydra.jdbc.standard.StandardXADataSource;
37  import org.jomc.standalone.ri.StandaloneEnvironment;
38  
39  /**
40   * Provides static methods supporting XAPool.
41   *
42   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
43   * @version $Id: XAPoolHelper.java 1647 2010-03-19 22:49:14Z schulte2005 $
44   */
45  abstract class XAPoolHelper
46  {
47  
48      XAPoolHelper()
49      {
50          super();
51      }
52  
53      static void initializeXAPool( final StandaloneEnvironment environment, final Context context )
54          throws NamingException
55      {
56          final TransactionManager transactionManager =
57              (TransactionManager) context.lookup( environment.getTransactionManagerJndiName() );
58  
59          if ( context.lookup( environment.getDataSourceJndiName() ) instanceof StandardXADataSource )
60          {
61              final StandardXADataSource ds =
62                  (StandardXADataSource) context.lookup( environment.getDataSourceJndiName() );
63  
64              ds.setTransactionManager( transactionManager );
65          }
66          if ( context.lookup( environment.getJtaDataSourceJndiName() ) instanceof StandardXADataSource )
67          {
68              final StandardXADataSource ds =
69                  (StandardXADataSource) context.lookup( environment.getJtaDataSourceJndiName() );
70  
71              ds.setTransactionManager( transactionManager );
72          }
73      }
74  
75  }