[jboss-svn-commits] JBL Code SVN: r9004 - labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 24 05:57:58 EST 2007
Author: mark.little at jboss.com
Date: 2007-01-24 05:57:58 -0500 (Wed, 24 Jan 2007)
New Revision: 9004
Added:
labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java
labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/OracleXARecovery.java
Modified:
labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java
labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBC2RecoveryConnection.java
Log:
Added in resource recovery implementations from Arjuna used at Glencore.
Modified: labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java 2007-01-24 09:51:01 UTC (rev 9003)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/BasicXARecovery.java 2007-01-24 10:57:58 UTC (rev 9004)
@@ -35,17 +35,11 @@
import com.arjuna.ats.jdbc.common.jdbcPropertyManager;
import com.arjuna.ats.jdbc.logging.jdbcLogger;
-import com.arjuna.ats.internal.jdbc.*;
-
import com.arjuna.ats.jta.recovery.XAResourceRecovery;
-import com.arjuna.ats.arjuna.common.*;
-
import com.arjuna.common.util.logging.*;
import java.sql.*;
-import javax.sql.*;
-import javax.transaction.*;
import javax.transaction.xa.*;
import java.util.*;
@@ -53,249 +47,265 @@
import com.arjuna.common.internal.util.propertyservice.plugins.io.XMLFilePlugin;
/**
- * This class implements the XAResourceRecovery interface for XAResources.
- * The parameter supplied in setParameters can contain arbitrary information
+ * This class implements the XAResourceRecovery interface for XAResources. The
+ * parameter supplied in setParameters can contain arbitrary information
* necessary to initialise the class once created. In this instance it contains
* the name of the property file in which the db connection information is
* specified, as well as the number of connections that this file contains
* information on (separated by ;).
- *
+ *
* IMPORTANT: this is only an *example* of the sorts of things an
- * XAResourceRecovery implementor could do. This implementation uses
- * a property file which is assumed to contain sufficient information to
- * recreate connections used during the normal run of an application so that
- * we can perform recovery on them. It is not recommended that information such
- * as user name and password appear in such a raw text format as it opens up
- * a potential security hole.
- *
- * The db parameters specified in the property file are assumed to be
- * in the format:
- *
- * DB_x_DatabaseURL=
- * DB_x_DatabaseUser=
- * DB_x_DatabasePassword=
+ * XAResourceRecovery implementor could do. This implementation uses a property
+ * file which is assumed to contain sufficient information to recreate
+ * connections used during the normal run of an application so that we can
+ * perform recovery on them. It is not recommended that information such as user
+ * name and password appear in such a raw text format as it opens up a potential
+ * security hole.
+ *
+ * The db parameters specified in the property file are assumed to be in the
+ * format:
+ *
+ * DB_x_DatabaseURL= DB_x_DatabaseUser= DB_x_DatabasePassword=
* DB_x_DatabaseDynamicClass=
- *
- * DB_JNDI_x_DatabaseURL=
- * DB_JNDI_x_DatabaseUser=
- * DB_JNDI_x_DatabasePassword=
- *
+ *
+ * DB_JNDI_x_DatabaseURL= DB_JNDI_x_DatabaseUser= DB_JNDI_x_DatabasePassword=
+ *
* where x is the number of the connection information.
- *
+ *
* @since JTS 2.1.
*/
public class BasicXARecovery implements XAResourceRecovery
-{
- /*
- * 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 BasicXARecovery () throws SQLException
- {
- if (jdbcLogger.logger.isDebugEnabled())
+{
+ /*
+ * 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 BasicXARecovery () throws SQLException
{
- jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC,
- com.arjuna.ats.arjuna.logging.FacilityCode.FAC_CRASH_RECOVERY,
- "BasicXARecovery ()");
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger
+ .debug(
+ DebugLevel.CONSTRUCTORS,
+ VisibilityLevel.VIS_PUBLIC,
+ com.arjuna.ats.arjuna.logging.FacilityCode.FAC_CRASH_RECOVERY,
+ "BasicXARecovery ()");
+ }
+
+ numberOfConnections = 1;
+ connectionIndex = 0;
+ props = null;
}
- numberOfConnections = 1;
- connectionIndex = 0;
- props = null;
- }
+ /**
+ * The recovery module will have chopped off this class name already. The
+ * parameter should specify a property file from which the url, user name,
+ * password, etc. can be read.
+ *
+ * @message com.arjuna.ats.internal.jdbc.recovery.basic.initexp An exception
+ * occurred during initialisation.
+ */
- /**
- * The recovery module will have chopped off this class name already.
- * The parameter should specify a property file from which the url,
- * user name, password, etc. can be read.
- *
- * @message com.arjuna.ats.internal.jdbc.recovery.initexp An exception occurred during initialisation.
- */
+ public boolean initialise (String parameter) throws SQLException
+ {
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger
+ .debug(
+ DebugLevel.CONSTRUCTORS,
+ VisibilityLevel.VIS_PUBLIC,
+ com.arjuna.ats.arjuna.logging.FacilityCode.FAC_CRASH_RECOVERY,
+ "BasicXARecovery.setDetail(" + parameter + ")");
+ }
- public boolean initialise (String parameter) throws SQLException
- {
- if (jdbcLogger.logger.isDebugEnabled())
- {
- jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC,
- com.arjuna.ats.arjuna.logging.FacilityCode.FAC_CRASH_RECOVERY,
- "BasicXARecovery.setDetail(" + parameter + ")");
+ if (parameter == null)
+ return true;
+
+ int breakPosition = parameter.indexOf(BREAKCHARACTER);
+ String fileName = parameter;
+
+ if (breakPosition != -1)
+ {
+ fileName = parameter.substring(0, breakPosition - 1);
+
+ try
+ {
+ numberOfConnections = Integer.parseInt(parameter
+ .substring(breakPosition + 1));
+ }
+ catch (NumberFormatException e)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N.warn(
+ "com.arjuna.ats.internal.jdbc.recovery.basic.initexp",
+ new Object[] { e });
+ }
+
+ return false;
+ }
+ }
+
+ try
+ {
+ String uri = com.arjuna.common.util.FileLocator
+ .locateFile(fileName);
+ jdbcPropertyManager.propertyManager.load(XMLFilePlugin.class
+ .getName(), uri);
+
+ props = jdbcPropertyManager.propertyManager.getProperties();
+ }
+ catch (Exception e)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N.warn(
+ "com.arjuna.ats.internal.jdbc.recovery.basic.initexp",
+ new Object[] { e });
+ }
+
+ return false;
+ }
+
+ if (jdbcLogger.logger.isDebugEnabled())
+ {
+ jdbcLogger.logger
+ .debug(
+ DebugLevel.CONSTRUCTORS,
+ VisibilityLevel.VIS_PUBLIC,
+ com.arjuna.ats.arjuna.logging.FacilityCode.FAC_CRASH_RECOVERY,
+ "BasicXARecovery properties file = " + parameter);
+ }
+
+ return true;
}
- if (parameter == null)
- return true;
-
- int breakPosition = parameter.indexOf(BREAKCHARACTER);
- String fileName = parameter;
-
- if (breakPosition != -1)
+ /**
+ * @message com.arjuna.ats.internal.jdbc.recovery.basic.xarec {0} could not find
+ * information for connection!
+ */
+
+ public synchronized XAResource getXAResource () throws SQLException
{
- fileName = parameter.substring(0, breakPosition -1);
+ JDBC2RecoveryConnection conn = null;
- try
- {
- numberOfConnections = Integer.parseInt(parameter.substring(breakPosition +1));
- }
- catch (NumberFormatException e)
- {
- if (jdbcLogger.loggerI18N.isWarnEnabled())
+ if (hasMoreResources())
{
- jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.recovery.initexp",
- new Object[] {e});
+ connectionIndex++;
+
+ conn = getStandardConnection();
+
+ if (conn == null) conn = getJNDIConnection();
+
+ if (conn == null)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N.warn(
+ "com.arjuna.ats.internal.jdbc.recovery.basic.xarec",
+ new Object[] { "BasicXARecovery.getConnection -" });
+ }
+ }
}
-
- return false;
- }
+
+ return conn.recoveryConnection().getConnection().getXAResource();
}
-
- try
- {
- String uri = com.arjuna.common.util.FileLocator.locateFile(fileName);
- jdbcPropertyManager.propertyManager.load(XMLFilePlugin.class.getName(), uri);
- props = jdbcPropertyManager.propertyManager.getProperties();
- }
- catch (Exception e)
+ public synchronized boolean hasMoreResources ()
{
- if (jdbcLogger.loggerI18N.isWarnEnabled())
- {
- jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.recovery.initexp",
- new Object[] {e});
- }
-
- return false;
+ if (connectionIndex == numberOfConnections)
+ return false;
+ else
+ return true;
}
-
- if (jdbcLogger.logger.isDebugEnabled())
+
+ private final JDBC2RecoveryConnection getStandardConnection ()
+ throws SQLException
{
- jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC,
- com.arjuna.ats.arjuna.logging.FacilityCode.FAC_CRASH_RECOVERY,
- "BasicXARecovery properties file = " + parameter);
+ String number = new String("" + connectionIndex);
+ String url = new String(dbTag + number + urlTag);
+ String password = new String(dbTag + number + passwordTag);
+ String user = new String(dbTag + number + userTag);
+ String dynamicClass = new String(dbTag + number + dynamicClassTag);
+
+ Properties dbProperties = new Properties();
+
+ String theUser = props.getProperty(user);
+ String thePassword = props.getProperty(password);
+
+ if (theUser != null)
+ {
+ dbProperties.put(TransactionalDriver.userName, theUser);
+ dbProperties.put(TransactionalDriver.password, thePassword);
+
+ String dc = props.getProperty(dynamicClass);
+
+ if (dc != null)
+ dbProperties.put(TransactionalDriver.dynamicClass, dc);
+
+ return new JDBC2RecoveryConnection(url, dbProperties);
+ }
+ else
+ return null;
}
-
- return true;
- }
- /**
- * @message com.arjuna.ats.internal.jdbc.recovery.xarec {0} could not find information for connection!
- */
-
- public synchronized XAResource getXAResource () throws SQLException
- {
- JDBC2RecoveryConnection conn = null;
-
- if (hasMoreResources())
+ private final JDBC2RecoveryConnection getJNDIConnection ()
+ throws SQLException
{
- connectionIndex++;
+ String number = new String("" + connectionIndex);
+ String url = new String(dbTag + jndiTag + number + urlTag);
+ String password = new String(dbTag + jndiTag + number + passwordTag);
+ String user = new String(dbTag + jndiTag + number + userTag);
- conn = getStandardConnection();
+ Properties dbProperties = new Properties();
- if (conn == null)
- conn = getJNDIConnection();
-
- if (conn == null)
- {
- if (jdbcLogger.loggerI18N.isWarnEnabled())
+ String theUser = props.getProperty(user);
+ String thePassword = props.getProperty(password);
+
+ if (theUser != null)
{
- jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.recovery.xarec",
- new Object[] {"BasicXARecovery.getConnection -"});
+ dbProperties.put(TransactionalDriver.userName, theUser);
+ dbProperties.put(TransactionalDriver.password, thePassword);
+
+ return new JDBC2RecoveryConnection(url, dbProperties);
}
- }
+ else
+ return null;
}
- return conn.recoveryConnection().getConnection().getXAResource();
- }
+ private int numberOfConnections;
- public synchronized boolean hasMoreResources ()
- {
- if (connectionIndex == numberOfConnections)
- return false;
- else
- return true;
- }
+ private int connectionIndex;
- private final JDBC2RecoveryConnection getStandardConnection () throws SQLException
- {
- String number = new String(""+connectionIndex);
- String url = new String(dbTag+number+urlTag);
- String password = new String(dbTag+number+passwordTag);
- String user = new String(dbTag+number+userTag);
- String dynamicClass = new String(dbTag+number+dynamicClassTag);
+ private Properties props;
- Properties dbProperties = new Properties();
+ private static final String dbTag = "DB_";
- String theUser = props.getProperty(user);
- String thePassword = props.getProperty(password);
+ private static final String urlTag = "_DatabaseURL";
- if (theUser != null)
- {
- dbProperties.put(TransactionalDriver.userName, theUser);
- dbProperties.put(TransactionalDriver.password, thePassword);
-
- String dc = props.getProperty(dynamicClass);
-
- if (dc != null)
- dbProperties.put(TransactionalDriver.dynamicClass, dc);
+ private static final String passwordTag = "_DatabasePassword";
- return new JDBC2RecoveryConnection(url, dbProperties);
- }
- else
- return null;
- }
+ private static final String userTag = "_DatabaseUser";
- private final JDBC2RecoveryConnection getJNDIConnection () throws SQLException
- {
- String number = new String(""+connectionIndex);
- String url = new String(dbTag+jndiTag+number+urlTag);
- String password = new String(dbTag+jndiTag+number+passwordTag);
- String user = new String(dbTag+jndiTag+number+userTag);
+ private static final String dynamicClassTag = "_DatabaseDynamicClass";
- Properties dbProperties = new Properties();
+ private static final String jndiTag = "JNDI_";
- String theUser = props.getProperty(user);
- String thePassword = props.getProperty(password);
+ /*
+ * Example:
+ *
+ * DB2_DatabaseURL=jdbc\:arjuna\:sequelink\://qa02\:20001
+ * DB2_DatabaseUser=tester2 DB2_DatabasePassword=tester
+ * DB2_DatabaseDynamicClass=com.arjuna.ats.internal.jdbc.drivers.sequelink_5_1
+ *
+ * DB_JNDI_DatabaseURL=jdbc\:arjuna\:jndi DB_JNDI_DatabaseUser=tester1
+ * DB_JNDI_DatabasePassword=tester DB_JNDI_DatabaseName=empay
+ * DB_JNDI_Host=qa02 DB_JNDI_Port=20000
+ */
- if (theUser != null)
- {
- dbProperties.put(TransactionalDriver.userName, theUser);
- dbProperties.put(TransactionalDriver.password, thePassword);
-
- return new JDBC2RecoveryConnection(url, dbProperties);
- }
- else
- return null;
- }
+ private static final char BREAKCHARACTER = ';'; // delimiter for parameters
- private int numberOfConnections;
- private int connectionIndex;
- private Properties props;
-
- private static final String dbTag = "DB_";
- private static final String urlTag = "_DatabaseURL";
- private static final String passwordTag = "_DatabasePassword";
- private static final String userTag = "_DatabaseUser";
- private static final String dynamicClassTag = "_DatabaseDynamicClass";
- private static final String jndiTag = "JNDI_";
-
- /*
- * Example:
- *
- * DB2_DatabaseURL=jdbc\:arjuna\:sequelink\://qa02\:20001
- * DB2_DatabaseUser=tester2
- * DB2_DatabasePassword=tester
- * DB2_DatabaseDynamicClass=com.arjuna.ats.internal.jdbc.drivers.sequelink_5_1
- *
- * DB_JNDI_DatabaseURL=jdbc\:arjuna\:jndi
- * DB_JNDI_DatabaseUser=tester1
- * DB_JNDI_DatabasePassword=tester
- * DB_JNDI_DatabaseName=empay
- * DB_JNDI_Host=qa02
- * DB_JNDI_Port=20000
- */
-
- private static final char BREAKCHARACTER = ';'; // delimiter for parameters
-
}
-
Modified: labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBC2RecoveryConnection.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBC2RecoveryConnection.java 2007-01-24 09:51:01 UTC (rev 9003)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBC2RecoveryConnection.java 2007-01-24 10:57:58 UTC (rev 9004)
@@ -31,45 +31,40 @@
package com.arjuna.ats.internal.jdbc.recovery;
-import com.arjuna.ats.arjuna.common.*;
-
-import com.arjuna.ats.jdbc.TransactionalDriver;
-
import com.arjuna.ats.internal.jdbc.ConnectionImple;
import java.util.Properties;
import java.sql.*;
-import javax.sql.*;
-import javax.transaction.*;
-import javax.transaction.xa.*;
/**
- * To perform recovery on arbitrary connections we may need
- * to recreate those connections.
- *
- * The ArjunaJDBC2Connection class must not be used directly by
- * applications, hence the requirement for this class.
- *
+ * To perform recovery on arbitrary connections we may need to recreate those
+ * connections.
+ *
+ * The ArjunaJDBC2Connection class must not be used directly by applications,
+ * hence the requirement for this class.
+ *
* @since JTS 2.1.
*/
public class JDBC2RecoveryConnection extends ConnectionImple
{
- public JDBC2RecoveryConnection (String dbName, Properties info) throws SQLException
- {
- super(dbName, info);
- }
-
- public JDBC2RecoveryConnection (String dbName, String user, String passwd) throws SQLException
- {
- this(dbName, user, passwd, null);
- }
-
- public JDBC2RecoveryConnection (String dbName, String user, String passwd, String dynamic) throws SQLException
- {
- super(dbName, user, passwd, dynamic);
- }
-
-}
+ public JDBC2RecoveryConnection (String dbName, Properties info)
+ throws SQLException
+ {
+ super(dbName, info);
+ }
+ public JDBC2RecoveryConnection (String dbName, String user, String passwd)
+ throws SQLException
+ {
+ this(dbName, user, passwd, null);
+ }
+
+ public JDBC2RecoveryConnection (String dbName, String user, String passwd,
+ String dynamic) throws SQLException
+ {
+ super(dbName, user, passwd, dynamic);
+ }
+
+}
Added: labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/JDBCXARecovery.java 2007-01-24 10:57:58 UTC (rev 9004)
@@ -0,0 +1,253 @@
+/*
+ * 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;
+
+import java.util.*;
+import java.sql.*;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.*;
+import javax.transaction.xa.*;
+import com.arjuna.common.util.logging.*;
+import com.arjuna.common.internal.util.propertyservice.plugins.io.XMLFilePlugin;
+import com.arjuna.ats.arjuna.logging.FacilityCode;
+import com.arjuna.ats.jdbc.common.*;
+import com.arjuna.ats.jdbc.logging.jdbcLogger;
+import com.arjuna.ats.jta.recovery.XAResourceRecovery;
+
+/**
+ * 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 (jdbcLogger.logger.isDebugEnabled())
+ jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_CRASH_RECOVERY, "JDBCXARecovery()");
+
+ _props = null;
+ _hasMoreResources = false;
+ _connectionEventListener = new LocalConnectionEventListener();
+ }
+
+ /**
+ * 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.
+ *
+ * @message com.arjuna.ats.internal.jdbc.recovery.xa.initexp An exception
+ * occurred during initialisation.
+ */
+
+ public boolean initialise(String parameter)
+ throws SQLException
+ {
+ if (jdbcLogger.logger.isDebugEnabled())
+ jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_CRASH_RECOVERY, "JDBCXARecovery.initialise(" + parameter + ")");
+
+ if (parameter == null)
+ return false;
+
+ try
+ {
+ jdbcPropertyManager.propertyManager.load(XMLFilePlugin.class.getName(), parameter);
+
+ _props = jdbcPropertyManager.propertyManager.getProperties();
+
+ _dbName = _props.getProperty(DATABASE_JNDI_NAME);
+ _user = _props.getProperty(USER_NAME);
+ _password = _props.getProperty(PASSWORD);
+ }
+ catch (Exception e)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.recovery.xa.initexp", new Object[] { e });
+
+ e.printStackTrace();
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @message com.arjuna.ats.internal.jdbc.recovery.xa.xarec {0} could not find
+ * information for connection!
+ */
+
+ public synchronized XAResource getXAResource()
+ throws SQLException
+ {
+ createConnection();
+
+ return _connection.getXAResource();
+ }
+
+ public boolean hasMoreResources()
+ {
+ if (_dataSource == null)
+ try
+ {
+ createDataSource();
+ }
+ catch (SQLException sqlException)
+ {
+ return false;
+ }
+
+ if (_dataSource != null)
+ {
+ _hasMoreResources = ! _hasMoreResources;
+
+ return _hasMoreResources;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Lookup the XADataSource in JNDI. We got the relevant information from the
+ * property file provided at input to this instance.
+ *
+ * @message com.arjuna.ats.internal.jdbc.xa.recjndierror Could not resolve JNDI
+ * XADataSource
+ */
+
+ private final void createDataSource()
+ throws SQLException
+ {
+ try
+ {
+ if (_dataSource == null)
+ {
+ Context context = new InitialContext();
+ _dataSource = (XADataSource) context.lookup(_dbName);
+
+ if (_dataSource == null)
+ throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.xa.recjndierror"));
+ }
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+
+ throw ex;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ throw new SQLException(e.toString());
+ }
+ }
+
+ /**
+ * Create the XAConnection from the XADataSource.
+ */
+
+ private final void createConnection()
+ throws SQLException
+ {
+ try
+ {
+ if (_dataSource == null)
+ createDataSource();
+
+ if (_connection == null)
+ {
+ if ((_user == null) && (_password == null))
+ _connection = _dataSource.getXAConnection();
+ else
+ _connection = _dataSource.getXAConnection(_user, _password);
+
+ _connection.addConnectionEventListener(_connectionEventListener);
+ }
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+
+ throw ex;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ throw new SQLException(e.toString());
+ }
+ }
+
+ private class LocalConnectionEventListener implements ConnectionEventListener
+ {
+ public void connectionErrorOccurred(ConnectionEvent connectionEvent)
+ {
+ _connection.removeConnectionEventListener(_connectionEventListener);
+ _connection = null;
+ }
+
+ public void connectionClosed(ConnectionEvent connectionEvent)
+ {
+ _connection.removeConnectionEventListener(_connectionEventListener);
+ _connection = null;
+ }
+ }
+
+ private XAConnection _connection;
+ private XADataSource _dataSource;
+ private LocalConnectionEventListener _connectionEventListener;
+ private Properties _props;
+ private String _dbName;
+ private String _user;
+ private String _password;
+ private boolean _hasMoreResources;
+}
Added: labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/OracleXARecovery.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/OracleXARecovery.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/jdbc/classes/com/arjuna/ats/internal/jdbc/recovery/OracleXARecovery.java 2007-01-24 10:57:58 UTC (rev 9004)
@@ -0,0 +1,250 @@
+/*
+ * 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;
+
+import java.util.*;
+import java.sql.*;
+import javax.sql.*;
+import javax.transaction.xa.*;
+import com.arjuna.common.util.logging.*;
+import com.arjuna.common.internal.util.propertyservice.plugins.io.XMLFilePlugin;
+import com.arjuna.ats.arjuna.logging.FacilityCode;
+import com.arjuna.ats.jdbc.common.*;
+import com.arjuna.ats.jdbc.logging.jdbcLogger;
+import com.arjuna.ats.jta.recovery.XAResourceRecovery;
+import oracle.jdbc.xa.client.OracleXADataSource;
+
+/**
+ * This provides resource recovery for Oracle JDBC drivers.
+ *
+ * Users are responsible for DataSource creation information in a property file to
+ * setup this class. Username and password values may also be provided in
+ * the same property file.
+ */
+
+public class OracleXARecovery implements XAResourceRecovery
+{
+ public static final String DATABASE_URL = "DatabaseURL";
+ public static final String USER_NAME = "UserName";
+ public static final String PASSWORD = "Password";
+
+ /*
+ * Some XAResourceRecovery implementations will do their startup work here.
+ */
+
+ public OracleXARecovery()
+ throws SQLException
+ {
+ if (jdbcLogger.logger.isDebugEnabled())
+ jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_CRASH_RECOVERY, "JDBCXARecovery()");
+
+ _props = null;
+ _hasMoreResources = false;
+ _connectionEventListener = new LocalConnectionEventListener();
+ }
+
+ /**
+ * The recovery module will have chopped off this class name already. The
+ * parameter should specify a property file from which the url, user name,
+ * password can be read.
+ *
+ * @message com.arjuna.ats.internal.jdbc.recovery.oracle.initexp An exception
+ * occurred during initialisation.
+ */
+
+ public boolean initialise(String parameter)
+ throws SQLException
+ {
+ if (jdbcLogger.logger.isDebugEnabled())
+ jdbcLogger.logger.debug(DebugLevel.CONSTRUCTORS, VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_CRASH_RECOVERY, "JDBCXARecovery.initialise(" + parameter + ")");
+
+ if (parameter == null)
+ return false;
+
+ try
+ {
+ jdbcPropertyManager.propertyManager.load(XMLFilePlugin.class.getName(), parameter);
+
+ _props = jdbcPropertyManager.propertyManager.getProperties();
+
+ _dbURL = _props.getProperty(DATABASE_URL);
+ _user = _props.getProperty(USER_NAME);
+ _password = _props.getProperty(PASSWORD);
+ }
+ catch (Exception e)
+ {
+ if (jdbcLogger.loggerI18N.isWarnEnabled())
+ {
+ jdbcLogger.loggerI18N.warn("com.arjuna.ats.internal.jdbc.recovery.oracle.initexp", new Object[] { e });
+
+ e.printStackTrace();
+ }
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @message com.arjuna.ats.internal.jdbc.recovery.oracle.xarec {0} could not find
+ * information for connection!
+ */
+
+ public synchronized XAResource getXAResource()
+ throws SQLException
+ {
+ createConnection();
+
+ return _connection.getXAResource();
+ }
+
+ public boolean hasMoreResources()
+ {
+ if (_dataSource == null)
+ try
+ {
+ createDataSource();
+ }
+ catch (SQLException sqlException)
+ {
+ return false;
+ }
+
+ if (_dataSource != null)
+ {
+ _hasMoreResources = ! _hasMoreResources;
+
+ return _hasMoreResources;
+ }
+ else
+ return false;
+ }
+
+ /**
+ * Creating and initalising an OracleXADataSource instance. We got the relevant information from the
+ * property file provided at input to this instance.
+ *
+ * @message com.arjuna.ats.internal.jdbc.oracle.recjndierror Could not resolve JNDI
+ * XADataSource
+ */
+
+ private final void createDataSource()
+ throws SQLException
+ {
+ try
+ {
+ if (_dataSource == null)
+ {
+ OracleXADataSource dataSource = new OracleXADataSource();
+ dataSource.setURL(_dbURL);
+
+ _dataSource = dataSource;
+
+ if (_dataSource == null)
+ throw new SQLException(jdbcLogger.logMesg.getString("com.arjuna.ats.internal.jdbc.oracle.recjndierror"));
+ }
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+
+ throw ex;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ throw new SQLException(e.toString());
+ }
+ }
+
+ /**
+ * Create the XAConnection from the XADataSource.
+ */
+
+ private final void createConnection()
+ throws SQLException
+ {
+ try
+ {
+ if (_dataSource == null)
+ createDataSource();
+
+ if (_connection == null)
+ {
+ if ((_user == null) && (_password == null))
+ _connection = _dataSource.getXAConnection();
+ else
+ _connection = _dataSource.getXAConnection(_user, _password);
+
+ _connection.addConnectionEventListener(_connectionEventListener);
+ }
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+
+ throw ex;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ throw new SQLException(e.toString());
+ }
+ }
+
+ private class LocalConnectionEventListener implements ConnectionEventListener
+ {
+ public void connectionErrorOccurred(ConnectionEvent connectionEvent)
+ {
+ _connection.removeConnectionEventListener(_connectionEventListener);
+ _connection = null;
+ }
+
+ public void connectionClosed(ConnectionEvent connectionEvent)
+ {
+ _connection.removeConnectionEventListener(_connectionEventListener);
+ _connection = null;
+ }
+ }
+
+ private XAConnection _connection;
+ private XADataSource _dataSource;
+ private LocalConnectionEventListener _connectionEventListener;
+ private Properties _props;
+ private String _dbURL;
+ private String _user;
+ private String _password;
+ private boolean _hasMoreResources;
+}
More information about the jboss-svn-commits
mailing list