将 Bitronix 与 Jtds 驱动程序集成
Integrating Bitronix with Jtds driver
我正在尝试使用 Jtds 驱动程序为 SQL 服务器和 Sybase 连接执行 PoolingDataSource。
protected DataSource dataSource() throws Exception {
// Create pool datasource
final PoolingDataSource poolingDataSource = new PoolingDataSource();
poolingDataSource.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
poolingDataSource.setMaxPoolSize(20);
poolingDataSource.setUniqueName(getDataSourceProperty().getUserName());
poolingDataSource.setAllowLocalTransactions(true);
poolingDataSource.setAutomaticEnlistingEnabled(true);
poolingDataSource.setShareTransactionConnections(false);
final Properties properties = new Properties();
properties.put("driverClassName", getDataSourceProperty().getDriverClassName());
properties.put("url", getDataSourceProperty().getUrl());
properties.put("user", getDataSourceProperty().getUserName());
properties.put("password", DataSourceSecureIdentity.decode(getDataSourceProperty().getPassword()));
poolingDataSource.setDriverProperties(properties);
return poolingDataSource;
}
服务器启动后显示:
Caused by: bitronix.tm.internal.BitronixSystemException: cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=xxx XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=xxx2 XAResource=a JDBC LrcXAResource in state STARTED (started) with XID a Bitronix XID [7465737465000000001757A2D000000005 : 7465737465000000001757A70A00000006]
at bitronix.tm.internal.XAResourceManager.enlist(XAResourceManager.java:107) ~[btm-2.1.4.jar:2.1.4]
at bitronix.tm.BitronixTransaction.enlistResource(BitronixTransaction.java:130) ~[btm-2.1.4.jar:2.1.4]
at bitronix.tm.resource.common.TransactionContextHelper.enlistInCurrentTransaction(TransactionContextHelper.java:69) ~[btm-2.1.4.jar:2.1.4]
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:85) ~[btm-2.1.4.jar:2.1.4]
... 93 common frames omitted
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is bitronix.tm.internal.BitronixRollbackException: transaction was marked as rollback only and has been rolled back
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1024)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
我读到我只能有一个非 XA 数据源,但如果 LrcXADataSource class 正在包装数据源,为什么会发生这种情况?
有什么方法可以通知 Jtds Driver XA 选项吗?
我发现通过 LrcXADataSource 模拟 XA 数据源并通过 PoolingDataSourceBean 插入到 XA 池中,我可以在 Bitronix 上运行多个非 XA 数据源。
protected DataSource dataSource() throws Exception {
// Create XA datasource
final LrcXADataSource lrcXADataSource = new LrcXADataSource();
lrcXADataSource.setDriverClassName(getDataSourceProperty().getDriverClassName());
lrcXADataSource.setUrl(getDataSourceProperty().getUrl());
lrcXADataSource.setUser(getDataSourceProperty().getUserName());
lrcXADataSource.setPassword(DataSourceSecureIdentity.decode(getDataSourceProperty().getPassword()));
// Create a pool of XA datasource
final PoolingDataSourceBean poolingDataSourceBean = new PoolingDataSourceBean();
poolingDataSourceBean.setDataSource(lrcXADataSource);
poolingDataSourceBean.setMaxPoolSize(getDataSourceProperty().getMaxPoolSize());
poolingDataSourceBean.setMinPoolSize(getDataSourceProperty().getMinPoolSize());
poolingDataSourceBean.setTestQuery(getDataSourceProperty().getValidationQuery());
return poolingDataSourceBean;
}
我正在尝试使用 Jtds 驱动程序为 SQL 服务器和 Sybase 连接执行 PoolingDataSource。
protected DataSource dataSource() throws Exception {
// Create pool datasource
final PoolingDataSource poolingDataSource = new PoolingDataSource();
poolingDataSource.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
poolingDataSource.setMaxPoolSize(20);
poolingDataSource.setUniqueName(getDataSourceProperty().getUserName());
poolingDataSource.setAllowLocalTransactions(true);
poolingDataSource.setAutomaticEnlistingEnabled(true);
poolingDataSource.setShareTransactionConnections(false);
final Properties properties = new Properties();
properties.put("driverClassName", getDataSourceProperty().getDriverClassName());
properties.put("url", getDataSourceProperty().getUrl());
properties.put("user", getDataSourceProperty().getUserName());
properties.put("password", DataSourceSecureIdentity.decode(getDataSourceProperty().getPassword()));
poolingDataSource.setDriverProperties(properties);
return poolingDataSource;
}
服务器启动后显示:
Caused by: bitronix.tm.internal.BitronixSystemException: cannot enlist more than one non-XA resource, tried enlisting an XAResourceHolderState with uniqueName=xxx XAResource=a JDBC LrcXAResource in state NO_TX with XID null, already enlisted: an XAResourceHolderState with uniqueName=xxx2 XAResource=a JDBC LrcXAResource in state STARTED (started) with XID a Bitronix XID [7465737465000000001757A2D000000005 : 7465737465000000001757A70A00000006]
at bitronix.tm.internal.XAResourceManager.enlist(XAResourceManager.java:107) ~[btm-2.1.4.jar:2.1.4]
at bitronix.tm.BitronixTransaction.enlistResource(BitronixTransaction.java:130) ~[btm-2.1.4.jar:2.1.4]
at bitronix.tm.resource.common.TransactionContextHelper.enlistInCurrentTransaction(TransactionContextHelper.java:69) ~[btm-2.1.4.jar:2.1.4]
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:85) ~[btm-2.1.4.jar:2.1.4]
... 93 common frames omitted
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is bitronix.tm.internal.BitronixRollbackException: transaction was marked as rollback only and has been rolled back
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1024)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
我读到我只能有一个非 XA 数据源,但如果 LrcXADataSource class 正在包装数据源,为什么会发生这种情况?
有什么方法可以通知 Jtds Driver XA 选项吗?
我发现通过 LrcXADataSource 模拟 XA 数据源并通过 PoolingDataSourceBean 插入到 XA 池中,我可以在 Bitronix 上运行多个非 XA 数据源。
protected DataSource dataSource() throws Exception {
// Create XA datasource
final LrcXADataSource lrcXADataSource = new LrcXADataSource();
lrcXADataSource.setDriverClassName(getDataSourceProperty().getDriverClassName());
lrcXADataSource.setUrl(getDataSourceProperty().getUrl());
lrcXADataSource.setUser(getDataSourceProperty().getUserName());
lrcXADataSource.setPassword(DataSourceSecureIdentity.decode(getDataSourceProperty().getPassword()));
// Create a pool of XA datasource
final PoolingDataSourceBean poolingDataSourceBean = new PoolingDataSourceBean();
poolingDataSourceBean.setDataSource(lrcXADataSource);
poolingDataSourceBean.setMaxPoolSize(getDataSourceProperty().getMaxPoolSize());
poolingDataSourceBean.setMinPoolSize(getDataSourceProperty().getMinPoolSize());
poolingDataSourceBean.setTestQuery(getDataSourceProperty().getValidationQuery());
return poolingDataSourceBean;
}