本文整理汇总了Java中io.dropwizard.db.PooledDataSourceFactory类的典型用法代码示例。如果您正苦于以下问题:Java PooledDataSourceFactory类的具体用法?Java PooledDataSourceFactory怎么用?Java PooledDataSourceFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PooledDataSourceFactory类属于io.dropwizard.db包,在下文中一共展示了PooledDataSourceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectToDatasource
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
private IDBI connectToDatasource(ShardInfo shardInfo) {
PooledDataSourceFactory urlReplacedCopy =
copyAndReplaceURL(dropwizardDSFactory, shardInfo);
// we cannot re-register using the same name (dropwizard metrics do not merge on name collision)
String dbShardName = humanFriendlyShardNamer.nameShard(shardInfo);
DBI jdbi = dropwizardDbiFactory.build(
dropwizardEnvironment,
urlReplacedCopy,
dbShardName);
if (DBIInitializer != null) {
DBIInitializer.initialize(jdbi);
}
logger.info("New shard connection created: " + dbShardName);
return jdbi;
}
示例2: build
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Override
public DBI build(Environment environment, PooledDataSourceFactory configuration, ManagedDataSource dataSource, String name) {
final DBI dbi = super.build(environment, configuration, dataSource, name);
dbi.registerArgumentFactory(new ValueArgumentFactory(configuration.getDriverClass()));
dbi.registerArgumentFactory(new OptionArgumentFactory(configuration.getDriverClass()));
dbi.registerContainerFactory(new OptionContainerFactory());
// The order of container factories is important, least specific to most specific
dbi.registerContainerFactory(new SeqContainerFactory());
dbi.registerContainerFactory(new IndexedSeqContainerFactory());
dbi.registerContainerFactory(new SetContainerFactory());
dbi.registerContainerFactory(new TreeContainerFactory());
dbi.registerContainerFactory(new ListContainerFactory());
dbi.registerContainerFactory(new ArrayContainerFactory());
dbi.registerContainerFactory(new QueueContainerFactory());
dbi.registerContainerFactory(new StreamContainerFactory());
dbi.registerContainerFactory(new VectorContainerFactory());
return dbi;
}
示例3: build
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
public Jdbi build(Environment environment,
PooledDataSourceFactory configuration,
String name) {
ManagedDataSource dataSource = configuration.build(environment.metrics(), name);
String validationQuery = configuration.getValidationQuery();
Jdbi jdbi = Jdbi.create(dataSource);
jdbi.setTimingCollector(new InstrumentedTimingCollector(environment.metrics(), nameStrategy));
jdbi.installPlugins();
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name, new JdbiHealthCheck(
environment.getHealthCheckExecutorService(),
configuration.getValidationQueryTimeout().orElseGet(() -> Duration.seconds(5)),
jdbi, validationQuery));
return jdbi;
}
示例4: build
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
public SessionFactory build(final RemoteCredentialHibernateBundle<?> bundle,
final Environment environment,
final PooledDataSourceFactory dbConfig,
final ManagedDataSource dataSource,
final List<Class<?>> entities) {
final ConnectionProvider provider = this.buildConnectionProvider(dataSource,
dbConfig.getProperties());
final SessionFactory factory = this.buildSessionFactory(bundle,
dbConfig,
provider,
dbConfig.getProperties(),
entities);
final SessionFactoryManager managedFactory = new SessionFactoryManager(factory, dataSource);
environment.lifecycle().manage(managedFactory);
return factory;
}
示例5: init
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
private void init(final ImmutableList<Class<?>> inEntities) {
String numShardsEnv = System.getProperty("db.shards", "2");
int numShards = Integer.parseInt(numShardsEnv);
shardManager = new ShardManager(numShards);
for (int i = 0; i < numShards; i++) {
final int finalI = i;
shardBundles.add(new HibernateBundle<T>(inEntities, new SessionFactoryFactory()) {
@Override
protected String name() {
return String.format("connectionpool-%d", finalI);
}
@Override
public PooledDataSourceFactory getDataSourceFactory(T t) {
return getConfig(t).getShards().get(finalI);
}
});
}
}
示例6: initialize
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Override
public void initialize(final Bootstrap<ProductCatalogConfiguration> bootstrap) {
bootstrap.addBundle(discoveryBundle);
bootstrap.addBundle(new MigrationsBundle<ProductCatalogConfiguration>() {
@Override
public PooledDataSourceFactory getDataSourceFactory(ProductCatalogConfiguration configuration) {
return configuration.getDataSourceFactory();
}
});
guiceBundle = GuiceBundle.<ProductCatalogConfiguration> newBuilder().addModule(new ProductCatalogModule())
.enableAutoConfig(getClass().getPackage().getName()).setConfigClass(ProductCatalogConfiguration.class)
.build(Stage.PRODUCTION);
bootstrap.addBundle(guiceBundle);
// Uncomment below to read the yaml file from Jar
// bootstrap.setConfigurationSourceProvider(new
// ResourceConfigurationSourceProvider());
}
示例7: initialize
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Override
public void initialize(final Bootstrap<ProductReviewConfiguration> bootstrap) {
bootstrap.addBundle(discoveryBundle);
bootstrap.addBundle(new MigrationsBundle<ProductReviewConfiguration>() {
@Override
public PooledDataSourceFactory getDataSourceFactory(ProductReviewConfiguration configuration) {
return configuration.getDataSourceFactory();
}
});
guiceBundle = GuiceBundle.<ProductReviewConfiguration> newBuilder().addModule(new ProductReviewModule())
.enableAutoConfig(getClass().getPackage().getName()).setConfigClass(ProductReviewConfiguration.class)
.build(Stage.PRODUCTION);
bootstrap.addBundle(guiceBundle);
// Uncomment below to read the yaml file from Jar
// bootstrap.setConfigurationSourceProvider(new
// ResourceConfigurationSourceProvider());
}
示例8: run
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Override
public final void run(T configuration, Environment environment) throws Exception {
final PooledDataSourceFactory dbConfig = getDataSourceFactory(configuration);
this.entityManagerFactory = entityManagerFactoryFactory.build(this, environment, dbConfig, entities, name());
this.entityManagerContext = new EntityManagerContext(entityManagerFactory);
this.sharedEntityManager = sharedEntityManagerFactory.build(entityManagerContext);
registerUnitOfWorkListerIfAbsent(environment).registerEntityManagerFactory(name(), entityManagerFactory);
environment.healthChecks().register(name(),
new EntityManagerFactoryHealthCheck(
environment.getHealthCheckExecutorService(),
dbConfig.getValidationQueryTimeout().orElse(Duration.seconds(5)),
entityManagerFactory,
dbConfig.getValidationQuery()));
}
示例9: testFindEntityClassesFromDirectory
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testFindEntityClassesFromDirectory() {
String packageWithEntities = "com.scottescue.dropwizard.entitymanager.entity.fake.entities.pckg";
ScanningEntityManagerBundle bundle = new ScanningEntityManagerBundle(packageWithEntities) {
@Override
public void run(Object o, Environment environment) throws Exception {
}
@Override
public PooledDataSourceFactory getDataSourceFactory(Configuration configuration) {
return null;
}
};
assertThat(bundle.getEntities()).containsOnly(
FakeEntity1.class,
DeepFakeEntity.class,
DeeperFakeEntity.class);
}
示例10: testFindEntityClassesFromMultipleDirectories
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testFindEntityClassesFromMultipleDirectories() {
String root = "com.scottescue.dropwizard.entitymanager.entity.fake.entities.";
ScanningEntityManagerBundle bundle = new ScanningEntityManagerBundle(
root.concat("pckg"), root.concat("pckg2"), root.concat("pckg3")) {
@Override
public void run(Object o, Environment environment) throws Exception {
}
@Override
public PooledDataSourceFactory getDataSourceFactory(Configuration configuration) {
return null;
}
};
assertThat(bundle.getEntities()).containsOnly(
FakeEntity1.class,
FakeEntity2.class,
FakeEntity3.class,
DeepFakeEntity.class,
DeeperFakeEntity.class);
}
示例11: build
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Override
public DBI build(Environment environment,
PooledDataSourceFactory configuration,
ManagedDataSource dataSource,
String name) {
final DBI dbi = super.build(environment, configuration, dataSource, name);
dbi.registerArgumentFactory(new OptionalArgumentFactory(configuration.getDriverClass()));
dbi.registerContainerFactory(new OptionalContainerFactory());
dbi.registerArgumentFactory(new LocalDateArgumentFactory());
dbi.registerArgumentFactory(new OptionalLocalDateArgumentFactory());
dbi.registerArgumentFactory(new LocalDateTimeArgumentFactory());
dbi.registerArgumentFactory(new OptionalLocalDateTimeArgumentFactory());
dbi.registerMapper(new LocalDateMapper());
dbi.registerMapper(new LocalDateTimeMapper());
final Optional<TimeZone> tz = Optional.ofNullable(databaseTimeZone().orNull());
dbi.registerArgumentFactory(new InstantArgumentFactory(tz));
dbi.registerArgumentFactory(new OptionalInstantArgumentFactory(tz));
dbi.registerMapper(new InstantMapper(tz));
return dbi;
}
示例12: configureDataSourceFactory
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
private void configureDataSourceFactory(
final C configuration,
final Environment environment,
final String name,
final PooledDataSourceFactory dataSourceFactory
) throws RuntimeException {
try {
final JooqFactory jooqFactory = getJooqFactory(configuration);
final Configuration cfg = jooqFactory.build(environment, dataSourceFactory, name);
final JooqHealthCheck healthCheck = new JooqHealthCheck(cfg, dataSourceFactory.getValidationQuery());
environment.healthChecks().register(name, healthCheck);
jooqFactoryConfigurationMap.put(name, cfg);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
示例13: initialize
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
public void initialize(Environment environment, PooledDataSourceFactory dataSourceFactory, String name) {
dataSource = dataSourceFactory.build(environment.metrics(), name);
bCryptPasswordEncryptor = BCryptPasswordEncryptor.newInstance(12);
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name,
new DataSourceHealthCheck(environment.getHealthCheckExecutorService(),
dataSourceFactory.getValidationQueryTimeout()
.orElse(Duration.seconds(5)),
dataSource,
dataSourceFactory.getValidationQuery()));
}
示例14: run
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
@Override
public void run(final BenchConfiguration config,
final Environment environment) {
final DBIFactory factory = new DBIFactory();
final Optional<PooledDataSourceFactory> tomcatFactory = config.getTomcatFactory().map(x -> x);
config.getHikariFactory().ifPresent(x -> x.setHealthCheckRegistry(environment.healthChecks()));
final Optional<PooledDataSourceFactory> hikariFactory = config.getHikariFactory().map(x -> x);
final PooledDataSourceFactory datasource = tomcatFactory.orElse(hikariFactory.orElse(null));
final DBI jdbi = factory.build(environment, datasource, "postgresql");
jdbi.registerMapper(new QuestionMapper());
final QuestionQuery dao = jdbi.onDemand(QuestionQuery.class);
environment.jersey().register(new QuestionResource(dao));
}
示例15: copyAndReplaceURL
import io.dropwizard.db.PooledDataSourceFactory; //导入依赖的package包/类
private PooledDataSourceFactory copyAndReplaceURL(
DataSourceFactory dsFactory,
ShardInfo shardInfo) {
DataSourceFactory copy = new CopiedDataSourceFactory(dsFactory);
copy.setUrl(shardInfo.url());
return copy;
}