本文整理汇总了Java中io.dropwizard.db.ManagedDataSource类的典型用法代码示例。如果您正苦于以下问题:Java ManagedDataSource类的具体用法?Java ManagedDataSource怎么用?Java ManagedDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ManagedDataSource类属于io.dropwizard.db包,在下文中一共展示了ManagedDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的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;
}
示例2: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public ManagedDataSource build(MetricRegistry metricRegistry, String name) throws
ClassNotFoundException {
ManagedDataSource managedDataSource = super.build(metricRegistry, name);
if (isLazy) {
if (managedDataSource instanceof ManagedPooledDataSource) {
/* of course we can't depend on it by method protocol, but right now
* (currently used version of dropwizard 0.7.1 as well as last currently available 0.8.1)
* exactly this implementation will be returned by super.build(MetricRegistry mr, String name) method
*/
ManagedPooledDataSource managedPooledDataSource = (ManagedPooledDataSource) managedDataSource;
return new LazyManagedPooledDataSource(managedPooledDataSource.getPoolProperties(), metricRegistry);
}
throw new AssertionError(
"You can't use this DataSourceFactory implementation with your dropwizard version");
} else {
return managedDataSource;
}
}
示例3: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
/**
* Create an instance of MyBatis.
*
* @param environment The dropwizard environment
* @param config A Mybatis config object
* @param dataSource
* @param name The name of this mybatis factory used for metrics
* @return An instance of MyBatis.
*/
public final SqlSessionFactory build(Environment environment,
MyBatisConfiguration config,
ManagedDataSource dataSource,
String name) {
SqlSessionFactory sessionFactory = null;
// Try to use the mybatis configuration file if it is specified and exists.
try (InputStream inputStream = Resources.getResourceAsStream(config.getConfigFile())) {
sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException ioe) {
// Build session factory from configuration values given in the dropwizard config.
TransactionFactory transactionFactory = new JdbcTransactionFactory();
org.apache.ibatis.mapping.Environment myBatisEnvironment =
new org.apache.ibatis.mapping.Environment(ENV_NAME, transactionFactory, dataSource);
Configuration mybatisConfiguration = new Configuration(myBatisEnvironment);
sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);
}
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name,
new MyBatisHealthCheck(sessionFactory, config.getConfig().getValidationQuery()));
return sessionFactory;
}
示例4: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的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;
}
示例5: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的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;
}
示例6: run
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
@Override
public void run(ProductCatalogConfiguration configuration, Environment environment) throws Exception {
environment.jersey().setUrlPattern("/api/*");
environment.healthChecks().register("product catalog service",
guiceBundle.getInjector().getInstance(ProductCatalogServiceHealthCheck.class));
// run the migrations as part of startup and prepare the db with sample
// data
ManagedDataSource mds = configuration.getDataSourceFactory().build(environment.metrics(), "migrations");
try (Connection connection = mds.getConnection()) {
Liquibase migrator = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(),
new JdbcConnection(connection));
migrator.dropAll();
migrator.clearCheckSums();
migrator.update("");
}
}
示例7: run
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
@Override
public void run(final ProductReviewConfiguration configuration, final Environment environment) throws Exception {
environment.jersey().setUrlPattern("/api/*");
environment.healthChecks().register("product review service",
guiceBundle.getInjector().getInstance(ProductReviewServiceHealthCheck.class));
// run the migrations as part of startup and prepare the db with sample
// data
ManagedDataSource mds = configuration.getDataSourceFactory().build(environment.metrics(), "migrations");
try (Connection connection = mds.getConnection()) {
Liquibase migrator = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(),
new JdbcConnection(connection));
migrator.dropAll();
migrator.clearCheckSums();
migrator.update("");
}
}
示例8: run
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
@Override
public void run(T dwConfiguration, Environment environment) throws Exception {
final DataSourceFactory dbConfig = getDataSourceFactory(dwConfiguration);
ManagedDataSource dataSource = dbConfig.build(environment.metrics(), "jooq");
this.configuration = new DefaultConfiguration();
this.configuration.set(new DataSourceConnectionProvider(dataSource));
configure(this.configuration);
environment.jersey().register(JooqTransactionalApplicationListener.class);
environment.jersey().register(
new ConfigurationFactoryProvider.Binder(this.configuration, dataSource, multiTenantConnectionProvider));
environment.lifecycle().manage(dataSource);
if (multiTenantConnectionProvider != null) {
environment.lifecycle().manage(multiTenantConnectionProvider);
}
environment.healthChecks().register("jooq", new JooqHealthCheck(
DSL.using(this.configuration.derive(new DefaultConnectionProvider(dataSource.getConnection()))),
dbConfig.getValidationQuery()));
}
示例9: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的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;
}
示例10: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
@Override
public ManagedDataSource build(final MetricRegistry metricRegistry, final String name) {
final Properties properties = new Properties();
for (final Map.Entry<String, String> property : this.properties.entrySet()) {
properties.setProperty(property.getKey(), property.getValue());
}
final HikariConfig config = new HikariConfig();
config.setMetricRegistry(metricRegistry);
if (healthCheckRegistry != null) {
config.setHealthCheckRegistry(healthCheckRegistry);
}
config.setAutoCommit(autoCommit);
config.setDataSourceProperties(properties);
if (datasourceClassName != null) {
config.setDataSourceClassName(datasourceClassName);
} else {
config.setDriverClassName(driverClass);
}
config.setMaximumPoolSize(maxSize);
minSize.ifPresent(config::setMinimumIdle);
config.setPoolName(name);
config.setUsername(user);
config.setPassword(user != null && password == null ? "" : password);
return new HikariManagedPooledDataSource(config);
}
示例11: buildJdbcEventStore
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
private EventStore buildJdbcEventStore(EventPublisher publisher, Environment environment) {
ManagedDataSource ds = database.build(environment.metrics(), "eventstore");
DBI jdbi = new DBIFactory().build(environment, database, "eventstore");
updateDatabaseSchema(ds);
EventStore eventStore = new JdbcEventStore(jdbi, environment.getObjectMapper(), publisher);
return eventStore;
}
示例12: readonlyDataSource
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
@Provides @Singleton @Readonly ManagedDataSource readonlyDataSource(Environment environment,
KeywhizConfig config) {
DataSourceFactory dataSourceFactory = config.getReadonlyDataSourceFactory();
ManagedDataSource dataSource = dataSourceFactory.build(environment.metrics(), "db-readonly");
environment.lifecycle().manage(dataSource);
environment.healthChecks().register("db-readonly-health",
new JooqHealthCheck(dataSource, RETURN_UNHEALTHY));
return dataSource;
}
示例13: readonlyJooqContext
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
@Provides @Singleton
@Readonly DSLContext readonlyJooqContext(@Readonly ManagedDataSource dataSource)
throws SQLException {
DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
org.jooq.Configuration configuration = dslContext.configuration();
// Disable support for nested transactions via savepoints (required for MySQL)
// See: https://groups.google.com/forum/#!topic/jooq-user/zG0U6CkxI5o
configuration.set(new DefaultTransactionProvider(configuration.connectionProvider(), false));
return dslContext;
}
示例14: acquire
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
@Override
public Connection acquire(String tenantIdentifier) {
ManagedDataSource dataSource = dataSources.get(tenantIdentifier);
if (dataSource == null) {
dataSourceFactory.setUrl(url);
dataSource = dataSourceFactory.build(metricRegistry, "dataSource-" + tenantIdentifier);
dataSources.put(tenantIdentifier, dataSource);
}
try {
return dataSource.getConnection();
} catch (SQLException e) {
throw new DataAccessException("An error occurred while getting a connection.", e);
}
}
示例15: build
import io.dropwizard.db.ManagedDataSource; //导入依赖的package包/类
EntityManagerFactory build(EntityManagerBundle<?> bundle,
Environment environment,
PooledDataSourceFactory dbConfig,
List<Class<?>> entities,
String name) {
final ManagedDataSource dataSource = dbConfig.build(environment.metrics(), name);
return build(bundle, environment, dbConfig, dataSource, entities);
}