Java Code Examples for com.atomikos.jdbc.AtomikosDataSourceBean#setTestQuery()

The following examples show how to use com.atomikos.jdbc.AtomikosDataSourceBean#setTestQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeListener.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * Get or initialize the XA data source.
 * @return a {@link DataSource} instance.
 */
private static DataSource createXADataSource() {
  final AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
  final Properties props = ds.getXaProperties();
  /*
  // PostgreSQL Properties
  // !!! on PostgreSQL, the server configuration property "maxPreparedConnections"
  // must be set to a value > 0
  ds.setXaDataSourceClassName("org.postgresql.xa.PGXADataSource");
  props.setProperty("user", "jppf");
  props.setProperty("password", "jppf");
  props.setProperty("databaseName", "jppf_samples");
  props.setProperty("serverName", "localhost");
  props.setProperty("portNumber", "5432");
  // MySQL Properties
  ds.setXaDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
  props.setProperty("user", "jppf");
  props.setProperty("password", "jppf");
  props.setProperty("serverName", "localhost");
  props.setProperty("port", "3306");
  props.setProperty("databaseName", "jppf_samples");
  props.setProperty("pinGlobalTxToPhysicalConnection", "true");
  */
  // H2 Properties
  ds.setXaDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
  props.setProperty("user", "jppf");
  props.setProperty("password", "jppf");
  props.setProperty("URL", "jdbc:h2:tcp://localhost:9092/./jppf_samples;SCHEMA=PUBLIC");

  // common properties
  ds.setTestQuery("select count(id) from task_result");
  ds.setUniqueResourceName("jppf_samples_ds");
  ds.setPoolSize(10);
  return ds;
}
 
Example 2
Source File: AtomikosDataSourceConfig.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@SneakyThrows
public void putProperties(AtomikosDataSourceBean atomikosDataSourceBean) {

    if (null != xaProperties) {
        xaProperties.entrySet().forEach(entry -> entry.setValue(String.valueOf(entry.getValue())));
    }
    //fix #87
    XADataSource dataSource = (XADataSource) Class.forName(getXaDataSourceClassName()).newInstance();
    FastBeanCopier.copy(xaProperties, dataSource);
    atomikosDataSourceBean.setXaDataSource(dataSource);

    atomikosDataSourceBean.setXaDataSourceClassName(getXaDataSourceClassName());
    atomikosDataSourceBean.setBorrowConnectionTimeout(getBorrowConnectionTimeout());
    if (loginTimeout != 0) {
        try {
            atomikosDataSourceBean.setLoginTimeout(getLoginTimeout());
        } catch (SQLException e) {
            log.warn(e.getMessage(), e);
        }
    }
    atomikosDataSourceBean.setMaxIdleTime(getMaxIdleTime());
    atomikosDataSourceBean.setMaxPoolSize(getMaxPoolSize());
    atomikosDataSourceBean.setMinPoolSize(getMinPoolSize());
    atomikosDataSourceBean.setDefaultIsolationLevel(getDefaultIsolationLevel());
    atomikosDataSourceBean.setMaintenanceInterval(getMaintenanceInterval());
    atomikosDataSourceBean.setReapTimeout(getReapTimeout());
    atomikosDataSourceBean.setTestQuery(getTestQuery());
    atomikosDataSourceBean.setXaProperties(getXaProperties());
    atomikosDataSourceBean.setMaxLifetime(getMaxLifetime());
}