Java Code Examples for io.dropwizard.jdbi.DBIFactory#build()
The following examples show how to use
io.dropwizard.jdbi.DBIFactory#build() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJdbiDynamicAttributes.java From soabase with Apache License 2.0 | 6 votes |
@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(); }
Example 2
Source File: ReaperApplication.java From cassandra-reaper with Apache License 2.0 | 5 votes |
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(context.reaperInstanceId, config, environment); } else if ("postgres".equalsIgnoreCase(config.getStorageType()) || "h2".equalsIgnoreCase(config.getStorageType()) || "database".equalsIgnoreCase(config.getStorageType())) { // create DBI instance final DBIFactory factory = new DBIFactory(); if (StringUtils.isEmpty(config.getDataSourceFactory().getDriverClass()) && "postgres".equalsIgnoreCase(config.getStorageType())) { config.getDataSourceFactory().setDriverClass("org.postgresql.Driver"); } else if (StringUtils.isEmpty(config.getDataSourceFactory().getDriverClass()) && "h2".equalsIgnoreCase(config.getStorageType())) { config.getDataSourceFactory().setDriverClass("org.h2.Driver"); } // instantiate store storage = new PostgresStorage( context.reaperInstanceId, 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; }
Example 3
Source File: AirpalModule.java From airpal with Apache License 2.0 | 5 votes |
@Singleton @Provides public DBI provideDBI(ObjectMapper objectMapper) throws ClassNotFoundException { final DBIFactory factory = new DBIFactory(); final DBI dbi = factory.build(environment, config.getDataSourceFactory(), provideDbType().name()); dbi.registerMapper(new TableRow.TableRowMapper(objectMapper)); dbi.registerMapper(new QueryStoreMapper(objectMapper)); dbi.registerArgumentFactory(new UUIDArgumentFactory()); dbi.registerArgumentFactory(new URIArgumentFactory()); return dbi; }
Example 4
Source File: NiPingMonitorApplication.java From SAPNetworkMonitor with GNU General Public License v3.0 | 4 votes |
@Override public void run(ServerConfiguration configuration, Environment environment) throws Exception { final DBIFactory factory = new DBIFactory(); final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "sapData"); ObjectMapper objectMapper = environment.getObjectMapper(); SapConfiguration sapConfiguration = configuration.getSapConfig(); JobConfiguration jobConfiguration = configuration.getJobConfig(); NiPingServiceBinder niPingServiceBinder = new NiPingServiceBinder(jdbi, objectMapper, sapConfiguration, jobConfiguration); ServiceLocator serviceLocator = ServiceLocatorUtilities.bind(niPingServiceBinder); SapBasicAuthenticator sapBasicAuthenticator = ServiceLocatorUtilities.getService(serviceLocator, SapBasicAuthenticator.class .getName()); SapOAuthenticator sapOAuthenticator = ServiceLocatorUtilities.getService(serviceLocator, SapOAuthenticator.class.getName()); final BasicCredentialAuthFilter basicAuthFilter = new BasicCredentialAuthFilter.Builder<BasicAuthUser>() .setAuthenticator(sapBasicAuthenticator) .buildAuthFilter(); final AuthFilter oAuthFilter = new OAuthCredentialAuthFilter.Builder<OAuthUser>() .setAuthenticator(sapOAuthenticator) .setPrefix("Bearer") .buildAuthFilter(); final PolymorphicAuthDynamicFeature feature = new PolymorphicAuthDynamicFeature<UserPrincipal>(ImmutableMap.of(BasicAuthUser .class, basicAuthFilter, OAuthUser.class, oAuthFilter)); final AbstractBinder binder = new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(BasicAuthUser.class, OAuthUser .class)); environment.jersey().register(new AuthFilterDynamicBinding()); environment.jersey().register(feature); environment.jersey().register(binder); environment.jersey().register(niPingServiceBinder); environment.jersey().packages("com.cloudwise.sap.niping.auth"); environment.jersey().packages("com.cloudwise.sap.niping.service"); environment.jersey().packages("com.cloudwise.sap.niping.dao"); environment.jersey().packages("com.cloudwise.sap.niping.common.vo.converter"); environment.jersey().packages("com.cloudwise.sap.niping.resource"); environment.jersey().register(SessionFactoryProvider.class); environment.servlets().setSessionHandler(new SessionHandler()); }
Example 5
Source File: RufusApplication.java From rufus with MIT License | 4 votes |
@Override public void run(RufusConfiguration conf, Environment env) throws Exception { final DBIFactory factory = new DBIFactory(); final DBI jdbi = factory.build(env, conf.getDataSourceFactory(), DB_SOURCE); final UserDao userDao = jdbi.onDemand(UserDao.class); final ArticleDao articleDao = jdbi.onDemand(ArticleDao.class); final FeedProcessorImpl processor = FeedProcessorImpl.newInstance(articleDao); final FeedParser parser = new FeedParser(articleDao, processor); final JwtConsumer jwtConsumer = new JwtConsumerBuilder() .setAllowedClockSkewInSeconds(30) .setRequireExpirationTime() .setRequireSubject() .setVerificationKey(new HmacKey(VERIFICATION_KEY)) .setRelaxVerificationKeyValidation() .build(); final CachingJwtAuthenticator<User> cachingJwtAuthenticator = new CachingJwtAuthenticator<>( env.metrics(), new JwtAuthenticator(userDao), conf.getAuthenticationCachePolicy() ); env.jersey().register(new ArticleResource(userDao, articleDao, processor, parser)); env.jersey().register( new UserResource( new BasicAuthenticator(userDao), new TokenGenerator(VERIFICATION_KEY), userDao, articleDao ) ); //route source env.jersey().setUrlPattern(ROOT_PATH); env.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class)); env.jersey().register(new AuthDynamicFeature( new JwtAuthFilter.Builder<User>() .setJwtConsumer(jwtConsumer) .setRealm(REALM) .setPrefix(BEARER) .setAuthenticator(cachingJwtAuthenticator) .buildAuthFilter() )); }