Index: main/org/castor/jdo/engine/AbstractConnectionFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/castor/jdo/engine/AbstractConnectionFactory.java,v retrieving revision 1.3 diff -u -r1.3 AbstractConnectionFactory.java --- main/org/castor/jdo/engine/AbstractConnectionFactory.java 2 Aug 2005 22:15:29 -0000 1.3 +++ main/org/castor/jdo/engine/AbstractConnectionFactory.java 15 Aug 2005 19:47:13 -0000 @@ -17,10 +17,14 @@ import java.util.Enumeration; +import javax.transaction.TransactionManager; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.exolab.castor.jdo.conf.Database; +import org.exolab.castor.jdo.conf.JdoConf; +import org.exolab.castor.jdo.transactionmanager.TransactionManagerRegistry; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.mapping.MappingException; import org.exolab.castor.persist.LockEngine; @@ -50,8 +54,11 @@ /** Has the factory been initialized? */ private boolean _initialized = false; - /** The database configuration. */ - private Database _database; + /** The jdo configuartion. */ + private JdoConf _jdoConf; + + /** Index of the database configuration in the jdo configuration. */ + private int _index; /** The name of the database configuration. */ private String _name; @@ -59,6 +66,9 @@ /** The mapping to load. */ private Mapping _mapping; + /** The transaction manager. */ + private TransactionManager _txManager; + /** The LockEngine only available after initialization. */ private LockEngine _engine = null; @@ -70,15 +80,19 @@ * * @param name The Name of the database configuration. * @param engine The Name of the persistence factory to use. + * @param txManager The transaction manager to use. * @param mapping The previously loaded mapping. * @throws MappingException If LockEngine could not be initialized. */ protected AbstractConnectionFactory(final String name, final String engine, - final Mapping mapping) + final Mapping mapping, + final TransactionManager txManager) throws MappingException { - _database = null; + _jdoConf = null; + _index = -1; _name = name; _mapping = mapping; + _txManager = txManager; initializeEngine(engine); _initialized = true; @@ -88,13 +102,17 @@ * Constructs a new AbstractConnectionFactory with given database and mapping. * Initialize needs to be called before using the factory to create connections. * - * @param database The database configuration. + * @param jdoConf The jdo configuartion. + * @param index Index of the database configuration in the jdo configuration. * @param mapping The mapping to load. */ - protected AbstractConnectionFactory(final Database database, final Mapping mapping) { - _database = database; - _name = database.getName(); + protected AbstractConnectionFactory(final JdoConf jdoConf, final int index, + final Mapping mapping) { + _jdoConf = jdoConf; + _index = index; + _name = jdoConf.getDatabase(index).getName(); _mapping = mapping; + _txManager = null; } //-------------------------------------------------------------------------- @@ -110,7 +128,8 @@ // this request to initialize it. if (!_initialized) { initializeMapping(); - initializeEngine(_database.getEngine()); + _txManager = TransactionManagerRegistry.getTransactionManager(_jdoConf); + initializeEngine(_jdoConf.getDatabase(_index).getEngine()); initializeFactory(); _initialized = true; @@ -125,7 +144,7 @@ private void initializeMapping() throws MappingException { try { // Initialize all the mappings of the database. - Enumeration mappings = _database.enumerateMapping(); + Enumeration mappings = _jdoConf.getDatabase(_index).enumerateMapping(); org.exolab.castor.jdo.conf.Mapping mapConf; while (mappings.hasMoreElements()) { mapConf = (org.exolab.castor.jdo.conf.Mapping) mappings.nextElement(); @@ -180,13 +199,6 @@ //-------------------------------------------------------------------------- /** - * Get the database configuration. - * - * @return The database configuration. - */ - public final Database getDatabase() { return _database; } - - /** * Get the name of the database configuration. * * @return The name of the database configuration. @@ -194,11 +206,25 @@ public final String getName() { return _name; } /** + * Get the database configuration. + * + * @return The database configuration. + */ + public final Database getDatabase() { return _jdoConf.getDatabase(_index); } + + /** * Get the mapping to load. * * @return The mapping to load. */ public final Mapping getMapping() { return _mapping; } + + /** + * Get the transaction manager. + * + * @return The transaction manager. + */ + public final TransactionManager getTransactionManager() { return _txManager; } /** * Get the LockEngine only available after initialization. Index: main/org/castor/jdo/engine/DataSourceConnectionFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/castor/jdo/engine/DataSourceConnectionFactory.java,v retrieving revision 1.4 diff -u -r1.4 DataSourceConnectionFactory.java --- main/org/castor/jdo/engine/DataSourceConnectionFactory.java 7 Aug 2005 09:55:02 -0000 1.4 +++ main/org/castor/jdo/engine/DataSourceConnectionFactory.java 15 Aug 2005 19:47:13 -0000 @@ -20,12 +20,14 @@ import java.sql.SQLException; import javax.sql.DataSource; +import javax.transaction.TransactionManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.exolab.castor.jdo.conf.Database; import org.exolab.castor.jdo.conf.DatabaseChoice; +import org.exolab.castor.jdo.conf.JdoConf; import org.exolab.castor.jdo.conf.Param; import org.exolab.castor.jdo.drivers.ConnectionProxy; import org.exolab.castor.mapping.Mapping; @@ -178,12 +180,15 @@ * @param engine The Name of the persistence factory to use. * @param datasource The preconfigured datasource to use for creating connections. * @param mapping The previously loaded mapping. + * @param txManager The transaction manager to use. * @throws MappingException If LockEngine could not be initialized. */ - public DataSourceConnectionFactory(final String name, final String engine, - final DataSource datasource, final Mapping mapping) + public DataSourceConnectionFactory( + final String name, final String engine, final DataSource datasource, + final Mapping mapping, final TransactionManager txManager) throws MappingException { - super(name, engine, mapping); + super(name, engine, mapping, txManager); + _dataSource = datasource; } @@ -191,11 +196,13 @@ * Constructs a new DataSourceConnectionFactory with given database and mapping. * Initialize needs to be called before using the factory to create connections. * - * @param database The database configuration. + * @param jdoConf An in-memory jdo configuration. + * @param index Index of the database configuration inside the jdo configuration. * @param mapping The mapping to load. */ - public DataSourceConnectionFactory(final Database database, final Mapping mapping) { - super(database, mapping); + public DataSourceConnectionFactory(final JdoConf jdoConf, final int index, + final Mapping mapping) { + super(jdoConf, index, mapping); } /** Index: main/org/castor/jdo/engine/DatabaseRegistry.java =================================================================== RCS file: /scm/castor/castor/src/main/org/castor/jdo/engine/DatabaseRegistry.java,v retrieving revision 1.3 diff -u -r1.3 DatabaseRegistry.java --- main/org/castor/jdo/engine/DatabaseRegistry.java 2 Aug 2005 22:15:29 -0000 1.3 +++ main/org/castor/jdo/engine/DatabaseRegistry.java 15 Aug 2005 19:47:14 -0000 @@ -18,18 +18,23 @@ import java.util.Hashtable; import javax.sql.DataSource; +import javax.transaction.TransactionManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.exolab.castor.jdo.conf.Database; +import org.exolab.castor.jdo.conf.DatabaseChoice; import org.exolab.castor.jdo.conf.JdoConf; -import org.exolab.castor.jdo.engine.JDOConfLoader; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.mapping.MappingException; +import org.exolab.castor.util.DTDResolver; import org.exolab.castor.util.LocalConfiguration; import org.exolab.castor.util.Messages; +import org.exolab.castor.xml.MarshalException; +import org.exolab.castor.xml.Unmarshaller; +import org.exolab.castor.xml.ValidationException; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; @@ -44,6 +49,11 @@ public final class DatabaseRegistry { //-------------------------------------------------------------------------- + /** Temporary note to check for the changed jdo-conf syntax. */ + private static final String NOTE_096 = + "NOTE: JDO configuration syntax has changed with castor 0.9.6, " + + "please see http://castor.codehaus.org/release-notes.html for details"; + /** Property telling if database should be initialized when loading. */ private static final String INITIALIZE_AT_LOAD = "org.exolab.castor.jdo.DatabaseInitializeAtLoad"; @@ -65,14 +75,16 @@ * @param engine The Name of the persistence factory to use. * @param datasource The preconfigured datasource to use for creating connections. * @param mapping The previously loaded mapping. + * @param txManager The transaction manager to use. * @throws MappingException If LockEngine could not be initialized. */ - public static synchronized void loadDatabase(final String name, final String engine, - final DataSource datasource, - final Mapping mapping) + public static synchronized void loadDatabase( + final String name, final String engine, final DataSource datasource, + final Mapping mapping, final TransactionManager txManager) throws MappingException { - AbstractConnectionFactory factory; - factory = new DataSourceConnectionFactory(name, engine, datasource, mapping); + AbstractConnectionFactory factory = new DataSourceConnectionFactory( + name, engine, datasource, mapping, txManager); + if (FACTORIES.put(name, factory) != null) { LOG.warn(Messages.format("jdo.configLoadedTwice", name)); } @@ -81,7 +93,7 @@ /** * Instantiates a ConnectionFactory from an in-memory JDO configuration. * - * @param jdoConf An in-memory JDO configuration. + * @param jdoConf An in-memory jdo configuration. * @param resolver An entity resolver. * @param loader A class loader * @throws MappingException If the database cannot be instantiated/loadeed. @@ -90,8 +102,7 @@ final EntityResolver resolver, final ClassLoader loader) throws MappingException { - Database[] databases = JDOConfLoader.getDatabases(jdoConf); - loadDatabase(databases, resolver, loader, null); + loadDatabase(jdoConf, resolver, loader, null); } /** @@ -107,8 +118,22 @@ final ClassLoader loader) throws MappingException { // Load the JDO configuration file from the specified input source. - Database[] databases = JDOConfLoader.getDatabases(source, resolver); - loadDatabase(databases, resolver, loader, source.getSystemId()); + JdoConf jdoConf = null; + + Unmarshaller unmarshaller = new Unmarshaller(JdoConf.class); + try { + unmarshaller.setEntityResolver(new DTDResolver(resolver)); + jdoConf = (JdoConf) unmarshaller.unmarshal(source); + } catch (MarshalException e) { + LOG.info(NOTE_096); + throw new MappingException(e); + } catch (ValidationException e) { + throw new MappingException(e); + } + + LOG.debug("Loaded jdo conf successfully"); + + loadDatabase(jdoConf, resolver, loader, source.getSystemId()); } /** @@ -119,13 +144,13 @@ * to false it will instantiate all databases only when they are * needed. * - * @param databases Database configuration instances. + * @param jdoConf An in-memory jdo configuration. * @param resolver An entity resolver. * @param loader A class loader * @param baseURI The base URL for the mapping * @throws MappingException If the database cannot be instantiated/loadeed. */ - private static synchronized void loadDatabase(final Database[] databases, + private static synchronized void loadDatabase(final JdoConf jdoConf, final EntityResolver resolver, final ClassLoader loader, final String baseURI) @@ -138,23 +163,21 @@ // Load the JDO configuration file from the specified input source. // databases = JDOConfLoader.getDatabases(baseURI, resolver); - Database database; - Mapping mapping; + Database[] databases = jdoConf.getDatabase(); AbstractConnectionFactory factory; for (int i = 0; i < databases.length; i++) { - database = databases[i]; - // Load the mapping file from the URL specified in the database // configuration file, relative to the configuration file. // Fail if cannot load the mapping for whatever reason. - mapping = new Mapping(loader); + Mapping mapping = new Mapping(loader); if (resolver != null) { mapping.setEntityResolver(resolver); } if (baseURI != null) { mapping.setBaseURL(baseURI); } - factory = DatabaseRegistry.createFactory(database, mapping); + factory = DatabaseRegistry.createFactory(jdoConf, i, mapping); if (init) { factory.initialize(); } - if (FACTORIES.put(database.getName(), factory) != null) { - LOG.warn(Messages.format("jdo.configLoadedTwice", database.getName())); + String name = databases[i].getName(); + if (FACTORIES.put(name, factory) != null) { + LOG.warn(Messages.format("jdo.configLoadedTwice", name)); } } } @@ -163,37 +186,41 @@ * Factory methode to create a ConnectionFactory for given database configuration * and given mapping. * - * @param database The database configuration. + * @param jdoConf An in-memory jdo configuration. + * @param index Index of the database configuration inside the jdo configuration. * @param mapping The mapping to load. * @return The ConnectionFactory. * @throws MappingException If the database cannot be instantiated/loadeed. */ - private static AbstractConnectionFactory createFactory(final Database database, - final Mapping mapping) + private static AbstractConnectionFactory createFactory( + final JdoConf jdoConf, final int index, final Mapping mapping) throws MappingException { AbstractConnectionFactory factory; - if (database.getDatabaseChoice() == null) { - String msg = Messages.format("jdo.missingDataSource", database.getName()); + DatabaseChoice choice = jdoConf.getDatabase(index).getDatabaseChoice(); + if (choice == null) { + String name = jdoConf.getDatabase(index).getName(); + String msg = Messages.format("jdo.missingDataSource", name); LOG.error(msg); throw new MappingException(msg); } - if (database.getDatabaseChoice().getDriver() != null) { + if (choice.getDriver() != null) { // JDO configuration file specifies a driver, use the driver // properties to create a new registry object. - factory = new DriverConnectionFactory(database, mapping); - } else if (database.getDatabaseChoice().getDataSource() != null) { + factory = new DriverConnectionFactory(jdoConf, index, mapping); + } else if (choice.getDataSource() != null) { // JDO configuration file specifies a DataSource object, use the // DataSource which was configured from the JDO configuration file // to create a new registry object. - factory = new DataSourceConnectionFactory(database, mapping); - } else if (database.getDatabaseChoice().getJndi() != null) { + factory = new DataSourceConnectionFactory(jdoConf, index, mapping); + } else if (choice.getJndi() != null) { // JDO configuration file specifies a DataSource lookup through JNDI, // locate the DataSource object frome the JNDI namespace and use it. - factory = new JNDIConnectionFactory(database, mapping); + factory = new JNDIConnectionFactory(jdoConf, index, mapping); } else { - String msg = Messages.format("jdo.missingDataSource", database.getName()); + String name = jdoConf.getDatabase(index).getName(); + String msg = Messages.format("jdo.missingDataSource", name); LOG.error(msg); throw new MappingException(msg); } @@ -251,9 +278,6 @@ */ public static void clear() { FACTORIES.clear(); - - // reset the JDO configuration data to re-enable loadConfiguration() - JDOConfLoader.deleteConfiguration(); } //-------------------------------------------------------------------------- Index: main/org/castor/jdo/engine/DriverConnectionFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/castor/jdo/engine/DriverConnectionFactory.java,v retrieving revision 1.2 diff -u -r1.2 DriverConnectionFactory.java --- main/org/castor/jdo/engine/DriverConnectionFactory.java 24 Jul 2005 20:37:15 -0000 1.2 +++ main/org/castor/jdo/engine/DriverConnectionFactory.java 15 Aug 2005 19:47:14 -0000 @@ -23,9 +23,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.exolab.castor.jdo.conf.Database; import org.exolab.castor.jdo.conf.DatabaseChoice; import org.exolab.castor.jdo.conf.Driver; +import org.exolab.castor.jdo.conf.JdoConf; import org.exolab.castor.jdo.conf.Param; import org.exolab.castor.jdo.drivers.ConnectionProxy; import org.exolab.castor.mapping.Mapping; @@ -58,11 +58,13 @@ /** * Constructs a new DriverConnectionFactory with given database and mapping. * - * @param database The database configuration. + * @param jdoConf An in-memory jdo configuration. + * @param index Index of the database configuration inside the jdo configuration. * @param mapping The mapping to load. */ - public DriverConnectionFactory(final Database database, final Mapping mapping) { - super(database, mapping); + public DriverConnectionFactory(final JdoConf jdoConf, final int index, + final Mapping mapping) { + super(jdoConf, index, mapping); } /** Index: main/org/castor/jdo/engine/JNDIConnectionFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/castor/jdo/engine/JNDIConnectionFactory.java,v retrieving revision 1.2 diff -u -r1.2 JNDIConnectionFactory.java --- main/org/castor/jdo/engine/JNDIConnectionFactory.java 24 Jul 2005 20:37:15 -0000 1.2 +++ main/org/castor/jdo/engine/JNDIConnectionFactory.java 15 Aug 2005 19:47:15 -0000 @@ -26,8 +26,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.exolab.castor.jdo.conf.Database; import org.exolab.castor.jdo.conf.DatabaseChoice; +import org.exolab.castor.jdo.conf.JdoConf; import org.exolab.castor.jdo.drivers.ConnectionProxy; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.mapping.MappingException; @@ -56,11 +56,13 @@ /** * Constructs a new JNDIConnectionFactory with given database and mapping. * - * @param database The database configuration. + * @param jdoConf An in-memory jdo configuration. + * @param index Index of the database configuration inside the jdo configuration. * @param mapping The mapping to load. */ - public JNDIConnectionFactory(final Database database, final Mapping mapping) { - super(database, mapping); + public JNDIConnectionFactory(final JdoConf jdoConf, final int index, + final Mapping mapping) { + super(jdoConf, index, mapping); } /** Index: main/org/exolab/castor/jdo/JDO.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/JDO.java,v retrieving revision 1.13 diff -u -r1.13 JDO.java --- main/org/exolab/castor/jdo/JDO.java 24 Jul 2005 17:48:18 -0000 1.13 +++ main/org/exolab/castor/jdo/JDO.java 15 Aug 2005 19:47:17 -0000 @@ -64,16 +64,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.castor.jdo.engine.AbstractConnectionFactory; import org.castor.jdo.engine.DatabaseRegistry; import org.exolab.castor.jdo.conf.JdoConf; -import org.exolab.castor.jdo.conf.TransactionDemarcation; import org.exolab.castor.jdo.engine.DatabaseImpl; -import org.exolab.castor.jdo.engine.JDOConfLoader; import org.exolab.castor.jdo.engine.TxDatabaseMap; -import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory; -import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactoryRegistry; import org.exolab.castor.jdo.transactionmanager.spi.LocalTransactionManagerFactory; import org.exolab.castor.mapping.MappingException; import org.exolab.castor.persist.OutputLogInterceptor; @@ -566,86 +563,21 @@ _classLoader); // alternatively, use a JdoConf instance to load the JDO config } else if (_jdoConf != null) { - DatabaseRegistry.loadDatabase(_jdoConf, - _entityResolver, - _classLoader); + DatabaseRegistry.loadDatabase(_jdoConf, _entityResolver, + _classLoader); } else { throw new DatabaseNotFoundException(Messages.format( "jdo.dbNoMapping", _dbName)); } } + + AbstractConnectionFactory factory; + factory = DatabaseRegistry.getConnectionFactory(_dbName); + _transactionManager = factory.getTransactionManager(); } catch (MappingException ex) { throw new DatabaseNotFoundException(ex); } - // load transaction manager factory registry configuration - try { - TransactionManagerFactoryRegistry.load( - new InputSource(_jdoConfURI), _entityResolver); - } catch (TransactionManagerAcquireException ex) { - throw new PersistenceException(Messages.message( - "jdo.problem.initializingTransactionManagerFactory"), ex); - } - - if (_transactionManagerFactory == null) { - String transactionMode = null; - try { - TransactionDemarcation demarcation; - String mode; - org.exolab.castor.jdo.conf.TransactionManager manager; - - demarcation = JDOConfLoader.getTransactionDemarcation( - new InputSource(_jdoConfURI), _entityResolver); - - mode = demarcation.getMode(); - manager = demarcation.getTransactionManager(); - - if (manager != null) { - transactionMode = manager.getName(); - } else if (LocalTransactionManagerFactory.NAME.equals(mode)) { - transactionMode = LocalTransactionManagerFactory.NAME; - } else { - throw new PersistenceException(Messages.message( - "jdo.problem.missingTransactionConfiguration")); - } - - } catch (MappingException ex) { - throw new PersistenceException(Messages.message( - "jdo.problem.noValidTransactionMode"), ex); - } - - /* - * Try to obtain the specifiedTransactionManagerFactory - * instance from the registry. - * - * If the returned TransactionManagerFactory instance is null, - * return an exception to indicate that we cannot live without a - * valid TransactionManagerFactory instance and that the user should - * change her configuration. - */ - _transactionManagerFactory = TransactionManagerFactoryRegistry - .getTransactionManagerFactory(transactionMode); - - if (_transactionManagerFactory == null) { - throw new DatabaseNotFoundException(Messages.format( - "jdo.transaction.missingTransactionManagerFactory", - transactionMode)); - } - - /* - * Try to obtain a javax.jta.TransactionManager>/code> from - * the factory. - */ - try { - _transactionManager = _transactionManagerFactory - .getTransactionManager(); - } catch (TransactionManagerAcquireException ex) { - throw new DatabaseNotFoundException(Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", - _transactionManagerFactory.getName(), ex)); - } - } - /* At this point, we MUST have a instance of TransactionManagerFactory, * and dependent on its type (LOCAL or not), we MIGHT have a valid * javax.jta.TransactionManager instance. Index: main/org/exolab/castor/jdo/JDOManager.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/JDOManager.java,v retrieving revision 1.7 diff -u -r1.7 JDOManager.java --- main/org/exolab/castor/jdo/JDOManager.java 4 Aug 2005 07:31:16 -0000 1.7 +++ main/org/exolab/castor/jdo/JDOManager.java 15 Aug 2005 19:47:19 -0000 @@ -72,14 +72,8 @@ import org.castor.jdo.engine.DatabaseRegistry; import org.exolab.castor.jdo.conf.JdoConf; -import org.exolab.castor.jdo.conf.TransactionDemarcation; import org.exolab.castor.jdo.engine.DatabaseImpl; -import org.exolab.castor.jdo.engine.JDOConfLoader; import org.exolab.castor.jdo.engine.TxDatabaseMap; -import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; -import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory; -import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactoryRegistry; -import org.exolab.castor.jdo.transactionmanager.spi.LocalTransactionManagerFactory; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.mapping.MappingException; import org.exolab.castor.persist.LockEngine; @@ -178,12 +172,6 @@ */ private static InputSource _source; - /** - * The transaction demarcation descriptor; only set when setting demarcation - * programmatically within an application. - */ - private static TransactionDemarcation _globalTransactionDemarcation = null; - //-------------------------------------------------------------------------- /** @@ -237,20 +225,18 @@ * @param name The Name of the database configuration. * @param engine The Name of the persistence factory to use. * @param datasource The preconfigured datasource to use for creating connections. - * @param demarcation The transaction demarcation to use. * @param mapping The previously loaded mapping. + * @param txManager The transaction manager to use. * @throws MappingException If LockEngine could not be initialized. */ - public static void loadConfiguration(final String name, final String engine, - final DataSource datasource, - final TransactionDemarcation demarcation, - final Mapping mapping) + public static void loadConfiguration( + final String name, final String engine, final DataSource datasource, + final Mapping mapping, final TransactionManager txManager) throws MappingException { - DatabaseRegistry.loadDatabase(name, engine, datasource, mapping); + DatabaseRegistry.loadDatabase(name, engine, datasource, mapping, txManager); _classLoader = null; _entityResolver = null; - _globalTransactionDemarcation = demarcation; LOG.debug("Successfully loaded JDOManager form preconfigured datasource"); } @@ -275,7 +261,6 @@ _classLoader = loader; _entityResolver = resolver; - _globalTransactionDemarcation = jdoConf.getTransactionDemarcation(); LOG.debug("Successfully loaded JDOManager form in-memory configuration"); } @@ -406,17 +391,6 @@ */ private String _databaseName; - /** - * The transaction manager factory to be used to obtain a - * javax.jta.TransactionManager instance. - */ - private TransactionManagerFactory _transactionManagerFactory = null; - - /** - * The transaction manager - */ - private TransactionManager _transactionManager = null; - //-------------------------------------------------------------------------- /** @@ -615,12 +589,12 @@ /** * Enable/disable database pooling. This option only affects JDOManager - * if transactionManager is set and a transaction is associated - * with the thread that call {@link #getDatabase}. If database pooling is - * enabled, JDOManager will first search in the pool to see if there is - * already a database for the current transaction. If found, it returns the - * database; if not, it create a new one, associates it will the transaction - * and return the newly created database. + * if J2EE transactions and a transaction is associated with the thread + * that call {@link #getDatabase}. If database pooling is enabled, JDOManager + * will first search in the pool to see if there is already a database for the + * current transaction. If found, it returns the database; if not, it create a + * new one, associates it will the transaction and return the newly created + * database. *

* This method should be called before {@link #getDatabase}. *

@@ -637,7 +611,7 @@ return; } else { throw new IllegalStateException( - "JDO Pooling started. It can not be set to false"); + "JDO Pooling started. It can not be set to false."); } } else if (_txDbPool == null) { _txDbPool = new TxDatabaseMap(); @@ -655,7 +629,7 @@ * @return True if pooling is enabled for this Database instance. */ public boolean getDatabasePooling() { - return _txDbPool != null; + return (_txDbPool != null); } /** @@ -709,170 +683,93 @@ */ public Database getDatabase() throws PersistenceException { if (_databaseName == null) { - LOG.error("getDatabase() called without specifying database name"); - throw new IllegalStateException(Messages.message( - "jdo.missing.database.name")); + String msg = Messages.message("jdo.missing.database.name"); + LOG.error(msg); + throw new IllegalStateException(msg); } - + + TransactionManager transactionManager = null; try { if (!DatabaseRegistry.isDatabaseRegistred(_databaseName)) { if (_jdoConfURI == null) { - LOG.error("No configuration loaded for database " - + _databaseName); - throw new DatabaseNotFoundException(Messages.format( - "jdo.dbNoMapping", _databaseName)); + String msg = Messages.format("jdo.dbNoMapping", _databaseName); + LOG.error(msg); + throw new DatabaseNotFoundException(msg); } - DatabaseRegistry.loadDatabase(_jdoConfURI, - _entityResolver, - _classLoader); + DatabaseRegistry.loadDatabase(_jdoConfURI, _entityResolver, _classLoader); } + + AbstractConnectionFactory factory; + factory = DatabaseRegistry.getConnectionFactory(_databaseName); + transactionManager = factory.getTransactionManager(); } catch (MappingException ex) { - LOG.error("Problem loading database configuration", ex); - throw new DatabaseNotFoundException(Messages.format( - "jdo.problem.loading.conf", _jdoConfURI), ex); - } - - String transactionMode = null; - - if (_globalTransactionDemarcation != null) { - // We have been provided a JdoConf with one hardwired in. - // In all likelihood, we're not interested in source-reading, as - // we probably haven't got one. - // Let's extract the name to use. - String mode = _globalTransactionDemarcation.getMode(); - org.exolab.castor.jdo.conf.TransactionManager manager = - _globalTransactionDemarcation.getTransactionManager(); - if (manager != null) { - transactionMode = manager.getName(); - } else if (mode.equalsIgnoreCase(LocalTransactionManagerFactory.NAME)) { - transactionMode = LocalTransactionManagerFactory.NAME; - } else { - LOG.error("Missing configuration for TransactionManager"); - throw new PersistenceException(Messages.message( - "jdo.problem.missingTransactionConfiguration")); - } - } else { - // load transaction manager factory registry configuration. + String msg = Messages.format("jdo.problem.loading.conf", _jdoConfURI); + LOG.error(msg, ex); + throw new DatabaseNotFoundException(msg, ex); + } + + Transaction tx = null; + int status = -1; + // If we have a transaction manager we are inm J2EE mode. + if (transactionManager != null) { + // Now we need a valid Transaction. try { - TransactionManagerFactoryRegistry.load(_jdoConfURI, - _entityResolver); - } catch (TransactionManagerAcquireException ex) { - LOG.error("Failed to initalize TransactionManagerFactory", ex); - throw new PersistenceException(Messages.message( - "jdo.problem.initializingTransactionManagerFactory"), ex); - } - - if (_transactionManagerFactory == null) { - try { - TransactionDemarcation demarcation; - String mode; - org.exolab.castor.jdo.conf.TransactionManager manager; - - demarcation = JDOConfLoader.getTransactionDemarcation( - _jdoConfURI, _entityResolver); - mode = demarcation.getMode(); - manager = demarcation.getTransactionManager(); - - if (manager != null) { - transactionMode = manager.getName(); - } else if (mode.equals(LocalTransactionManagerFactory.NAME)) { - transactionMode = LocalTransactionManagerFactory.NAME; - } else { - LOG.error("Missing configuration for TransactionManager"); - throw new PersistenceException(Messages.message( - "jdo.problem.missingTransactionConfiguration")); - } - } catch (MappingException ex) { - LOG.error("No valid mode for TransactionManager", ex); - throw new PersistenceException(Messages.message( - "jdo.problem.noValidTransactionMode"), ex); + tx = transactionManager.getTransaction(); + if (tx != null) { status = tx.getStatus(); } + + // If transaction is not active fall back to LOCAL mode. + if ((tx != null) && (tx.getStatus() == Status.STATUS_ACTIVE)) { + tx = null; } + } catch (Exception ex) { // SystemException + // Failed to get transaction from transaction manager or failed to get + // status information from transaction. + String msg = Messages.message("jdo.manager.failCreateTransaction"); + LOG.error(msg, ex); + throw new PersistenceException(msg, ex); } - } - - /* - * Try to obtain the specifiedTransactionManagerFactory - * instance from the registry. - * - * If the returned TransactionManagerFactory instance is null, - * return an exception to indicate that we cannot live without a - * valid TransactionManagerFactory instance and that the user - * should change the configuration. - */ - _transactionManagerFactory = TransactionManagerFactoryRegistry - .getTransactionManagerFactory(transactionMode); - - if (_transactionManagerFactory == null) { - LOG.error("Missing TransactionManagerFactory"); - throw new DatabaseNotFoundException(Messages.format( - "jdo.transaction.missingTransactionManagerFactory", - transactionMode)); - } - - /* - * Try to obtain a javax.jta.TransactionManager>/code> from - * the factory. - */ - try { - _transactionManager = _transactionManagerFactory - .getTransactionManager(); - - } catch (TransactionManagerAcquireException ex) { - LOG.error("Unable to acquire TransactionManager", ex); - throw new DatabaseNotFoundException(Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", - _transactionManagerFactory.getName()), ex); - } - - /* At this point, we MUST have a valid TransactionManagerFactory, and - * dependent on its type (LOCAL or not), we MIGHT have a valid - * javax.jta.TransactionManager instance. - * - * Scenario 1: If the user uses Castor in standalone mode (outside of an - * J2EE container), we have a TransactionManagerFactory instance only, - * but no TransactionManager instance. - * - * Scenario 2: If the user uses Castor in J2EE mode (inside of an J2EE - * container), and wants the container to control transaction - * demarcation, we have both a TransactionManagerFactory and a - * TransactionManager instance. - */ - if ((_transactionManager != null) - && !LocalTransactionManagerFactory.NAME.equals( - _transactionManagerFactory.getName())) { - Transaction tx; - DatabaseImpl dbImpl; + if ((tx == null) || (status != Status.STATUS_ACTIVE)) { + String msg = Messages.message("jdo.manager.failGetTransaction"); + LOG.error(msg); + throw new PersistenceException(msg); + } + } + + DatabaseImpl dbImpl; - try { - tx = _transactionManager.getTransaction(); - if ((_txDbPool != null) && (_txDbPool.containsTx(tx))) { - return _txDbPool.get(tx); - } + // If we have a transaction and a database pool that contains a database + // for this transaction we can reuse this database. In all other cases + // we need to create a new database instance. + if ((tx != null) && (_txDbPool != null) && (_txDbPool.containsTx(tx))) { + dbImpl = _txDbPool.get(tx); + } else { + dbImpl = new DatabaseImpl(_databaseName, _lockTimeout, _callbackInterceptor, + _instanceFactory, tx, _classLoader, _autoStore); - if ((tx != null) && (tx.getStatus() == Status.STATUS_ACTIVE)) { - dbImpl = new DatabaseImpl(_databaseName, _lockTimeout, - _callbackInterceptor, - _instanceFactory, tx, - _classLoader, _autoStore); + // If we have a active transaction, which happens only in J2EE mode, we + // need to register the database for synchronization. + if (tx != null) { + try { + tx.registerSynchronization(dbImpl); + // If we have a database pool we put the new database into this pool. if (_txDbPool != null) { _txDbPool.put(tx, dbImpl); } - - tx.registerSynchronization(dbImpl); - return dbImpl; + } catch (Exception ex) { // RollbackException, SystemException + // Failed to register database at transaction manager for + // synchronization. + String msg = Messages.message("jdo.manager.failRegisterTransaction"); + LOG.error(msg, ex); + throw new PersistenceException(msg, ex); } - } catch (Exception ex) { - // NamingException, SystemException, RollbackException - LOG.error("Failed to create LocalTransactionManager", ex); } } - return new DatabaseImpl(_databaseName, _lockTimeout, - _callbackInterceptor, _instanceFactory, null, - _classLoader, _autoStore); + // Now we have managed to create a valid database to be returned. + return dbImpl; } /** @@ -963,8 +860,8 @@ */ public void close () { try { - ConnectionFactory connectionFactory = getConnectionFactory(); - LockEngine engine = ((AbstractConnectionFactory) connectionFactory).getEngine(); + ConnectionFactory factory = getConnectionFactory(); + LockEngine engine = ((AbstractConnectionFactory) factory).getEngine(); engine.closeCaches(); } catch (MappingException e) { LOG.fatal ("Problem closing down caches", e); Index: main/org/exolab/castor/jdo/engine/JDOConfLoader.java =================================================================== RCS file: main/org/exolab/castor/jdo/engine/JDOConfLoader.java diff -N main/org/exolab/castor/jdo/engine/JDOConfLoader.java --- main/org/exolab/castor/jdo/engine/JDOConfLoader.java 30 May 2005 19:19:55 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,160 +0,0 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: JDOConfLoader.java,v 1.7 2005/05/30 19:19:55 rjoachim Exp $ - */ - -package org.exolab.castor.jdo.engine; - -import org.exolab.castor.jdo.conf.Database; -import org.exolab.castor.jdo.conf.JdoConf; -import org.exolab.castor.jdo.conf.Mapping; -import org.exolab.castor.jdo.conf.TransactionDemarcation; -import org.exolab.castor.mapping.MappingException; -import org.exolab.castor.util.DTDResolver; -import org.exolab.castor.xml.MarshalException; -import org.exolab.castor.xml.Unmarshaller; -import org.exolab.castor.xml.ValidationException; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Helper class to load the Castor JDO configuration from its configuration file. - * @author Werner Guttmann - */ -public class JDOConfLoader { - private static final String NOTE_096 = - "NOTE: JDO configuration syntax has changed with castor 0.9.6, " - + "please see http://castor.codehaus.org/release-notes.html for details"; - - private static Log _log = LogFactory.getFactory().getInstance( JDOConfLoader.class ); - - private static JdoConf _jdoConf = null; - - /** - * Loads the JDO configuration from the specified InputSource. - * @param source An InputSource pointing to the JDO configuration to be loaded. - * @param resolver An EntityResolver instance. - * @throws MappingException If the JDO configuration cannot be loaded/unmarshalled. - */ - public static synchronized void loadConfiguration( - final InputSource source, final EntityResolver resolver) - throws MappingException { - Unmarshaller unmarshaller; - - unmarshaller = new Unmarshaller(JdoConf.class); - try { - - if (resolver == null) - unmarshaller.setEntityResolver(new DTDResolver()); - else - unmarshaller.setEntityResolver(new DTDResolver (resolver)); - - _jdoConf = (JdoConf) unmarshaller.unmarshal (source); - } - catch (MarshalException e) { - _log.info(NOTE_096); - throw new MappingException(e); - } - catch (ValidationException e) { - throw new MappingException(e); - } - - _log.debug("Loaded jdo conf successfully"); - } - - /** - * Loads the JDO configuration from the specified InputSource. - * @param jdoConf An JDoConf instance representing a JDO configuration to be loaded. - */ - public static synchronized void loadConfiguration(final JdoConf jdoConf) { - _jdoConf = jdoConf; - _log.debug( "Loaded jdo conf successfully" ); - } - - public static Database[] getDatabases(final JdoConf jdoConf) { - loadConfiguration (jdoConf); - return _jdoConf.getDatabase(); - } - - public static Database[] getDatabases( - final InputSource source, final EntityResolver resolver) - throws MappingException { - loadConfiguration (source, resolver); - return _jdoConf.getDatabase(); - } - - public static Database getDatabase(final String databaseName, - final InputSource source, final EntityResolver resolver) - throws MappingException { - Database database = null; - loadConfiguration (source, resolver); - Database[] databases = getDatabases (source, resolver); - for (int i = 0; i < databases.length ;i++) { - if (databases[i].getName().equals (databaseName)) { - database = databases[i]; - } - } - return database; - } - - public static TransactionDemarcation getTransactionDemarcation( - final InputSource source, final EntityResolver resolver) - throws MappingException { - loadConfiguration (source, resolver); - return _jdoConf.getTransactionDemarcation(); - } - - public static Mapping[] getMapping(final String databaseName, - final InputSource source, final EntityResolver resolver) - throws MappingException { - loadConfiguration (source, resolver); - return getDatabase(databaseName, source, resolver).getMapping(); - } - - /** - * Deletes JDO configuration. - */ - public static synchronized void deleteConfiguration() { } -} Index: main/org/exolab/castor/jdo/transactionmanager/TransactionManagerAcquireException.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/TransactionManagerAcquireException.java,v retrieving revision 1.4 diff -u -r1.4 TransactionManagerAcquireException.java --- main/org/exolab/castor/jdo/transactionmanager/TransactionManagerAcquireException.java 14 Dec 2004 15:41:01 -0000 1.4 +++ main/org/exolab/castor/jdo/transactionmanager/TransactionManagerAcquireException.java 15 Aug 2005 19:47:20 -0000 @@ -1,49 +1,18 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 2001 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: TransactionManagerAcquireException.java,v 1.4 2004/12/14 15:41:01 wguttmann Exp $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager; import org.exolab.castor.core.exceptions.CastorException; @@ -54,20 +23,31 @@ * * @author Bruce Snyder * @author Werner Guttmann - * @version $Id: TransactionManagerAcquireException.java,v 1.4 2004/12/14 15:41:01 wguttmann Exp $ + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ */ -public class TransactionManagerAcquireException - extends CastorException -{ +public final class TransactionManagerAcquireException extends CastorException { + //-------------------------------------------------------------------------- - public TransactionManagerAcquireException( String message, Throwable except ) - { - super( message, except ); + /** + * Creates a new TransactionManagerAcquireException with the given message. + * + * @param message the message for this Exception + */ + public TransactionManagerAcquireException(final String message) { + super (message); } - public TransactionManagerAcquireException( String message ) - { - super( message ); + /** + * Creates a new TransactionManagerAcquireException with the given message and cause. + * + * @param message The message for this exception. + * @param cause A Throwable instance. + */ + public TransactionManagerAcquireException(final String message, + final Throwable cause) { + super(message, cause); } - + + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactory.java,v retrieving revision 1.4 diff -u -r1.4 TransactionManagerFactory.java --- main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactory.java 5 Mar 2005 13:41:51 -0000 1.4 +++ main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactory.java 15 Aug 2005 19:47:20 -0000 @@ -1,93 +1,56 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: TransactionManagerFactory.java,v 1.1.1.1 2003/03/03 07:08:25 kvisco Exp - * $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager; - -import java.util.Properties; - import javax.transaction.TransactionManager; +import org.exolab.castor.jdo.conf.JdoConf; + /** * A factory for properly acquiring javax.transaction.TransactionManager - * from J2EE containers. To provide an implementation for a specific J2EE - * container, implement this interface. + * from J2EE containers. To provide an implementation for a specific J2EE container, + * implement this interface. * - * @author Bruce Snyder, Werner Guttmann - * @version $Id: TransactionManagerFactory.java,v 1.1.1.1 2003/03/03 07:08:25 - * kvisco Exp $ + * @author Bruce Snyder + * @author Werner Guttmann + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ */ -public interface TransactionManagerFactory -{ - - /** - * Acquires the appropriate javax.transaction.TransactionManager. - */ - TransactionManager getTransactionManager() - throws TransactionManagerAcquireException; +public interface TransactionManagerFactory { + //-------------------------------------------------------------------------- /** * Returns the short alias for this factory instance. + * * @return The short alias name. */ String getName(); - + /** - * Returns the full set of parameters associated with this factory instance. - * @return The full set of parameters. Null if no parameters are available. - */ - Properties getParams(); - - /** - * Setsthe full set of parameters on this factory instance. - * @param params The full set of parameters. - */ - void setParams(Properties params); - + * Acquires the appropriate javax.transaction.TransactionManager with the + * parameters from the given jdo configuration. + * + * @param jdoConf The jdo configuration holding the parameters to set on the + * transaction manager. + * @return The transaction manager. + * @throws TransactionManagerAcquireException If any failure occures when loading + * the transaction manager. + */ + TransactionManager getTransactionManager(final JdoConf jdoConf) + throws TransactionManagerAcquireException; + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactoryRegistry.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactoryRegistry.java,v retrieving revision 1.4 diff -u -r1.4 TransactionManagerFactoryRegistry.java --- main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactoryRegistry.java 1 Oct 2004 13:25:02 -0000 1.4 +++ main/org/exolab/castor/jdo/transactionmanager/TransactionManagerFactoryRegistry.java 15 Aug 2005 19:47:20 -0000 @@ -1,71 +1,28 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: TransactionManagerFactoryRegistry.java,v 1.4 2004/10/01 13:25:02 snyder Exp $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager; - -import java.util.Collection; -import java.util.Collections; import java.util.Enumeration; import java.util.Hashtable; -import java.util.Properties; import java.util.StringTokenizer; -import org.exolab.castor.jdo.conf.Param; -import org.exolab.castor.jdo.conf.TransactionDemarcation; -import org.exolab.castor.jdo.conf.TransactionManager; -import org.exolab.castor.jdo.engine.JDOConfLoader; -import org.exolab.castor.jdo.transactionmanager.spi.LocalTransactionManagerFactory; -import org.exolab.castor.mapping.MappingException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.exolab.castor.util.LocalConfiguration; -import org.exolab.castor.util.Logger; import org.exolab.castor.util.Messages; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - /** * Registry for {@link TransactionManagerFactory} implementations @@ -74,160 +31,103 @@ * * @author Bruce Snyder * @author Werner Guttmann - * @version $Id: TransactionManagerFactoryRegistry.java,v 1.4 2004/10/01 13:25:02 snyder Exp $ + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ */ public final class TransactionManagerFactoryRegistry { + //-------------------------------------------------------------------------- - - /** - * Property listing all the available {@link TransactionManagerFactory} - * implementations (org.exolab.castor.jdo.transactionManagerFactories). - */ - private static final String TransactionManagerFactoriesProperty = + /** The Jakarta + * Commons Logging instance used for all logging. */ + private static final Log LOG = LogFactory.getLog( + TransactionManagerFactoryRegistry.class); + + /** Property listing all the available {@link TransactionManagerFactory} + * implementations (org.exolab.castor.jdo.transactionManagerFactories). */ + private static final String PROPERTY_TRANSACTION_MANAGER_FACTORY = "org.exolab.castor.jdo.spi.transactionManagerFactories"; + /** Association between name of {@link TransactionManager} implementation and + * TransactionManagerFactory instance. */ + private static Hashtable _factories = null; - /** - * Association between {@link TransactionManager} implementation name and - * TransactionManagerFactory. - */ - private static Hashtable _factories; - - - /** - * Returns a {@link TransactionManagerFactory} with the specified name. - * The factory class names are loaded from the Castor properties - * file. Returns null if the named factory is not supported. - * - * @param name The TransactionManagerFactory name - * @return The {@link TransactionManagerFactory}, null - * if no TransactionManagerFactory with this name exists - */ - public static TransactionManagerFactory getTransactionManagerFactory( String name ) - { - load(); - return ( TransactionManagerFactory ) _factories.get( name ); - } - + //-------------------------------------------------------------------------- /** * Returns the names of all the configured {@link TransactionManagerFactory} - * implementations. The names can be used to obtain a {@link TransactionManagerFactory} - * from {@link #getTransactionManagerFactory}. + * implementations. A {@link TransactionManagerFactory} instance can be obtained + * by one of the {@link #getTransactionManagerFactory} methods. * * @return Names of {@link TransactionManagerFactory} implementations */ - public static String[] getTransactionManagerFactoryNames() - { - String[] names; - Enumeration enumeration; - + public static String[] getTransactionManagerFactoryNames() { load(); - names = new String[ _factories.size() ]; - enumeration = _factories.keys(); - for ( int i = 0 ; i < names.length ; ++i ) { - names[ i ] = (String) enumeration.nextElement(); + + String[] names = new String[_factories.size()]; + Enumeration enumeration = _factories.keys(); + for (int i = 0; i < names.length; ++i) { + names[i] = (String) enumeration.nextElement(); } return names; } - /** - * Returns the names of all the configured {@link TransactionManagerFactory} - * implementations. The names can be used to obtain a {@link TransactionManagerFactory} - * from {@link #getTransactionManagerFactory}. - * - * @return Names of {@link TransactionManagerFactory} implementations - */ - public static Collection getTransactionManagerFactories() { - load(); - return Collections.unmodifiableCollection(_factories.keySet()); - } - - - /** - * Loads configuration related to transaction demarcation and transaction manager factories from JDO config file. - * @param source InputSource pointing to the JDO config file. - * @param resolver Custom EntityResolver instance. - * @throws TransactionManagerAcquireException If there is a problem obtaining tthe configuration. - */ - public static void load (InputSource source, EntityResolver resolver) - throws TransactionManagerAcquireException - { - load(); - - try { - // Load the JDO configuration file from the specified input source. - TransactionDemarcation transactionDemarcation = JDOConfLoader.getTransactionDemarcation (source, resolver); - - if (transactionDemarcation == null) - throw new TransactionManagerAcquireException ("Problem obtaining transaction manager demarcation configuration"); - - String demarcationMode = transactionDemarcation.getMode(); - TransactionManager transactionManager = transactionDemarcation.getTransactionManager(); - - if (transactionManager == null) { - - if (!demarcationMode.equals(LocalTransactionManagerFactory.NAME)) - throw new TransactionManagerAcquireException ("Problem obtaining required transaction manager configuration."); - - } else { - - String mode = transactionManager.getName(); - if (mode == null) - throw new TransactionManagerAcquireException ("Attribute MODE for required"); - - TransactionManagerFactory factory = getTransactionManagerFactory(mode); - if (factory == null) - throw new TransactionManagerAcquireException ("Invalid value for MODE. Transaction manager factory with MODE = " + - mode + "does not exist"); - - Properties properties = new Properties(); - - Enumeration parameters = transactionManager.enumerateParam(); - while (parameters.hasMoreElements()) { - Param param = (Param) parameters.nextElement(); - properties.put(param.getName(), param.getValue()); - } - - factory.setParams(properties); - - } - - - } - catch (MappingException e) { - throw new TransactionManagerAcquireException ("Problem obtaining JDO configuration", e); - } - - } + /** + * Returns a {@link TransactionManagerFactory} with the specified name. The factory + * class names are loaded from the Castor properties file. Returns null if the named + * factory is not supported. + * + * @param name The name of the TransactionManagerFactory. + * @return The {@link TransactionManagerFactory} or null if none exists with this + * name. + */ + public static TransactionManagerFactory getTransactionManagerFactory( + final String name) { + + // Try to omit entering the synchronized load() method. + if (_factories == null) { load(); } + return (TransactionManagerFactory) _factories.get(name); + } /** - * Load the {@link TransactionManagerFactory} implementations from the - * properties file, if not loaded before. + * Load the {@link TransactionManagerFactory} implementations from the properties + * file, if not loaded before. */ - private static synchronized void load() - { - if ( _factories == null ) { - String prop; - StringTokenizer tokenizer; - TransactionManagerFactory factory; - Class cls; + private static void load() { + if (_factories == null) { + // Create a new map for the factories but don't assign it to the static + // property as we try to omit synchronization by checking if static map + // is initialized. + Hashtable factories = new Hashtable(); - _factories = new Hashtable(); - prop = LocalConfiguration.getInstance().getProperty( TransactionManagerFactoriesProperty, "" ); - tokenizer = new StringTokenizer( prop, ", " ); - while ( tokenizer.hasMoreTokens() ) { - prop = tokenizer.nextToken(); + LocalConfiguration cfg = LocalConfiguration.getInstance(); + String prop = cfg.getProperty(PROPERTY_TRANSACTION_MANAGER_FACTORY, ""); + StringTokenizer tokenizer = new StringTokenizer(prop, ", "); + ClassLoader loader = TransactionManagerFactoryRegistry.class.getClassLoader(); + while (tokenizer.hasMoreTokens()) { + String classname = tokenizer.nextToken(); try { - cls = TransactionManagerFactoryRegistry.class.getClassLoader().loadClass( prop ); - factory = ( TransactionManagerFactory ) cls.newInstance(); - _factories.put( factory.getName(), factory ); - } catch ( Exception except ) { - Logger.getSystemLogger().println( Messages.format( - "transactionManager.missingTransactionManagerFactory", prop ) ); + Class cls = loader.loadClass(classname); + Object obj = cls.newInstance(); + TransactionManagerFactory factory = (TransactionManagerFactory) obj; + factories.put(factory.getName(), factory); + } catch (Exception except) { + LOG.error(Messages.format( + "jdo.transaction.failToCreateFactory", classname)); } } + + // As the map is initialized now we are on the save side to assign it to + // the static property. + _factories = factories; } } + + //-------------------------------------------------------------------------- + + /** + * Hide default constructor. + */ + private TransactionManagerFactoryRegistry() { } + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/jdo/transactionmanager/spi/BaseTransactionManagerFactory.java =================================================================== RCS file: main/org/exolab/castor/jdo/transactionmanager/spi/BaseTransactionManagerFactory.java diff -N main/org/exolab/castor/jdo/transactionmanager/spi/BaseTransactionManagerFactory.java --- main/org/exolab/castor/jdo/transactionmanager/spi/BaseTransactionManagerFactory.java 18 Aug 2004 11:45:19 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,99 +0,0 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: BaseTransactionManagerFactory.java,v 1.3 2004/08/18 11:45:19 snyder Exp $ - */ - - -package org.exolab.castor.jdo.transactionmanager.spi; - - -import java.util.Properties; - -import javax.transaction.TransactionManager; - -import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; -import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory; - -/** - * Transaction manager factory instance to be used with J2EE containers - * where the transaction manager is bound to the JNDI ENC of the container. - * - * Implements {link org.exolab.castor.jdo.transactionmanager. - * TransactionManagerFactory}. - * - * @author Bruce Snyder, Werner Guttmann - */ -public abstract class BaseTransactionManagerFactory - implements TransactionManagerFactory -{ - - protected Properties params = null; - - /** - * The javax.transaction.TransactionManager that Castor will use. - */ - protected TransactionManager _transactionManager; - - /** - * Acquires the appropriate TransactionManager. - */ - abstract public TransactionManager getTransactionManager() - throws TransactionManagerAcquireException; - - abstract public String getName(); - - /* (non-Javadoc) - * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory#getParams() - */ - public Properties getParams() { - return params; - } - - /* (non-Javadoc) - * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory#setParams(java.util.Properties) - */ - public void setParams(Properties params) { - this.params = params; - } -} Index: main/org/exolab/castor/jdo/transactionmanager/spi/JNDIENCTransactionManagerFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/spi/JNDIENCTransactionManagerFactory.java,v retrieving revision 1.5 diff -u -r1.5 JNDIENCTransactionManagerFactory.java --- main/org/exolab/castor/jdo/transactionmanager/spi/JNDIENCTransactionManagerFactory.java 18 Aug 2004 11:45:19 -0000 1.5 +++ main/org/exolab/castor/jdo/transactionmanager/spi/JNDIENCTransactionManagerFactory.java 15 Aug 2005 19:47:20 -0000 @@ -1,59 +1,33 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: JNDIENCTransactionManagerFactory.java,v 1.5 2004/08/18 11:45:19 snyder Exp $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager.spi; +import java.util.Enumeration; +import java.util.Properties; -import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NameNotFoundException; import javax.naming.NoInitialContextException; import javax.transaction.TransactionManager; +import org.exolab.castor.jdo.conf.JdoConf; +import org.exolab.castor.jdo.conf.Param; +import org.exolab.castor.jdo.conf.TransactionDemarcation; import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; +import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory; import org.exolab.castor.util.Messages; /** @@ -63,70 +37,65 @@ * Implements {link org.exolab.castor.jdo.transactionmanager. * TransactionManagerFactory}. * - * @author Bruce Snyder, Werner Guttmann + * @author Bruce Snyder + * @author Werner Guttmann + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ */ -public class JNDIENCTransactionManagerFactory - extends BaseTransactionManagerFactory -{ - - /** - * The javax.transaction.TransactionManager that Castor will use. - */ - private TransactionManager _transactionManager; +public final class JNDIENCTransactionManagerFactory implements TransactionManagerFactory { + //-------------------------------------------------------------------------- + /** Default JNDI binding for javax.transaction.TransactionManager + * instance. */ + private static final String TRANSACTION_MANAGER_NAME = "java:comp/TransactionManager"; - /** - * The name of the factory - */ - private final String _name = "jndi"; - - /** - * Default JNDI binding for javax.transaction.TransactionManager - * instance. - */ - private final String TRANSACTION_MANAGER_NAME = "java:comp/TransactionManager"; + /** The name of the factory. */ + private static final String NAME = "jndi"; + //-------------------------------------------------------------------------- /** - * Acquires the appropriate TransactionManager. + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory#getName() */ - public TransactionManager getTransactionManager() - throws TransactionManagerAcquireException - { - Context context = null; - Object objectFound = null; + public String getName() { return NAME; } - try - { - context = new InitialContext(); - - String jndiENC = params.getProperty("jndiEnc", TRANSACTION_MANAGER_NAME ); - objectFound = context.lookup(jndiENC); - _transactionManager = (TransactionManager) objectFound; - } - catch (ClassCastException e) { - throw new TransactionManagerAcquireException (Messages.format ( - "jdo.transaction.unableToCastToTransactionManager", objectFound.getClass().getName()), e); - } - catch (NoInitialContextException e) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", e.getMessage()), e); - } - catch (NameNotFoundException e) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", e.getMessage()), e); + /** + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory + * #getTransactionManager(org.exolab.castor.jdo.conf.JdoConf) + */ + public TransactionManager getTransactionManager(final JdoConf jdoConf) + throws TransactionManagerAcquireException { + Properties properties = new Properties(); + TransactionDemarcation demarcation = jdoConf.getTransactionDemarcation(); + Enumeration parameters = demarcation.getTransactionManager().enumerateParam(); + while (parameters.hasMoreElements()) { + Param param = (Param) parameters.nextElement(); + properties.put(param.getName(), param.getValue()); } - catch (Exception e) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", e.getMessage()), e); + + TransactionManager transactionManager; + Object objectFound = null; + String jndiENC = properties.getProperty("jndiEnc", TRANSACTION_MANAGER_NAME); + try { + objectFound = new InitialContext().lookup(jndiENC); + transactionManager = (TransactionManager) objectFound; + } catch (ClassCastException ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToCastToManager", + objectFound.getClass().getName()), ex); + } catch (NoInitialContextException ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToGetManager", jndiENC), ex); + } catch (NameNotFoundException ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToGetManager", jndiENC), ex); + } catch (Exception ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToGetManager", jndiENC), ex); } - return _transactionManager; + return transactionManager; } - public String getName() - { - return _name; - } + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/jdo/transactionmanager/spi/LocalTransactionManagerFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/spi/LocalTransactionManagerFactory.java,v retrieving revision 1.3 diff -u -r1.3 LocalTransactionManagerFactory.java --- main/org/exolab/castor/jdo/transactionmanager/spi/LocalTransactionManagerFactory.java 18 Aug 2004 11:45:19 -0000 1.3 +++ main/org/exolab/castor/jdo/transactionmanager/spi/LocalTransactionManagerFactory.java 15 Aug 2005 19:47:21 -0000 @@ -1,55 +1,25 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: LocalTransactionManagerFactory.java,v 1.3 2004/08/18 11:45:19 snyder Exp $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager.spi; - import javax.transaction.TransactionManager; +import org.exolab.castor.jdo.conf.JdoConf; import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; +import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory; /** * Default transaction manager when Castor is used in standalone mode, @@ -57,28 +27,30 @@ * * @author Bruce Snyder * @author Werner Guttmann + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ */ -public class LocalTransactionManagerFactory - extends BaseTransactionManagerFactory -{ +public final class LocalTransactionManagerFactory implements TransactionManagerFactory { + //-------------------------------------------------------------------------- + + /** The name of the factory. */ + public static final String NAME = "local"; + //-------------------------------------------------------------------------- + /** - * The name of the factory + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory#getName() */ - public static final String NAME = "local"; - + public String getName() { return NAME; } + /** - * Acquires the appropriate TransactionManager. + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory + * #getTransactionManager(org.exolab.castor.jdo.conf.JdoConf) */ - public TransactionManager getTransactionManager() - throws TransactionManagerAcquireException - { + public TransactionManager getTransactionManager(final JdoConf jdoConf) + throws TransactionManagerAcquireException { return null; } - - public String getName() - { - return NAME; - } + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere51TransactionManagerFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere51TransactionManagerFactory.java,v retrieving revision 1.3 diff -u -r1.3 WebSphere51TransactionManagerFactory.java --- main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere51TransactionManagerFactory.java 2 May 2005 20:58:58 -0000 1.3 +++ main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere51TransactionManagerFactory.java 15 Aug 2005 19:47:21 -0000 @@ -1,127 +1,62 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: WebSphere51TransactionManagerFactory.java,v 1.3 2005/05/02 20:58:58 rjoachim Exp $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager.spi; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import javax.transaction.TransactionManager; - -import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; -import org.exolab.castor.util.Messages; - /** * An IBM Websphere 5.1 specific factory for acquiring transactions from * this J2EE container. * * @author Bruce Snyder * @author Werner Guttmann + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ */ -public class WebSphere51TransactionManagerFactory - extends BaseTransactionManagerFactory -{ +public final class WebSphere51TransactionManagerFactory +extends AbstractTransactionManagerFactory { + //-------------------------------------------------------------------------- + + /** Name of the IBM Websphere specific transaction manager factory class. */ + private static final String FACTORY_CLASS_NAME = + "com.ibm.ws.Transaction.TransactionManagerFactory"; + + /** Name of the method that is used upon the factory to have a TransactionManager + * instance created. */ + private static final String FACTORY_METHOD_NAME = "getTransactionManager"; - /** - * Name of the IBM Websphere specific transaction manager factory class. - */ - private static final String FACTORY_CLASS_NAME = "com.ibm.ws.Transaction.TransactionManagerFactory"; - - /** - * Name of the method that is used upon the factory to have a TransactionManager instance created. - */ - private static final String FACTORY_METHOD_NAME = "getTransactionManager"; + /** The name of the factory. */ + private static final String NAME = "websphere51"; + + //-------------------------------------------------------------------------- + /** - * The javax.transaction.TransactionManager that Castor will use. + * @see org.exolab.castor.jdo.transactionmanager.spi.AbstractTransactionManagerFactory + * #getFactoryClassName() */ - private TransactionManager _transactionManager; - + public String getFactoryClassName() { return FACTORY_CLASS_NAME; } + /** - * The name of the factory + * @see org.exolab.castor.jdo.transactionmanager.spi.AbstractTransactionManagerFactory + * #getFactoryMethodName() */ - private final String _name = "websphere51"; - + public String getFactoryMethodName() { return FACTORY_METHOD_NAME; } + /** - * Acquires the appropriate TransactionManager. + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory#getName() */ - public TransactionManager getTransactionManager() - throws TransactionManagerAcquireException - { - Class webSphereTxMgrFactory = null; - Method method = null; - - try { - webSphereTxMgrFactory = Class.forName (FACTORY_CLASS_NAME); - method = webSphereTxMgrFactory.getMethod(FACTORY_METHOD_NAME, (Class[]) null ); - _transactionManager = (TransactionManager) method.invoke(webSphereTxMgrFactory, (Object[]) null ); - } - catch( ClassNotFoundException cnfe ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", cnfe.getMessage() ) ); - } - catch( IllegalAccessException iae ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", iae.getMessage() ) ); - } - catch( InvocationTargetException ite ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", ite.getMessage() ) ); - } - catch( NoSuchMethodException nsme ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", nsme.getMessage() ) ); - } - - return _transactionManager; - } - - - public String getName() - { - return _name; - } + public String getName() { return NAME; } + + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere5TransactionManagerFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere5TransactionManagerFactory.java,v retrieving revision 1.6 diff -u -r1.6 WebSphere5TransactionManagerFactory.java --- main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere5TransactionManagerFactory.java 2 May 2005 20:58:58 -0000 1.6 +++ main/org/exolab/castor/jdo/transactionmanager/spi/WebSphere5TransactionManagerFactory.java 15 Aug 2005 19:47:21 -0000 @@ -1,121 +1,62 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: WebSphere5TransactionManagerFactory.java,v 1.6 2005/05/02 20:58:58 rjoachim Exp $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager.spi; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import javax.transaction.TransactionManager; - -import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; -import org.exolab.castor.util.Messages; - /** * An IBM Websphere 5 specific factory for acquiring transactions from * this J2EE container. * * @author Bruce Snyder * @author Werner Guttmann + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ */ -public class WebSphere5TransactionManagerFactory - extends BaseTransactionManagerFactory -{ +public final class WebSphere5TransactionManagerFactory +extends AbstractTransactionManagerFactory { + //-------------------------------------------------------------------------- + + /** Name of the IBM Websphere specific transaction manager factory class. */ + private static final String FACTORY_CLASS_NAME = + "com.ibm.ejs.jts.jta.TransactionManagerFactory"; - /** - * The javax.transaction.TransactionManager that Castor will use. - */ - private TransactionManager _transactionManager; + /** Name of the method that is used upon the factory to have a TransactionManager + * instance created. */ + private static final String FACTORY_METHOD_NAME = "getTransactionManager"; + + /** The name of the factory. */ + private static final String NAME = "websphere5"; + //-------------------------------------------------------------------------- /** - * The name of the factory + * @see org.exolab.castor.jdo.transactionmanager.spi.AbstractTransactionManagerFactory + * #getFactoryClassName() */ - private final String _name = "websphere5"; - - + public String getFactoryClassName() { return FACTORY_CLASS_NAME; } + /** - * Acquires the appropriate TransactionManager. + * @see org.exolab.castor.jdo.transactionmanager.spi.AbstractTransactionManagerFactory + * #getFactoryMethodName() */ - public TransactionManager getTransactionManager() - throws TransactionManagerAcquireException - { - Class webSphereTxMgr = null; - Method method = null; - - try - { - webSphereTxMgr = Class.forName( "com.ibm.ejs.jts.jta.TransactionManagerFactory" ); - method = webSphereTxMgr.getMethod( "getTransactionManager", (Class[]) null ); - _transactionManager = ( TransactionManager ) method.invoke( webSphereTxMgr, (Object[]) null ); - } - catch( ClassNotFoundException cnfe ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", cnfe.getMessage()), cnfe); - } - catch( IllegalAccessException iae ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", iae.getMessage()), iae ); - } - catch( InvocationTargetException ite ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", ite.getMessage()), ite ); - } - catch( NoSuchMethodException nsme ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", nsme.getMessage()), nsme ); - } - - return _transactionManager; - } - + public String getFactoryMethodName() { return FACTORY_METHOD_NAME; } + + /** + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory#getName() + */ + public String getName() { return NAME; } - public String getName() - { - return _name; - } + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/jdo/transactionmanager/spi/WebSphereTransactionManagerFactory.java =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/jdo/transactionmanager/spi/WebSphereTransactionManagerFactory.java,v retrieving revision 1.7 diff -u -r1.7 WebSphereTransactionManagerFactory.java --- main/org/exolab/castor/jdo/transactionmanager/spi/WebSphereTransactionManagerFactory.java 2 May 2005 20:58:58 -0000 1.7 +++ main/org/exolab/castor/jdo/transactionmanager/spi/WebSphereTransactionManagerFactory.java 15 Aug 2005 19:47:21 -0000 @@ -1,121 +1,62 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * Copyright 2005 Bruce Snyder, Werner Guttmann, Ralf Joachim * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: WebSphereTransactionManagerFactory.java,v 1.7 2005/05/02 20:58:58 rjoachim Exp $ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - - package org.exolab.castor.jdo.transactionmanager.spi; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import javax.transaction.TransactionManager; - -import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; -import org.exolab.castor.util.Messages; - /** - * An IBM Websphere 4 and prior specific factory for acquiring transactions - * from this particular J2EE container. - * - * @author Bruce Snyder - * @author Werner Guttmann - */ -public class WebSphereTransactionManagerFactory - extends BaseTransactionManagerFactory -{ + * An IBM Websphere 4 and prior specific factory for acquiring transactions + * from this particular J2EE container. + * + * @author Bruce Snyder + * @author Werner Guttmann + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ + */ +public final class WebSphereTransactionManagerFactory +extends AbstractTransactionManagerFactory { + //-------------------------------------------------------------------------- + + /** Name of the IBM Websphere specific transaction manager factory class. */ + private static final String FACTORY_CLASS_NAME = + "com.ibm.ejs.jts.jta.JTSXA"; - /** - * The javax.transaction.TransactionManager that Castor will use. - */ - private TransactionManager _transactionManager; + /** Name of the method that is used upon the factory to have a TransactionManager + * instance created. */ + private static final String FACTORY_METHOD_NAME = "getTransactionManager"; + + /** The name of the factory. */ + private static final String NAME = "websphere"; + //-------------------------------------------------------------------------- /** - * The name of the factory + * @see org.exolab.castor.jdo.transactionmanager.spi.AbstractTransactionManagerFactory + * #getFactoryClassName() */ - private final String _name = "websphere"; - - + public String getFactoryClassName() { return FACTORY_CLASS_NAME; } + /** - * Acquires the appropriate TransactionManager. + * @see org.exolab.castor.jdo.transactionmanager.spi.AbstractTransactionManagerFactory + * #getFactoryMethodName() */ - public TransactionManager getTransactionManager() - throws TransactionManagerAcquireException - { - Class webSphereTxMgr = null; - Method method = null; - - try - { - webSphereTxMgr = Class.forName( "com.ibm.ejs.jts.jta.JTSXA" ); - method = webSphereTxMgr.getMethod( "getTransactionManager", (Class[]) null ); - _transactionManager = ( TransactionManager ) method.invoke( webSphereTxMgr, (Object[]) null ); - } - catch( ClassNotFoundException cnfe ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", cnfe.getMessage()), cnfe ); - } - catch( IllegalAccessException iae ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", iae.getMessage()), iae ); - } - catch( InvocationTargetException ite ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", ite.getMessage()), ite ); - } - catch( NoSuchMethodException nsme ) { - throw new TransactionManagerAcquireException( Messages.format( - "jdo.transaction.unableToAcquireTransactionManager", nsme.getMessage()), nsme ); - } - - return _transactionManager; - } - + public String getFactoryMethodName() { return FACTORY_METHOD_NAME; } + + /** + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory#getName() + */ + public String getName() { return NAME; } - public String getName() - { - return _name; - } + //-------------------------------------------------------------------------- } Index: main/org/exolab/castor/util/resources/messages.properties =================================================================== RCS file: /scm/castor/castor/src/main/org/exolab/castor/util/resources/messages.properties,v retrieving revision 1.35 diff -u -r1.35 messages.properties --- main/org/exolab/castor/util/resources/messages.properties 7 Aug 2005 09:55:01 -0000 1.35 +++ main/org/exolab/castor/util/resources/messages.properties 15 Aug 2005 19:47:24 -0000 @@ -480,14 +480,29 @@ Usage: +# +# JDOManager exceptions +# +jdo.manager.failCreateTransaction=\ + Failed to create J2EE transaction manager. +jdo.manager.failGetTransaction=\ + Failed to get an active transaction from J2EE transaction manager. +jdo.manager.failRegisterTransaction=\ + Failed to register at J2EE transaction manager. + + # # transaction manager exception # -jdo.transaction.unableToAcquireTransactionManager=\ - Unable to acquire instance of javax.transaction.TransactionManager.\ - Original exception: {0} -jdo.transaction.missingTransactionManagerFactory=\ - The TransactionManagerFactory implementation {0} specified in the Castor properties \ - file does not exist in this configuration and will not be supported. -jdo.transaction.unableToCastToTransactionManager=\ +jdo.transaction.missingConfiguration=\ + Missing configuration of TransactionManager. +jdo.transaction.missingFactory=\ + The TransactionManagerFactory {0} specified in the configuration does not \ + exist in the Castor properties file and will not be supported. +jdo.transaction.failToCreateFactory=\ + The TransactionManagerFactory {0} specified in the Castor properties file \ + could not be instantiated. +jdo.transaction.failToGetManager=\ + Unable to acquire instance of javax.transaction.TransactionManager: {0}.\ +jdo.transaction.failToCastToManager=\ Problem casting instance of {0} to javax.transaction.TransactionManager. Index: tests/utf/org/exolab/castor/jdo/engine/JDOConfigLoaderTest.java =================================================================== RCS file: tests/utf/org/exolab/castor/jdo/engine/JDOConfigLoaderTest.java diff -N tests/utf/org/exolab/castor/jdo/engine/JDOConfigLoaderTest.java --- tests/utf/org/exolab/castor/jdo/engine/JDOConfigLoaderTest.java 31 Jul 2005 21:37:34 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,207 +0,0 @@ -/** - * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * $Id: JDOConfigLoaderTest.java,v 1.1 2005/07/31 21:37:34 rjoachim Exp $ - */ - -package utf.org.exolab.castor.jdo.engine; - -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.exolab.castor.jdo.conf.Database; -import org.exolab.castor.jdo.conf.TransactionDemarcation; -import org.exolab.castor.jdo.engine.JDOConfLoader; -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - -import java.io.FileWriter; -import java.io.PrintWriter; - -/** - * - * @author me - * - */ -public class JDOConfigLoaderTest extends TestCase { - - private InputSource source = null; - private EntityResolver resolver = null; - private ClassLoader classLoader = null; - - private static final String JDO_CONF_FILE = "src/examples/jdo/jdo-conf.xml"; - private static final String DATABASE_NAME = "minimal"; - - private PrintWriter writer = null; - - /** - * Constructor for JDOConfigLoaderTest. - * @param arg0 - */ - public JDOConfigLoaderTest(String arg0) { - super(arg0); - } - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - source = new InputSource (JDO_CONF_FILE); - writer = new PrintWriter (new FileWriter ("output.log")); - } - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - super.tearDown(); - - writer.flush(); - writer.close(); - } - - public void testGetDatabase() - throws Exception - { - - Database database = JDOConfLoader.getDatabase (DATABASE_NAME, source, resolver); - writer.println (database); - } - - public void testGetTransactionDemarcation() - throws Exception - { - TransactionDemarcation transactionDemarcation = JDOConfLoader.getTransactionDemarcation (source, resolver); - writer.println (transactionDemarcation); - } - - public void testGetMapping() - throws Exception - { - /* - Mapping mapping = JDOConfLoader.getMapping (source, resolver); - writer.println(mapping); - */ - } - - public void testLoadConfigurationLocalMinimal() - throws Exception - { - source = new InputSource ("src/examples/jdo/jdo-conf.minimal.xml"); - - JDOConfLoader.deleteConfiguration(); - - TransactionDemarcation demarcation = JDOConfLoader.getTransactionDemarcation (source, resolver); - - assertNotNull (demarcation); - assertNull (demarcation.getTransactionManager()); - - } - - public void testLoadConfigurationGlobalJNDI() - throws Exception - { - source = new InputSource ("src/examples/jdo/jdo-conf.global.jndi.xml"); - - JDOConfLoader.deleteConfiguration(); - - TransactionDemarcation demarcation = JDOConfLoader.getTransactionDemarcation (source, resolver); - - assertNotNull (demarcation); - assertEquals (demarcation.getMode(), "global"); - assertNotNull (demarcation.getTransactionManager()); - assertEquals (demarcation.getTransactionManager().getName(), "jndi"); - - } - - public void testLoadConfigurationGlobalJNDIWithParams() - throws Exception - { - source = new InputSource ("src/examples/jdo/jdo-conf.global.jndi.with-params.xml"); - - JDOConfLoader.deleteConfiguration(); - - TransactionDemarcation demarcation = JDOConfLoader.getTransactionDemarcation (source, resolver); - - assertNotNull (demarcation); - assertEquals (demarcation.getMode(), "global"); - assertNotNull (demarcation.getTransactionManager()); - assertEquals (demarcation.getTransactionManager().getName(), "jndi"); - assertEquals (demarcation.getTransactionManager().getParamCount(), 1); - - } - - public void testLoadConfigurationMissingTransactionDemarcation() - throws Exception - { - source = new InputSource ("src/examples/jdo/jdo-conf.missing-demarcation.xml"); - - JDOConfLoader.deleteConfiguration(); - - TransactionDemarcation demarcation = JDOConfLoader.getTransactionDemarcation (source, resolver); - - assertNull(demarcation); - - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#run() - */ - public static TestSuite suite() { - - TestSuite suite = new TestSuite(); - - suite.addTest (new JDOConfigLoaderTest ("testGetDatabase")); - suite.addTest (new JDOConfigLoaderTest ("testGetTransactionDemarcation")); - suite.addTest (new JDOConfigLoaderTest ("testGetMapping")); - -// suite.addTest (new JDOConfigLoaderTest ("testLoadConfigurationLocalMinimal")); -// suite.addTest (new JDOConfigLoaderTest ("testLoadConfigurationMissingTransactionDemarcation")); - -// suite.addTest (new JDOConfigLoaderTest ("testLoadConfigurationGlobalJNDI")); -// suite.addTest (new JDOConfigLoaderTest ("testLoadConfigurationGlobalJNDIWithParams")); - - return suite; - } - -} Index: tests/utf/org/exolab/castor/jdo/transactionmanager/TestTransactionManagerFactoryRegistry.java =================================================================== RCS file: tests/utf/org/exolab/castor/jdo/transactionmanager/TestTransactionManagerFactoryRegistry.java diff -N tests/utf/org/exolab/castor/jdo/transactionmanager/TestTransactionManagerFactoryRegistry.java --- tests/utf/org/exolab/castor/jdo/transactionmanager/TestTransactionManagerFactoryRegistry.java 31 Jul 2005 21:37:35 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,66 +0,0 @@ -package utf.org.exolab.castor.jdo.transactionmanager; - -import java.io.PrintWriter; -import java.util.Collection; -import java.util.Properties; - -import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory; -import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactoryRegistry; - -import junit.framework.TestCase; - -/* - * JUnit test case for unit testing TransactionManagerFactoryRegistry. - * @author Werner Guttmann - * - */ -public class TestTransactionManagerFactoryRegistry - extends TestCase -{ - - private PrintWriter writer = null; - - /** - * Constructor for TransactionManagerFactoryRegistryTest. - * @param arg0 - */ - public TestTransactionManagerFactoryRegistry(String arg0) { - super(arg0); - } - - public void testGetTransactionManagerFactory() - throws Exception - { - TransactionManagerFactory localFactory = - TransactionManagerFactoryRegistry.getTransactionManagerFactory ("local"); - - assertEquals("equals", "local", localFactory.getName()); - - TransactionManagerFactory jndiFactoryNoParams = - TransactionManagerFactoryRegistry.getTransactionManagerFactory ("jndi"); - - assertEquals("equals", "jndi", jndiFactoryNoParams.getName()); - assertNull("params == null", jndiFactoryNoParams.getParams()); - - TransactionManagerFactory jndiFactory = - TransactionManagerFactoryRegistry.getTransactionManagerFactory ("jndi"); - - assertEquals("factory name == ", "jndi", jndiFactory.getName()); - - Collection factories = TransactionManagerFactoryRegistry.getTransactionManagerFactories(); - - assertNotNull ("At least one transaction manager factory", factories); - assertEquals ("5 transaction manager factories", 5, factories.size()); - } - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - - Properties params = new Properties (); - params.put ("jndiENC", "comp:java/transactionManager"); - } - -} Index: main/org/exolab/castor/jdo/transactionmanager/TransactionManagerRegistry.java =================================================================== RCS file: main/org/exolab/castor/jdo/transactionmanager/TransactionManagerRegistry.java diff -N main/org/exolab/castor/jdo/transactionmanager/TransactionManagerRegistry.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ main/org/exolab/castor/jdo/transactionmanager/TransactionManagerRegistry.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,128 @@ +/* + * Copyright 2005 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.exolab.castor.jdo.transactionmanager; + +import javax.transaction.TransactionManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.castor.util.IdentityMap; +import org.exolab.castor.jdo.conf.JdoConf; +import org.exolab.castor.jdo.conf.TransactionDemarcation; +import org.exolab.castor.jdo.transactionmanager.spi.LocalTransactionManagerFactory; +import org.exolab.castor.mapping.MappingException; +import org.exolab.castor.util.Messages; + +/** + * Registry for {@link TransactionManager} implementations obtained by the configuartion + * they are specified in. + * + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ + */ +public final class TransactionManagerRegistry { + //-------------------------------------------------------------------------- + + /** The Jakarta + * Commons Logging instance used for all logging. */ + private static final Log LOG = LogFactory.getLog(TransactionManagerRegistry.class); + + /** Name of the LocalTransactionManagerFactory. */ + private static final String LOCAL_TX_NAME = LocalTransactionManagerFactory.NAME; + + /** Association between configuration and TransactionManager instance. */ + private static IdentityMap _managers = new IdentityMap(); + + //-------------------------------------------------------------------------- + + /** + * Get TransactionManager for the given configuration. If we previously created a + * TransactionManager for the same configuration instance we need to return the + * same TransactionManager instance. Therefore this method needs to be synchronized + * and we need to use a IdentityMap. + * + * @param jdoConf The configuration we need a TransactionManager for. + * @return The TransactionManager. + * @throws MappingException If any failure occures at creation of TransactionManager. + */ + public static synchronized TransactionManager getTransactionManager( + final JdoConf jdoConf) throws MappingException { + + TransactionManager manager; + if (_managers.containsKey(jdoConf)) { + // If map contains a TransactionManager for the configuration we use it. + // We need to check with contains first as we get null in local mode. + manager = (TransactionManager) _managers.get(jdoConf); + } else { + // If we did not find a TransactionManager in the map we need to get a + // new one. Therefore we first need the mode configured at JdoConf. If + // no mode is configured at JdoConf we are not able to get the new + // TransactinManager so we throw an exception to indicate that user + // should change the configuration. + String mode = null; + TransactionDemarcation demarcation = jdoConf.getTransactionDemarcation(); + if (demarcation.getTransactionManager() != null) { + mode = demarcation.getTransactionManager().getName(); + } else if (LOCAL_TX_NAME.equals(demarcation.getMode())) { + mode = LOCAL_TX_NAME; + } else { + String msg = Messages.message("jdo.transaction.missingConfiguration"); + LOG.error(msg); + throw new MappingException(msg); + } + + // Try to obtain a TransactionManagerFactory instance for configured mode + // from the registry. If the returned TransactionManagerFactory instance + // is null, throw an exception to indicate that we cannot live without a + // valid TransactionManagerFactory instance and that the user should + // change the configuration. + TransactionManagerFactory factory = + TransactionManagerFactoryRegistry.getTransactionManagerFactory(mode); + + if (factory == null) { + String msg = Messages.format("jdo.transaction.missingFactory", mode); + LOG.error(msg); + throw new MappingException(msg); + } + + // As we now have a TransactionManagerFactroy we can try to obtain a new + // TransactionManager with the parameters configured at JdoConf from the + // factory. If any failure occures loading the TransactionManager we will + // catch that exception log that failure and throw the exception wrapped + // into another one again. + try { + manager = factory.getTransactionManager(jdoConf); + } catch (TransactionManagerAcquireException ex) { + String msg = Messages.format("jdo.transaction.failToGetManager", mode); + LOG.error(msg, ex); + throw new MappingException(msg, ex); + } + + // The TransactionManager need to be put into map. + _managers.put(jdoConf, manager); + } + return manager; + } + + //-------------------------------------------------------------------------- + + /** + * Hide default constructor. + */ + private TransactionManagerRegistry() { } + + //-------------------------------------------------------------------------- +} Index: main/org/exolab/castor/jdo/transactionmanager/spi/AbstractTransactionManagerFactory.java =================================================================== RCS file: main/org/exolab/castor/jdo/transactionmanager/spi/AbstractTransactionManagerFactory.java diff -N main/org/exolab/castor/jdo/transactionmanager/spi/AbstractTransactionManagerFactory.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ main/org/exolab/castor/jdo/transactionmanager/spi/AbstractTransactionManagerFactory.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,81 @@ +/* + * Copyright 2005 Ralf Joachim + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.exolab.castor.jdo.transactionmanager.spi; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import javax.transaction.TransactionManager; + +import org.exolab.castor.jdo.conf.JdoConf; +import org.exolab.castor.jdo.transactionmanager.TransactionManagerAcquireException; +import org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory; +import org.exolab.castor.util.Messages; + +/** + * An abstract factory for acquiring transactions from this J2EE container. + * + * @author Ralf Joachim + * @version $Revision: 1.1 $ $Date: 2005/07/31 21:37:33 $ + */ +public abstract class AbstractTransactionManagerFactory +implements TransactionManagerFactory { + //-------------------------------------------------------------------------- + + /** + * Get name of the factory class. + * + * @return Name of the factory class. + */ + public abstract String getFactoryClassName(); + + /** + * Get name of the factory method. + * + * @return Name of the factory method. + */ + public abstract String getFactoryMethodName(); + + /** + * @see org.exolab.castor.jdo.transactionmanager.TransactionManagerFactory + * #getTransactionManager(org.exolab.castor.jdo.conf.JdoConf) + */ + public final TransactionManager getTransactionManager(final JdoConf jdoConf) + throws TransactionManagerAcquireException { + TransactionManager transactionManager; + try { + Class factory = Class.forName(getFactoryClassName()); + Method method = factory.getMethod(getFactoryMethodName(), (Class[]) null); + Object obj = method.invoke(factory, (Object[]) null); + transactionManager = (TransactionManager) obj; + } catch (ClassNotFoundException ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToGetManager", getFactoryClassName()), ex); + } catch (IllegalAccessException ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToGetManager", getFactoryClassName()), ex); + } catch (InvocationTargetException ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToGetManager", getFactoryClassName()), ex); + } catch (NoSuchMethodException ex) { + throw new TransactionManagerAcquireException(Messages.format( + "jdo.transaction.failToGetManager", getFactoryClassName()), ex); + } + return transactionManager; + } + + //-------------------------------------------------------------------------- +}