Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, JBoss Inc., and others contributors as indicated
   * by the @authors tag. All rights reserved.
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  *
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 2004, 2005,
  *
  * Arjuna Technologies Limited,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.
  *
  * $Id$
  */
 
 package com.arjuna.ats.internal.jdbc.recovery;
 
 
 
This provides recovery for compliant JDBC drivers. It is not meant to be implementation specific. Users are responsible for deploying an appropriate XADataSource into JNDI and then providing the relevant JNDI lookup information in a property file to an instance of this class. Username and password values may also be provided in the same property file.
 
 
 public class JDBCXARecovery implements XAResourceRecovery
 {
     public static final String DATABASE_JNDI_NAME = "DatabaseJNDIName";
     public static final String USER_NAME          = "UserName";
     public static final String PASSWORD           = "Password";
 
     /*
      * Some XAResourceRecovery implementations will do their startup work here,
      * and then do little or nothing in setDetails. Since this one needs to know
      * dynamic class name, the constructor does nothing.
      */
 
     public JDBCXARecovery()
         throws SQLException
     {
         if (..isDebugEnabled())
             ..debug("JDBCXARecovery()");
 
                            = null;
                 = false;
     }

    
The recovery module will have chopped off this class name already. The parameter should specify a property file from which the jndi name, user name, password can be read.
 
 
     public boolean initialise(String parameter)
         throws SQLException
     {
         if (..isDebugEnabled())
             ..debug("JDBCXARecovery.initialise(" + parameter + ")");
 
         if (parameter == null)
             return false;
 
         try
         {
              = PropertiesFactory.getPropertiesFromFile(parameterJDBCXARecovery.class.getClassLoader());
               = .getProperty();
                 = .getProperty();
             = .getProperty();
        }
        catch (Exception e)
        {
            return false;
        }
        return true;
    }
    public synchronized XAResource getXAResource()
        throws SQLException
    {
        createConnection();
        return .getXAResource();
    }
    public boolean hasMoreResources()
    {
        if ( == null)
            try
            {
                createDataSource();
            }
            catch (SQLException sqlException)
            {
                return false;
            }
        if ( != null)
        {
             = ! ;
            return ;
        }
        else
            return false;
    }

    
Lookup the XADataSource in JNDI. We got the relevant information from the property file provided at input to this instance.
    private final void createDataSource()
        throws SQLException
    {
        try
        {
            if ( == null)
            {
                Context context = new InitialContext();
                 = (XADataSourcecontext.lookup();
                if ( == null)
                    throw new SQLException(..get_xa_recjndierror());
            }
        }
        catch (SQLException ex)
        {
            ex.printStackTrace();
            throw ex;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            SQLException sqlException = new SQLException(e.toString());
            sqlException.initCause(e);
            throw sqlException;
        }
    }

    
Create the XAConnection from the XADataSource.
    private final void createConnection()
        throws SQLException
    {
        try
        {
            if ( == null)
                createDataSource();
            if ( == null)
            {
                if (( == null) && ( == null))
                     = .getXAConnection();
                else
                     = .getXAConnection();
            }
        }
        catch (SQLException ex)
        {
            ex.printStackTrace();
            throw ex;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            SQLException sqlException = new SQLException(e.toString());
            sqlException.initCause(e);
            throw sqlException;
        }
    }
    private class LocalConnectionEventListener implements ConnectionEventListener
    {
        public void connectionErrorOccurred(ConnectionEvent connectionEvent)
        {
             = null;
        }
        public void connectionClosed(ConnectionEvent connectionEvent)
        {
             = null;
        }
    }
    private XAConnection                 _connection;
    private XADataSource                 _dataSource;
    private Properties                   _props;
    private String                       _dbName;
    private String                       _user;
    private String                       _password;
    private boolean                      _hasMoreResources;
New to GrepCode? Check out our FAQ X