当前位置: 首页>>代码示例>>Java>>正文


Java DataSourceFactory类代码示例

本文整理汇总了Java中io.dropwizard.db.DataSourceFactory的典型用法代码示例。如果您正苦于以下问题:Java DataSourceFactory类的具体用法?Java DataSourceFactory怎么用?Java DataSourceFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DataSourceFactory类属于io.dropwizard.db包,在下文中一共展示了DataSourceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Before
public void setup() throws Exception
{
    DBIFactory factory = new DBIFactory();
    Environment environment = new Environment("test", new ObjectMapper(), null, new MetricRegistry(), ClassLoader.getSystemClassLoader());
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:hsqldb:mem:soa-jdbi;shutdown=true");
    dataSourceFactory.setDriverClass("org.hsqldb.jdbc.JDBCDriver");
    dataSourceFactory.setLogValidationErrors(true);
    dataSourceFactory.setUser("SA");
    dataSourceFactory.setValidationQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES");
    DBI jdbi = factory.build(environment, dataSourceFactory, "test");
    dynamicAttributes = new JdbiDynamicAttributes(jdbi, Collections.singletonList("test"));

    dynamicAttributes.getDao().createTable();
    dynamicAttributes.start();
}
 
开发者ID:soabase,项目名称:soabase,代码行数:18,代码来源:TestJdbiDynamicAttributes.java

示例2: setupTests

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:test-" + System.currentTimeMillis() + "?user=sa");
    dataSourceFactory.setInitialSize(1);
    final DBI dbi = new VavrDBIFactory().build(env, dataSourceFactory, "test");
    try (Handle h = dbi.open()) {
        h.execute("CREATE TABLE tasks (" +
                "id INT PRIMARY KEY, " +
                "assignee VARCHAR(255) NOT NULL, " +
                "start_date TIMESTAMP, " +
                "end_date TIMESTAMP, " +
                "comments VARCHAR(1024) " +
                ")");
    }
    dao = dbi.onDemand(TaskDao.class);

    dao.insert(100, Option.some("Name 1"), LocalDate.parse("2017-08-24"), Option.none(), Option.none());
    dao.insert(200, Option.some("Name 2"), LocalDate.parse("2017-08-25"), Option.none(), Option.some("To be done"));
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:22,代码来源:VavrDBIFactoryTest.java

示例3: JDBIManager

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
/**
 * @param shardService Your shard service.
 * @param shardRegistry Your shard registry.
 * @param dbiRegistry Your DBI registry.
 * @param daoRegistry Your DAO registry.
 * @param dropwizardDbiFactory Your dropwizard application's DBI Factory.
 * @param dropwizardEnvironment Your dropwizard application's environment.
 * @param dropwizardDSFactory Your dropwizard application's datasource factory.
 * @param DBIInitializer We call your initializer immediately after dropwizardDbiFactory builds your
 *                        DBI. @see jdbishard.jdbi.NoOpDBIInitializer.
 * @param humanFriendlyShardNamer We register metrics for each shard connection given the human
 *                                friendly name. @see jdbishard.sharding.IdOnlyShardNamer.
 */
@Inject
public JDBIManager(
        ShardService<ShardIdT, KeyT> shardService,
        ShardRegistry<ShardIdT, KeyT> shardRegistry,
        DBIRegistry<ShardIdT> dbiRegistry,
        DAORegistry<ShardIdT> daoRegistry,
        DBIFactory dropwizardDbiFactory,
        Environment dropwizardEnvironment,
        DataSourceFactory dropwizardDSFactory,
        DBIInitializer DBIInitializer,
        HumanFriendlyShardNamer humanFriendlyShardNamer)
{
    this.shardService = shardService;
    this.shardRegistry = shardRegistry;
    this.dbiRegistry = dbiRegistry;
    this.daoRegistry = daoRegistry;
    this.dropwizardDbiFactory = dropwizardDbiFactory;
    this.dropwizardEnvironment = dropwizardEnvironment;
    this.dropwizardDSFactory = dropwizardDSFactory;
    this.DBIInitializer = DBIInitializer;
    this.humanFriendlyShardNamer = humanFriendlyShardNamer;
}
 
开发者ID:toasttab,项目名称:jdbishard,代码行数:36,代码来源:JDBIManager.java

示例4: build

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
/**
 * Create an instance of MyBatis.
 *
 * @param environment The dropwizard environment
 * @param configuration The data source factory/configuration
 * @param dataSource The datasource you want to use.
 * @param name The name of this mybatis factory used for metrics
 * @return An instance of MyBatis.
 */
public final SqlSessionFactory build(Environment environment,
        DataSourceFactory configuration,
        ManagedDataSource dataSource,
        String name) {
    // Initialize validation query
    final String validationQuery = configuration.getValidationQuery();

    // Build mybatis session factory
    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);
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);

    // Setup managed data source and health checks
    environment.lifecycle().manage(dataSource);
    environment.healthChecks().register(name, new MyBatisHealthCheck(sessionFactory, validationQuery));

    return sessionFactory;
}
 
开发者ID:cvent,项目名称:dropwizard-mybatis,代码行数:30,代码来源:MyBatisFactory.java

示例5: setUp

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    environment = new Environment("test", new ObjectMapper(), Validators.newValidator(),
            metricRegistry, ClassLoader.getSystemClassLoader());

    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:h2:mem:jdbi3-test");
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.asSingleConnectionPool();

    dbi = new JdbiFactory(new TimedAnnotationNameStrategy()).build(environment, dataSourceFactory, "h2");
    dbi.useTransaction(h -> {
        h.createScript(Resources.toString(Resources.getResource("schema.sql"), Charsets.UTF_8)).execute();
        h.createScript(Resources.toString(Resources.getResource("data.sql"), Charsets.UTF_8)).execute();
    });
    dao = dbi.onDemand(GameDao.class);
    for (LifeCycle lc : environment.lifecycle().getManagedObjects()) {
        lc.start();
    }
}
 
开发者ID:arteam,项目名称:dropwizard-jdbi3,代码行数:22,代码来源:JdbiTest.java

示例6: initialize

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Override
public void initialize(Bootstrap<AdminUsersConfig> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(NON_STRICT_VARIABLE_SUBSTITUTOR)
            )
    );

    bootstrap.addBundle(new MigrationsBundle<AdminUsersConfig>() {
        @Override
        public DataSourceFactory getDataSourceFactory(AdminUsersConfig configuration) {
            return configuration.getDataSourceFactory();
        }
    });

    bootstrap.addCommand(new DependentResourceWaitCommand());
    bootstrap.addCommand(new MigrateToInitialDbState());
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:19,代码来源:AdminUsersApp.java

示例7: apply

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Override
public Statement apply(Statement base, Description description) {
    return rules.apply(new Statement() {
        @Override
        public void evaluate() throws Throwable {
            logger.info("Clearing database.");
            app.getApplication().run("db", "drop-all", "--confirm-delete-everything", configFilePath);
            app.getApplication().run("migrateToInitialDbState", configFilePath);
            doSecondaryDatabaseMigration();
            restoreDropwizardsLogging();

            DataSourceFactory dataSourceFactory = app.getConfiguration().getDataSourceFactory();
            databaseTestHelper = new DatabaseTestHelper(new DBI(dataSourceFactory.getUrl(), dataSourceFactory.getUser(), dataSourceFactory.getPassword()));

            base.evaluate();
        }
    }, description);
}
 
开发者ID:alphagov,项目名称:pay-adminusers,代码行数:19,代码来源:DropwizardAppWithPostgresRule.java

示例8: registersACustomNameOfHealthCheckAndDBPoolMetrics

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void registersACustomNameOfHealthCheckAndDBPoolMetrics() throws Exception {
    final HibernateBundle<Configuration> customBundle = new HibernateBundle<Configuration>(entities, factory) {
        @Override
        public DataSourceFactory getDataSourceFactory(Configuration configuration) {
            return dbConfig;
        }

        @Override
        protected String name() {
            return "custom-hibernate";
        }
    };
    when(factory.build(eq(customBundle),
            any(Environment.class),
            any(DataSourceFactory.class),
            anyList(),
            eq("custom-hibernate"))).thenReturn(sessionFactory);

    customBundle.run(configuration, environment);

    final ArgumentCaptor<SessionFactoryHealthCheck> captor =
            ArgumentCaptor.forClass(SessionFactoryHealthCheck.class);
    verify(healthChecks).register(eq("custom-hibernate"), captor.capture());
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:27,代码来源:HibernateBundleTest.java

示例9: initDatabase

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
private void initDatabase(ReaperApplicationConfiguration config) throws ReaperException {
  Flyway flyway = new Flyway();
  DataSourceFactory dsfactory = config.getDataSourceFactory();
  flyway.setDataSource(
      dsfactory.getUrl(),
      dsfactory.getUser(),
      dsfactory.getPassword());

  if ("database".equals(config.getStorageType())) {
    LOG.warn("!!!!!!!!!!    USAGE 'database' AS STORAGE TYPE IS NOW DEPRECATED   !!!!!!!!!!!!!!");
    LOG.warn("!!!!!!!!!!    PLEASE USE EITHER 'postgres' OR 'h2' FROM NOW ON     !!!!!!!!!!!!!!");
    if (config.getDataSourceFactory().getUrl().contains("h2")) {
      flyway.setLocations("/db/h2");
    } else {
      flyway.setLocations("/db/postgres");
    }
  } else {
    flyway.setLocations("/db/".concat(config.getStorageType().toLowerCase()));
  }
  flyway.setBaselineOnMigrate(true);
  flyway.repair();
  flyway.migrate();
}
 
开发者ID:thelastpickle,项目名称:cassandra-reaper,代码行数:24,代码来源:ReaperApplication.java

示例10: setUp

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Before
public void setUp() {
  //create a valid config
  DataSourceFactory dataSourceFactory = new DataSourceFactory();
  dataSourceFactory.setDriverClass("org.postgresql.Driver");
  dataSourceFactory.setUrl("jdbc:postgresql://db.example.com/db-prod");
  dataSourceFactory.setUser("user");
  CassandraFactory cassandraFactory = new CassandraFactory();
  cassandraFactory.setContactPoints(new String[]{"127.0.0.1"});
  config.setCassandraFactory(cassandraFactory);
  config.setPostgresDataSourceFactory(dataSourceFactory);
  config.setHangingRepairTimeoutMins(1);
  config.setRepairParallelism(RepairParallelism.DATACENTER_AWARE);
  config.setRepairRunThreadCount(1);
  config.setSegmentCount(1);
  config.setScheduleDaysBetween(7);
  config.setStorageType("foo");
  config.setIncrementalRepair(false);
}
 
开发者ID:thelastpickle,项目名称:cassandra-reaper,代码行数:20,代码来源:ReaperApplicationConfigurationTest.java

示例11: initialize

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Override
public void initialize(Bootstrap<PublicAuthConfiguration> bootstrap) {
    bootstrap.setConfigurationSourceProvider(
            new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
                    new EnvironmentVariableSubstitutor(false)
            )
    );

    bootstrap.addBundle(new DBIExceptionsBundle());

    bootstrap.addBundle(new MigrationsBundle<PublicAuthConfiguration>() {
        @Override
        public DataSourceFactory getDataSourceFactory(PublicAuthConfiguration configuration) {
            return configuration.getDataSourceFactory();
        }
    });

    bootstrap.addCommand(new DependentResourceWaitCommand());
}
 
开发者ID:alphagov,项目名称:pay-publicauth,代码行数:20,代码来源:PublicAuthApp.java

示例12: run

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Override
public void run(PublicAuthConfiguration conf, Environment environment) throws Exception {
    DataSourceFactory dataSourceFactory = conf.getDataSourceFactory();

    jdbi = new DBIFactory().build(environment, dataSourceFactory, "postgresql");
    initialiseMetrics(conf, environment);

    TokenService tokenService = new TokenService(conf.getTokensConfiguration());

    environment.jersey().register(new AuthDynamicFeature(
            new OAuthCredentialAuthFilter.Builder<Token>()
                    .setAuthenticator(new TokenAuthenticator(tokenService))
                    .setPrefix("Bearer")
                    .buildAuthFilter()));
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(Token.class));

    environment.jersey().register(new PublicAuthResource(new AuthTokenDao(jdbi), tokenService));
    environment.jersey().register(new HealthCheckResource(environment));
    environment.jersey().register(new ValidationExceptionMapper());
    environment.jersey().register(new TokenNotFoundExceptionMapper());
    environment.healthChecks().register("database", new DatabaseHealthCheck(conf,environment));

    environment.servlets().addFilter("LoggingFilter", new LoggingFilter())
            .addMappingForUrlPatterns(of(REQUEST), true, "/v1" + "/*");
}
 
开发者ID:alphagov,项目名称:pay-publicauth,代码行数:26,代码来源:PublicAuthApp.java

示例13: initialize

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@Override
public void initialize(final Bootstrap<AuthriteServiceConfiguration> bootstrap) {
    bootstrap.addBundle(new Java8Bundle());

    if (useClasspathAssets) {
        bootstrap.addBundle(new AssetsBundle("/assets/", "/"));
    } else {
        bootstrap.addBundle(new FileAssetsBundle("src/main/resources/assets", "/"));
    }

    bootstrap.addBundle(new MigrationsBundle<AuthriteServiceConfiguration>() {
        @Override
        public DataSourceFactory getDataSourceFactory(final AuthriteServiceConfiguration configuration) {
            return configuration.getDatabase();
        }
    });
}
 
开发者ID:lewisd32,项目名称:authrite,代码行数:18,代码来源:AuthriteServiceApplication.java

示例14: AugmentedConfiguration

import io.dropwizard.db.DataSourceFactory; //导入依赖的package包/类
@JsonCreator
public AugmentedConfiguration(@JsonProperty(value = "dbtype") final DbType dbtype,
                              @JsonProperty(value = "mongodb", required = false) final MongodbConfiguration mongodbConfig,
                              @JsonProperty(value = "rdbms", required = false) final DataSourceFactory rdbmsConfig,
                              @JsonProperty(value = "authCacheSpec", required = false) final String authCacheSpec,
                              @JsonProperty(value = "openDataClient", required = true) final OpenDataClientConfiguration openDataClientConfig,
                              @JsonProperty(value = "resetPasswordToken", required = false) final ResetPasswordTokenConfiguration tokenConfig,
                              @JsonProperty(value = "defaultPageSize", required = false) final Integer defaultPageSize) {
    this.dbtype = dbtype;
    this.mongoConfig = mongodbConfig;
    this.rdbmsConfig = rdbmsConfig;
    this.openDataClientConfig = openDataClientConfig;
    this.defaultPageSize = defaultPageSize != null ? defaultPageSize : DEFAULT_PAGE_SIZE;
    this.authCacheSpec = CacheBuilder.from(authCacheSpec != null ? authCacheSpec : DEFAULT_AUTH_CACHE_SPEC);
    this.tokenConfig = tokenConfig != null ? tokenConfig : new ResetPasswordTokenConfiguration(DEFAULT_TOKEN_TIME);
}
 
开发者ID:blstream,项目名称:AugumentedSzczecin_java,代码行数:17,代码来源:AugmentedConfiguration.java

示例15: run

import io.dropwizard.db.DataSourceFactory; //导入依赖的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()));
}
 
开发者ID:tbugrara,项目名称:dropwizard-jooq,代码行数:24,代码来源:JooqBundle.java


注:本文中的io.dropwizard.db.DataSourceFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。