Java源码示例:bitronix.tm.resource.jdbc.PoolingDataSource
示例1
@Override
public DataSource actualDataSource() {
final PoolingDataSource poolingDataSource = (PoolingDataSource) super.actualDataSource();
com.vladmihalcea.flexypool.config.Configuration<PoolingDataSource> configuration = new com.vladmihalcea.flexypool.config.Configuration.Builder<>(
getClass().getSimpleName(), poolingDataSource, BitronixPoolAdapter.FACTORY).build();
FlexyPoolDataSource<PoolingDataSource> flexyPoolDataSource = new FlexyPoolDataSource<PoolingDataSource>(configuration) {
@Override
public void start() {
poolingDataSource.init();
super.start();
}
@Override
public void stop() {
super.stop();
poolingDataSource.close();
}
};
return flexyPoolDataSource;
}
示例2
static PoolingDataSource createBitronixWrappedDataSource() throws AssertionError {
if (Connections.class.getClassLoader() instanceof IsolatedWeavingClassLoader) {
throw new AssertionError("Bitronix loads JdbcProxyFactory implementation using a"
+ " parent-first class loader, which bypasses IsolatedWeavingClassLoader, must"
+ " use JavaagentContainer");
}
PoolingDataSource ds = new PoolingDataSource();
ds.setClassName(JDBCXADataSource.class.getName());
Properties props = new Properties();
props.setProperty("url", "jdbc:hsqldb:mem:test");
ds.setDriverProperties(props);
ds.setMaxPoolSize(1);
ds.setUniqueName("unique-name-" + nextUniqueNum++);
ds.setAllowLocalTransactions(true);
return ds;
}
示例3
@Bean
public Configuration<PoolingDataSource> configuration() {
return new Configuration.Builder<PoolingDataSource>(
uniqueId,
poolingDataSource,
BitronixPoolAdapter.FACTORY
)
.setMetricsFactory(MetricsFactoryResolver.INSTANCE.resolve())
.setConnectionProxyFactory(ConnectionDecoratorFactoryResolver.INSTANCE.resolve())
.setMetricLogReporterMillis(TimeUnit.SECONDS.toMillis(5))
.setJmxEnabled(true)
.setJmxAutoStart(true)
.setConnectionAcquireTimeThresholdMillis(50L)
.setConnectionLeaseTimeThresholdMillis(250L)
.setEventListenerResolver(new EventListenerResolver() {
@Override
public List<EventListener<? extends Event>> resolveListeners() {
return Arrays.<EventListener<? extends Event>>asList(
new ConnectionAcquireTimeoutEventListener(),
new ConnectionAcquireTimeThresholdExceededEventListener(),
new ConnectionLeaseTimeThresholdExceededEventListener()
);
}
})
.build();
}
示例4
private static PoolingDataSource setupJdbcDataSource(String url,
String userName, String password) {
log.debug("setting up JdbcDataSource url [" + url + "] username ["
+ userName + "] password ["
+ StringUtils.repeat("*", password.length()) + "]");
PoolingDataSource jdbcDataSource = new PoolingDataSource();
jdbcDataSource.setClassName("oracle.jdbc.xa.client.OracleXADataSource");
jdbcDataSource.setUniqueName("oracle");
jdbcDataSource.setMaxPoolSize(5);
jdbcDataSource.setAllowLocalTransactions(true);
// jdbcDataSource.setTestQuery("SELECT 1 FROM DUAL");
jdbcDataSource.getDriverProperties().setProperty("user", userName);
jdbcDataSource.getDriverProperties().setProperty("password", password);
jdbcDataSource.getDriverProperties().setProperty("URL", url);
jdbcDataSource.init();
return jdbcDataSource;
}
示例5
@Bean(destroyMethod = "close")
public PoolingDataSource actualDataSource() {
PoolingDataSource poolingDataSource = new PoolingDataSource();
poolingDataSource.setClassName(dataSourceClassName);
poolingDataSource.setUniqueName(getClass().getName());
poolingDataSource.setMinPoolSize(0);
poolingDataSource.setMaxPoolSize(5);
poolingDataSource.setAllowLocalTransactions(true);
poolingDataSource.setDriverProperties(new Properties());
poolingDataSource.getDriverProperties().put("user", jdbcUser);
poolingDataSource.getDriverProperties().put("password", jdbcPassword);
poolingDataSource.getDriverProperties().put("url", jdbcUrl);
return poolingDataSource;
}
示例6
public DataSource extraDataSource() {
PoolingDataSource poolingDataSource = new PoolingDataSource();
poolingDataSource.setClassName(dataSourceClassName);
poolingDataSource.setUniqueName("ExtraDS");
poolingDataSource.setMinPoolSize(0);
poolingDataSource.setMaxPoolSize(5);
poolingDataSource.setAllowLocalTransactions(true);
poolingDataSource.setDriverProperties(new Properties());
poolingDataSource.getDriverProperties().put("user", jdbcUser);
poolingDataSource.getDriverProperties().put("password", jdbcPassword);
poolingDataSource.getDriverProperties().put("databaseName", jdbcDatabase);
poolingDataSource.getDriverProperties().put("serverName", jdbcHost);
poolingDataSource.getDriverProperties().put("portNumber", jdbcPort);
return poolingDataSource;
}
示例7
public DataSource actualDataSource() {
PoolingDataSource poolingDataSource = new PoolingDataSource();
poolingDataSource.setClassName(dataSourceClassName);
poolingDataSource.setUniqueName(getClass().getName());
poolingDataSource.setMinPoolSize(0);
poolingDataSource.setMaxPoolSize(5);
poolingDataSource.setAllowLocalTransactions(true);
poolingDataSource.setDriverProperties(new Properties());
poolingDataSource.getDriverProperties().put("user", jdbcUser);
poolingDataSource.getDriverProperties().put("password", jdbcPassword);
poolingDataSource.getDriverProperties().put("url", jdbcUrl);
return poolingDataSource;
}
示例8
public DataSource actualDataSource() {
PoolingDataSource poolingDataSource = new PoolingDataSource();
poolingDataSource.setClassName(dataSourceClassName);
poolingDataSource.setUniqueName(getClass().getName());
poolingDataSource.setMinPoolSize(0);
poolingDataSource.setMaxPoolSize(5);
poolingDataSource.setAllowLocalTransactions(true);
poolingDataSource.setDriverProperties(new Properties());
poolingDataSource.getDriverProperties().put("user", jdbcUser);
poolingDataSource.getDriverProperties().put("password", jdbcPassword);
poolingDataSource.getDriverProperties().put("databaseName", jdbcDatabase);
poolingDataSource.getDriverProperties().put("serverName", jdbcHost);
poolingDataSource.getDriverProperties().put("portNumber", jdbcPort);
return poolingDataSource;
}
示例9
@Bean(initMethod = "start", destroyMethod = "stop")
public FlexyPoolDataSource dataSource() {
Configuration<PoolingDataSource> configuration = configuration();
return new FlexyPoolDataSource<PoolingDataSource>(configuration,
new IncrementPoolOnTimeoutConnectionAcquiringStrategy.Factory(5),
new RetryConnectionAcquiringStrategy.Factory(2)
);
}
示例10
public void setDataSource(PoolingDataSource dataSource) {
this.dataSource = dataSource;
}
示例11
@Override
public Class<?> getObjectType() {
return PoolingDataSource.class;
}
示例12
public void setDataSource(PoolingDataSource dataSource) {
this.dataSource = dataSource;
}
示例13
@Override
public Class<?> getObjectType() {
return PoolingDataSource.class;
}
示例14
public void setDataSource(PoolingDataSource dataSource) {
this.dataSource = dataSource;
}
示例15
@Override
public Class<?> getObjectType() {
return PoolingDataSource.class;
}
示例16
public void setDataSource(PoolingDataSource dataSource) {
this.dataSource = dataSource;
}
示例17
@Override
public Class<?> getObjectType() {
return PoolingDataSource.class;
}
示例18
@Override
public PoolAdapter<PoolingDataSource> newInstance(
ConfigurationProperties<PoolingDataSource, Metrics, PoolAdapter<PoolingDataSource>> configurationProperties) {
return new BitronixPoolAdapter(configurationProperties);
}
示例19
/**
* Init constructor
* @param configurationProperties configuration properties
*/
public BitronixPoolAdapter(ConfigurationProperties<PoolingDataSource, Metrics, PoolAdapter<PoolingDataSource>> configurationProperties) {
super(configurationProperties);
}