io.dropwizard.db.PooledDataSourceFactory Java Examples
The following examples show how to use
io.dropwizard.db.PooledDataSourceFactory.
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: AbstractFlywayCommand.java From dropwizard-flyway with Apache License 2.0 | 6 votes |
@Override protected void run(final Bootstrap<T> bootstrap, final Namespace namespace, final T configuration) throws Exception { final PooledDataSourceFactory datasourceFactory = databaseConfiguration.getDataSourceFactory(configuration); final FlywayFactory flywayFactory = flywayConfiguration.getFlywayFactory(configuration); // Give subclasses an option to set additional config flags for flyway. setAdditionalOptions(flywayFactory, namespace); final Flyway flyway = flywayFactory.build(datasourceFactory.build(bootstrap.getMetricRegistry(), "Flyway")); try { run(namespace, flyway); } catch (FlywayException e) { LOG.error("Error while running database command", e); throw e; } }
Example #2
Source File: AbstractCommandTest.java From dropwizard-flyway with Apache License 2.0 | 6 votes |
@BeforeEach public void setUp() throws Exception { // Setup necessary mock final JarLocation location = mock(JarLocation.class); when(location.getVersion()).thenReturn(Optional.of("1.0.0")); final DatabaseConfiguration dbConfiguration = mock(DatabaseConfiguration.class); when(dbConfiguration.getDataSourceFactory(any())).thenReturn(mock(PooledDataSourceFactory.class)); final FlywayConfiguration flywayConfiguration = mock(FlywayConfiguration.class); mockFlywayFactory = mock(FlywayFactory.class); when(flywayConfiguration.getFlywayFactory(any())).thenReturn(mockFlywayFactory); mockFlyway = mock(Flyway.class); when(mockFlywayFactory.build(any())).thenReturn(mockFlyway); // Add commands you want to test final Bootstrap<TestConfiguration> bootstrap = new Bootstrap<>(new TestApplication()); bootstrap.addCommand(new DbCommand<TestConfiguration>("db", dbConfiguration, flywayConfiguration, TestConfiguration.class)); // Build what'll run the command and interpret arguments cli = new Cli(location, bootstrap, System.out, System.err); }
Example #3
Source File: DBIFactory.java From dropwizard-java8 with Apache License 2.0 | 6 votes |
@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; }
Example #4
Source File: JooqBundle.java From droptools with Apache License 2.0 | 6 votes |
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); if (dataSourceFactory.getValidationQuery().isPresent()) { final JooqHealthCheck healthCheck = new JooqHealthCheck( cfg, dataSourceFactory.getValidationQuery().get()); environment.healthChecks().register(name, healthCheck); } jooqFactoryConfigurationMap.put(name, cfg); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
Example #5
Source File: JooqFactory.java From droptools with Apache License 2.0 | 5 votes |
public Configuration build(Environment environment, PooledDataSourceFactory factory, String name) throws ClassNotFoundException { final Settings settings = buildSettings(); final ManagedDataSource dataSource = factory.build(environment.metrics(), name); final SQLDialect dialect = determineDialect(factory, dataSource); final ConnectionProvider connectionProvider = new DataSourceConnectionProvider(dataSource); final Configuration config = new DefaultConfiguration() .set(settings) .set(dialect) .set(connectionProvider); environment.lifecycle().manage(dataSource); return config; }
Example #6
Source File: JooqFactory.java From droptools with Apache License 2.0 | 5 votes |
private SQLDialect determineDialect(PooledDataSourceFactory dataSourceFactory, ManagedDataSource dataSource) { // If a dialect was specified, great! if (getDialect().isPresent()) { return dialect.get(); } return JDBCUtils.dialect(dataSourceFactory.getUrl()); }
Example #7
Source File: JophielHibernateBundle.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public PooledDataSourceFactory getDataSourceFactory(JophielApplicationConfiguration config) { return config.getDatabaseConfig(); }
Example #8
Source File: JophielMigrationsBundle.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public PooledDataSourceFactory getDataSourceFactory(JophielApplicationConfiguration config) { return config.getDatabaseConfig(); }
Example #9
Source File: JerahmeelHibernateBundle.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public PooledDataSourceFactory getDataSourceFactory(JerahmeelApplicationConfiguration config) { return config.getDatabaseConfig(); }
Example #10
Source File: JerahmeelMigrationsBundle.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public PooledDataSourceFactory getDataSourceFactory(JerahmeelApplicationConfiguration config) { return config.getDatabaseConfig(); }
Example #11
Source File: UrielHibernateBundle.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public PooledDataSourceFactory getDataSourceFactory(UrielApplicationConfiguration config) { return config.getDatabaseConfig(); }
Example #12
Source File: UrielMigrationsBundle.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public PooledDataSourceFactory getDataSourceFactory(UrielApplicationConfiguration config) { return config.getDatabaseConfig(); }
Example #13
Source File: RobeHibernateBundle.java From robe with GNU Lesser General Public License v3.0 | 4 votes |
@Override public PooledDataSourceFactory getDataSourceFactory(T configuration) { return configuration.getHibernate().getDataSourceFactory(configuration); }
Example #14
Source File: RobeHibernateBundleTest.java From robe with GNU Lesser General Public License v3.0 | 4 votes |
@Test @Order(order = 8) public void getDatasourceFactory() { PooledDataSourceFactory dataSourceFactory = RobeHibernateBundle.getInstance().getDataSourceFactory(new TestConfig()); Assert.assertNotNull(dataSourceFactory); }