- Common ways to obtain AtomikosDataSourceBean
private void myMethod () {}
atomikosDataSourceBean.setMaintenanceInterval(getMaintenanceInterval()); atomikosDataSourceBean.setReapTimeout(getReapTimeout()); atomikosDataSourceBean.setTestQuery(getTestQuery()); atomikosDataSourceBean.setXaProperties(getXaProperties()); atomikosDataSourceBean.setMaxLifetime(getMaxLifetime());
public AtomikosDataSourceFactory() { super.setUniqueResourceName("opennms"); super.setXaDataSource(XADataSourceFactory.getInstance()); super.setPoolSize(30); // Automatically rollback the connection on borrow to avoid a problem where // Atomikos will reuse database connections that contain aborted transactions, // mark the connections as "erroneous", and recycle the connections. We want to // avoid database connection recycling to avoid lockups in PostgreSQL that occur // when creating new connections. This occurs on PostgreSQL 8.4 but may be fixed // in later versions. // // These aborted transactions shouldn't happen and are probably caused by errors // in JDBC code. Atomikos may also only exhibit this behavior when running without // a transaction manager (as is the case in the current OpenNMS code with // Hibernate 3.6). // super.setTestQuery("ROLLBACK;SELECT 1;"); /* // Disable pool maintenance (reaping and shrinking) by setting the interval // to the highest value possible. We want the connections to PostgreSQL to // remain open forever without being recycled. super.setMaintenanceInterval(Integer.MAX_VALUE / 1000); */ }
atomikosDataSourceBean.setMaintenanceInterval(getMaintenanceInterval()); atomikosDataSourceBean.setReapTimeout(getReapTimeout()); atomikosDataSourceBean.setTestQuery(getTestQuery()); atomikosDataSourceBean.setXaProperties(getXaProperties()); atomikosDataSourceBean.setMaxLifetime(getMaxLifetime());
@Override public DataSource wrap(String name, XADataSource xaDataSource, PoolOptions poolOptions, String testQuery) { AtomikosDataSourceBean wrapped = new AtomikosDataSourceBean(); wrapped.setXaDataSource(xaDataSource); wrapped.setUniqueResourceName(name); if (poolOptions == null) { poolOptions = new PoolOptions(); } if (poolOptions.getMaxLifeTime() != null && poolOptions.getMaxLifeTime() != 0) { wrapped.setMaxLifetime(poolOptions.getMaxLifeTime()); } else { // test query is only needed when we don't know how long Atomikos can keep connections in the pool wrapped.setTestQuery(testQuery); } if (poolOptions.getMinPoolSize() != null) { wrapped.setMinPoolSize(poolOptions.getMinPoolSize()); } if (poolOptions.getMaxPoolSize() != null) { wrapped.setMaxPoolSize(poolOptions.getMaxPoolSize()); } if (poolOptions.getMaxIdleTime() != null) { wrapped.setMaxIdleTime(poolOptions.getMaxIdleTime()); } if (poolOptions.getReapTimeout() != null) { wrapped.setReapTimeout(poolOptions.getReapTimeout()); } return wrapped; }