本文整理汇总了Java中io.dropwizard.jdbi.DBIFactory.build方法的典型用法代码示例。如果您正苦于以下问题:Java DBIFactory.build方法的具体用法?Java DBIFactory.build怎么用?Java DBIFactory.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.dropwizard.jdbi.DBIFactory
的用法示例。
在下文中一共展示了DBIFactory.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void run(final BloopServerConfiguration configuration,
final Environment environment) {
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "postgresql");
final FlagDAO flagDAO = jdbi.onDemand(FlagDAO.class);
final NearbyFlagDAO nearbyFlagDAO = jdbi.onDemand(NearbyFlagDAO.class);
final PlayerDAO playerDAO = jdbi.onDemand(PlayerDAO.class);
final Client client = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
.build(getName());
final String firebaseKey = configuration.getFirebaseKey();
environment.jersey().register(new FlagResource(flagDAO, nearbyFlagDAO, playerDAO, client, firebaseKey));
environment.jersey().register(new PlayerResource(playerDAO, flagDAO));
}
示例2: setup
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的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();
}
示例3: createSampleResources
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
private void createSampleResources(IronTestConfiguration configuration, Environment environment) {
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getSampleDatabase(), "sampleDatabase");
// create DAO objects
final ArticleDAO articleDAO = jdbi.onDemand(ArticleDAO.class);
// create database tables
articleDAO.createTableIfNotExists();
// register APIs
environment.jersey().register(new ArticleResource(articleDAO));
// register SOAP web services
jaxWsBundle.publishEndpoint(new EndpointBuilder("/article", new ArticleSOAP(articleDAO)));
}
示例4: initializeStorage
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
private IStorage initializeStorage(ReaperApplicationConfiguration config, Environment environment)
throws ReaperException {
IStorage storage;
if ("memory".equalsIgnoreCase(config.getStorageType())) {
storage = new MemoryStorage();
} else if ("cassandra".equalsIgnoreCase(config.getStorageType())) {
storage = new CassandraStorage(config, environment);
} else if ("postgres".equalsIgnoreCase(config.getStorageType())
|| "h2".equalsIgnoreCase(config.getStorageType())
|| "database".equalsIgnoreCase(config.getStorageType())) {
// create DBI instance
final DBIFactory factory = new DBIFactory();
// instanciate store
storage = new PostgresStorage(factory.build(environment, config.getDataSourceFactory(), "postgresql"));
initDatabase(config);
} else {
LOG.error("invalid storageType: {}", config.getStorageType());
throw new ReaperException("invalid storage type: " + config.getStorageType());
}
Preconditions.checkState(storage.isStorageConnected(), "Failed to connect storage");
return storage;
}
示例5: runService
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void runService(final HmlJdbiConfiguration configuration, final Environment environment) throws Exception {
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "mysql");
final HmlDao hmlDao = jdbi.onDemand(HmlDao.class);
Injector injector = Guice.createInjector(new JdbiHmlServiceModule(), new AbstractModule() {
@Override
protected void configure() {
bind(HmlDao.class).toInstance(hmlDao);
}
});
environment.healthChecks().register("database", new DBIHealthCheck(jdbi, "select 1"));
environment.jersey().register(injector.getInstance(HmlResource.class));
environment.jersey().register(new HmlExceptionMapper());
environment.jersey().register(new HmlMessageBodyReader());
environment.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
}
示例6: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void run(final ServiceRegistryConfiguration configuration, final Environment environment) throws Exception {
final DataSourceFactory database = configuration.getDatabase();
// execute DB migrations
final Flyway flyway = new Flyway();
flyway.setDataSource(database.getUrl(), database.getUser(), database.getPassword());
log.debug("execute database migrations");
flyway.migrate();
log.info("database migrations successfully executed");
// create DBI instance
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, database, "postgresql");
environment.jersey().register(AuthFactory.binder(new BasicAuthFactory<>(
new ServiceRegistryAuthenticator(configuration.getCredentials()), "Realm", ServiceRegistryCaller.class))
);
environment.jersey().register(new ServiceResource(jdbi.onDemand(ServiceDAO.class)));
}
示例7: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void run(SentimentalConfiguration configuration, Environment environment) {
final TemplateHealthCheck healthCheck = new TemplateHealthCheck(configuration.getTemplate());
environment.healthChecks().register("template", healthCheck);
// SPI Lexicon
final Lexicon lexicon = new FileBasedLexicon(configuration.getLexiconFileName());
// SPI Trend
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "postgresql");
final AuditDAO auditDao = jdbi.onDemand(AuditDAO.class);
final Trend audit = new TrendRepository(auditDao);
// Domain Model
final SentimentAnalysis service = new SentimentAnalysis(lexicon, audit);
// API RESTful
final SentimentalResource resource = new SentimentalResource(service);
environment.jersey().register(resource);
// API Twitter
final TwitterAdapter twitterAdapter = new TwitterAdapter(service, new SamplePlayer());
twitterAdapter.subscribe("devoxx, #memepasmal, @cyriux, @tpierrain, arolla");
// start
}
示例8: runService
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void runService(final FeatureJdbiConfiguration configuration, final Environment environment) throws Exception {
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "mysql");
final FeatureDao featureDao = jdbi.onDemand(FeatureDao.class);
Injector injector = Guice.createInjector(new JdbiFeatureServiceModule(), new ExceptionMapperModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(FeatureDao.class).toInstance(featureDao);
}
});
environment.healthChecks().register("database", new DBIHealthCheck(jdbi, "select 1"));
environment.jersey().register(injector.getInstance(FeatureResource.class));
environment.jersey().register(injector.getInstance(UserInputExceptionMapper.class));
environment.getObjectMapper()
.enable(SerializationFeature.INDENT_OUTPUT)
.addMixInAnnotations(Feature.class, FeatureMixIn.class);
}
示例9: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
public void run(MyApplicationConfiguration configuration,
Environment environment) throws ClassNotFoundException {
// create database connection using JDBI
final DBIFactory factory = new DBIFactory();
final DataSourceFactory dataSourceFactory = configuration.getDataSourceFactory();
final DBI jdbi = factory.build(environment, dataSourceFactory, "derby");
// add resources
final UserDAO dao = jdbi.onDemand(UserDAO.class);
try {
dao.createUserTable();
logger.info("User table created");
} catch (Exception e) {
// probably the table already exists. Don't worry about it.
if (e.getCause().getMessage().contains("already exists in Schema")) {
logger.info("User table already exists.");
} else {
logger.log(Level.INFO, "User DB was not created", e);
}
}
environment.jersey().register(new UserResourceImpl(dao));
}
示例10: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void run(ThmmyRssConfiguration configuration, Environment env)
throws Exception {
client = new JerseyClientBuilder(env).using(configuration.getJerseyClientConfiguration()).using(env)
.withProperty("PROPERTY_CHUNKED_ENCODING_SIZE", 0).build("jersey-client");
DBIFactory factory = new DBIFactory();
DBI jdbi = factory.build(env, configuration.getDatabase(), "announcement-db");
announcementDAO = jdbi.onDemand(AnnouncementDAO.class);
tryCreateAnnouncementTable();
AnnouncementFetcher announcementFetcher = new AnnouncementFetcher(client, configuration);
env.healthChecks().register("announcement-fetcher-health", new AnnouncementFetcherHealthCheck(configuration, announcementFetcher));
this.announcementService = new AnnouncementServiceImpl(announcementDAO, announcementFetcher, configuration);
env.jersey().register(new FeedResource(announcementService, configuration));
env.jersey().register(new IndexResource(configuration));
}
示例11: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
protected void run(Environment env, Namespace namespace, T configuration) throws Exception {
CliConveniences.quietLogging("ifar", "hsqldb.db");
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(env, getSkidRoadReadOnlyConfiguration(configuration).getDatabaseConfiguration(), "logfile");
JDBILogFileDAO dao = jdbi.onDemand(DefaultJDBILogFileDAO.class);
List<CountByState> counts = dao.countLogFilesByState();
if (!counts.isEmpty()) {
System.out.println(String.format("%-20s | %-10s", "STATE", "COUNT"));
System.out.println(String.format("%s_|_%s", StringUtils.repeat("_", 20), StringUtils.repeat("_", 10)));
}
for (CountByState cbs : counts) {
System.out.println(String.format("%-20s | %-10d", cbs.getState(), cbs.getCount()));
}
}
示例12: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void run(final SecureTodoConfiguration configuration,
final Environment environment) {
final DBIFactory dbiFactory = new DBIFactory();
final DBI todoJdbi = dbiFactory.build(environment, configuration.getTodoDbDataSourceFactory(), "todoDb");
final TodoUserDAO todoUserDao = todoJdbi.onDemand(TodoUserDAO.class);
final TodoItemDAO todoItemDao = todoJdbi.onDemand(TodoItemDAO.class);
final AccessControlContextFactory accessControlContextFactory = configuration.getAccessControlContextFactory();
accessControlContextFactory.initialize(environment, configuration.getOaccDbDataSourceFactory(), "oacc");
environment.jersey().register(new TodoUserResource(new TodoUserService(todoUserDao, accessControlContextFactory)));
environment.jersey().register(new TodoItemResource(new TodoItemService(todoItemDao)));
environment.jersey().register(new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<OaccPrincipal>()
.setAuthenticator(new OaccBasicAuthenticator(accessControlContextFactory))
.setRealm("OACC Basic Authentication")
.buildAuthFilter()));
// to use @Auth to inject a custom Principal type into a resource:
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(OaccPrincipal.class));
environment.jersey().register(new AuthorizationExceptionMapper(environment.metrics()));
environment.jersey().register(new IllegalArgumentExceptionMapper(environment.metrics()));
environment.jersey().register(new InvalidCredentialsExceptionMapper(environment.metrics()));
environment.jersey().register(new NotAuthenticatedExceptionMapper(environment.metrics()));
}
示例13: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的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));
}
示例14: run
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
@Override
public void run(final TrackerServerConfiguration config,
final Environment environment) {
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, config.getDataSourceFactory(), "postgresql");
final UserDAO dao = jdbi.onDemand(UserDAO.class);
environment.jersey().register(new MainResource(config, dao));
}
示例15: DatabaseManager
import io.dropwizard.jdbi.DBIFactory; //导入方法依赖的package包/类
public DatabaseManager(DatabaseConfiguration databaseConfiguration, Environment environment, DBIFactory dbiFactory, Boolean isRunningOnCloudFoundry) throws IOException {
this.database = databaseConfiguration.getDatabase();
this.database.getProperties().put("ApplicationName", "openregister_java");
if (isRunningOnCloudFoundry) {
this.database.setUrl(getCloudFoundryDatabaseServiceJDBCUrl());
}
// dbiFactory.build() will ensure that this dataSource is correctly shut down
// it will also be shared with flyway
this.dataSource = database.build(environment.metrics(), "openregister_java");
this.dbi = dbiFactory.build(environment, database, dataSource, "openregister_java");
}