Atomikos Forum |
|
Hello,
has anybody experience using Atomikos in conjunction with XADisk (transaction management for a file system) ? My goal is to have transactional integrity for the DB and the file system. My scenario: - self written J2SE server based on Netbeans - postgresSQL database - file system managed by XADisk For the DB I could use Atomikos JDBC and the User Transaction (chapter 4.1 of the Atomikos TransactionsEssential Guide) but for XADisk I would need the JTA Transaction Manager (chapter 4.2). Is it possible to mix both approaches (I don't want to lose the advantages of Atomikos JDBC)? If so, how? Thanks a lot in advance timekeeper
Hello,
XAResource is a standard point of integration between Transaction-Manager and resources involved, and I am sure Atomikos would treat all such XAResources independent of where do they come from. So, you should be able to do something like this: _____________________________________________________ Transaction txn = tm.getTransaction(); com.atomikos.jdbc.SimpleDataSourceBean ds = new com.atomikos.jdbc.SimpleDataSourceBean(); XAConnection xAConnection = ds.getXaDataSource().getXAConnection(); XAResource xar1 = xAConnection.getXAResource(); txn.enlistResource(xar1); XAResource xar2 = //xar from XADisk txn.enlistResource(xar2); _____________________________________________________ Please give it a try and see if works for you. I didn't have a chance to test the above, but please let me know if you face any issues. Thanks, Nitin
Hello,
I too have come across this in the documentation. Though I am not an Atomikos expert, it is generally a good practice to use the latest API instead of the deprecated one. In this case, you can simple use AtomikosDataSourceBean and the steps I wrote to retrieve the XAResource would remain the same. Thanks, Nitin
Hello Nitrin,
I have a problem with my startup code: UserTransactionServiceFactory utsFactory = new UserTransactionServiceFactory(); uts = utsFactory.getUserTransactionService(tsProperties); dbDataSource = dbConfig.createDataSource(); LOG.info("registering JDBC-Resource"); JdbcTransactionalResource jdbcResource = new JdbcTransactionalResource( "de.hermannmatthes.workbench.dbDataSource", dbDataSource); uts.registerResource(jdbcResource); xaFileSystem = XAFileSystemProxy.bootNativeXAFileSystem(createXaConfig()); xaFileSystem.waitForBootup(10000L); LOG.info("Booting completed for the XADisk instance."); LOG.info("registering XADisk-Resource"); ManagedConnectionFactory mcf = new XADiskManagedConnectionFactory(); ((XADiskManagedConnectionFactory) mcf).setInstanceId(fsConfig.getFsInstanceName()); JcaTransactionalResource xaResource = new JcaTransactionalResource(fsConfig.getFsInstanceName(), mcf); uts.registerResource(xaResource); LOG.info("Atomikos startup successfully completed!"); The code runs without visible errors but if I afterwards try to use a XASession (which I obtain with xaFileSystem.createSessionForXATransaction()), I get the following error: NoTransactionAssociatedException: The method that was called can only be called with a transaction associated, but there is no such transaction present. In the debugger I see that the XASession (it's a NativeXASession) the components sessionOfXATransaction and sessionOfLocalTransaction are null. It seems that my startup code is wrong because in my mind sessionOfXATransaction should be set. Is the approach of using XADiskManagedConnectionFactory wrong? Can you please help? Any hint is welcome. Hermann
Hurra, it works. And it's relatively simple. For JDBC I use the AtomikosDataSourceBean and for XADisk I do enlist/delist for myself.
If someone wants me to provide the code, just send an email to time-keeper at freenet dot de. Thanks a lot to anybody who supported me. |