Java Code Examples for io.dropwizard.db.DataSourceFactory#setUrl()
The following examples show how to use
io.dropwizard.db.DataSourceFactory#setUrl() .
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: DbDiffCommand.java From dropwizard-experiment with MIT License | 7 votes |
@Override protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception { // The existing database with migrations managed by Liquibase. DataSourceFactory outdatedDb = configuration.getDatabaseConfig(); try (CloseableLiquibase outdatedLiquibase = createLiquibase(outdatedDb)) { // A temporary database that starts out empty and then gets the autogenerated Ebean table definitions applied. DataSourceFactory freshDb = EbeanConfigUtils.clone(outdatedDb); String url = outdatedDb.getUrl(); freshDb.setUrl(url.substring(0, url.lastIndexOf("/")) + "/migrationdiff"); // Creating the Ebean server makes it apply its table definitions to the database immediately. ServerConfig serverConfig = EbeanConfigUtils.createServerConfig(freshDb); serverConfig.setDdlGenerate(true); serverConfig.setDdlRun(true); EbeanServer ebeanServer = EbeanServerFactory.create(serverConfig); try (CloseableLiquibase freshLiquibase = createLiquibase(freshDb)) { // Create and print the differences between the two databases, i.e. a migration that should be applied to update to the newest Ebean definitions. DiffResult diff = outdatedLiquibase.diff(freshLiquibase.getDatabase(), outdatedLiquibase.getDatabase(), CompareControl.STANDARD); DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diff, new DiffOutputControl(false, false, true)); diffToChangeLog.print(System.out); } } }
Example 2
Source File: ReaperApplicationConfigurationTest.java From cassandra-reaper with Apache License 2.0 | 6 votes |
@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); config.setBlacklistTwcsTables(true); }
Example 3
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 4
Source File: SQLIngester.java From macrobase with Apache License 2.0 | 6 votes |
private void initializeConnection() throws SQLException { if (connection == null) { DataSourceFactory factory = new DataSourceFactory(); factory.setDriverClass(getDriverClass()); factory.setUrl(String.format("%s//%s/%s", getJDBCUrlPrefix(), dbUrl, dbName)); factory.setProperties(getJDBCProperties()); if (dbUser != null) { factory.setUser(this.dbUser); } if (dbPassword != null) { factory.setPassword(dbPassword); } source = factory.build(MacroBase.metrics, dbName); this.connection = source.getConnection(); } }
Example 5
Source File: JDBIOptionalInstantTest.java From dropwizard-java8 with Apache License 2.0 | 6 votes |
@Before public void setupTests() throws IOException { final DataSourceFactory dataSourceFactory = new DataSourceFactory(); dataSourceFactory.setDriverClass("org.h2.Driver"); dataSourceFactory.setUrl("jdbc:h2:mem:date-time-optional-" + System.currentTimeMillis() + "?user=sa"); dataSourceFactory.setInitialSize(1); final DBI dbi = new DBIFactory().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); }
Example 6
Source File: JDBIOptionalLocalDateTimeTest.java From dropwizard-java8 with Apache License 2.0 | 6 votes |
@Before public void setupTests() throws IOException { final DataSourceFactory dataSourceFactory = new DataSourceFactory(); dataSourceFactory.setDriverClass("org.h2.Driver"); dataSourceFactory.setUrl("jdbc:h2:mem:date-time-optional-" + System.currentTimeMillis() + "?user=sa"); dataSourceFactory.setInitialSize(1); final DBI dbi = new DBIFactory().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); }
Example 7
Source File: JDBIOptionalLocalDateTest.java From dropwizard-java8 with Apache License 2.0 | 6 votes |
@Before public void setupTests() throws IOException { final DataSourceFactory dataSourceFactory = new DataSourceFactory(); dataSourceFactory.setDriverClass("org.h2.Driver"); dataSourceFactory.setUrl("jdbc:h2:mem:date-time-optional-" + System.currentTimeMillis() + "?user=sa"); dataSourceFactory.setInitialSize(1); final DBI dbi = new DBIFactory().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); }
Example 8
Source File: AbstractServiceIntegrationTests.java From judgels with GNU General Public License v2.0 | 5 votes |
@BeforeAll static void beforeAll() throws Exception { DataSourceFactory dbConfig = new DataSourceFactory(); dbConfig.setDriverClass(Driver.class.getName()); dbConfig.setUrl("jdbc:h2:mem:./" + JERAHMEEL_JDBC_SUFFIX); dbConfig.setProperties(ImmutableMap.<String, String>builder() .put(DIALECT, H2Dialect.class.getName()) .put(HBM2DDL_AUTO, "create") .put(GENERATE_STATISTICS, "false") .build()); baseDataDir = Files.createTempDirectory("jerahmeel"); JerahmeelApplicationConfiguration config = new JerahmeelApplicationConfiguration( dbConfig, WebSecurityConfiguration.DEFAULT, new JerahmeelConfiguration.Builder() .baseDataDir(baseDataDir.toString()) .jophielConfig(JophielClientConfiguration.DEFAULT) .sandalphonConfig(SandalphonClientConfiguration.DEFAULT) .gabrielConfig(GabrielClientConfiguration.DEFAULT) .submissionConfig(SubmissionConfiguration.DEFAULT) .build()); support = new DropwizardTestSupport<>(JerahmeelApplication.class, config); support.before(); }
Example 9
Source File: AbstractServiceIntegrationTests.java From judgels with GNU General Public License v2.0 | 5 votes |
@BeforeAll static void beforeAll() throws Exception { DataSourceFactory dbConfig = new DataSourceFactory(); dbConfig.setDriverClass(Driver.class.getName()); dbConfig.setUrl("jdbc:h2:mem:./" + URIEL_JDBC_SUFFIX); dbConfig.setProperties(ImmutableMap.<String, String>builder() .put(DIALECT, H2Dialect.class.getName()) .put(HBM2DDL_AUTO, "create") .put(GENERATE_STATISTICS, "false") .build()); baseDataDir = Files.createTempDirectory("uriel"); UrielApplicationConfiguration config = new UrielApplicationConfiguration( dbConfig, WebSecurityConfiguration.DEFAULT, new UrielConfiguration.Builder() .baseDataDir(baseDataDir.toString()) .jophielConfig(JophielClientConfiguration.DEFAULT) .sandalphonConfig(SandalphonClientConfiguration.DEFAULT) .sealtielConfig(SealtielClientConfiguration.DEFAULT) .gabrielConfig(GabrielClientConfiguration.DEFAULT) .submissionConfig(SubmissionConfiguration.DEFAULT) .fileConfig(FileConfiguration.DEFAULT) .build()); support = new DropwizardTestSupport<>(UrielApplication.class, config); support.before(); }
Example 10
Source File: SingularityTestModule.java From Singularity with Apache License 2.0 | 5 votes |
private DataSourceFactory getDataSourceFactory() { DataSourceFactory dataSourceFactory = new DataSourceFactory(); dataSourceFactory.setDriverClass("org.h2.Driver"); dataSourceFactory.setUrl("jdbc:h2:mem:singularity;DB_CLOSE_DELAY=-1"); dataSourceFactory.setUser("user"); dataSourceFactory.setPassword("password"); return dataSourceFactory; }
Example 11
Source File: EbeanConfigUtils.java From dropwizard-experiment with MIT License | 5 votes |
public static DataSourceFactory clone(DataSourceFactory dbConfig) { DataSourceFactory newConfig = new DataSourceFactory(); newConfig.setUser(dbConfig.getUser()); newConfig.setPassword(dbConfig.getPassword()); newConfig.setUrl(dbConfig.getUrl()); newConfig.setDriverClass(dbConfig.getDriverClass()); newConfig.setMaxSize(dbConfig.getMaxSize()); newConfig.setMinSize(dbConfig.getMinSize()); newConfig.setInitialSize(dbConfig.getInitialSize()); return newConfig; }
Example 12
Source File: AbstractServiceIntegrationTests.java From judgels with GNU General Public License v2.0 | 4 votes |
@BeforeAll static void beforeAll() throws Exception { DataSourceFactory dbConfig = new DataSourceFactory(); dbConfig.setDriverClass(Driver.class.getName()); dbConfig.setUrl("jdbc:h2:mem:./" + UUID.randomUUID().toString()); dbConfig.setProperties(ImmutableMap.<String, String>builder() .put(DIALECT, H2Dialect.class.getName()) .put(HBM2DDL_AUTO, "create") .put(GENERATE_STATISTICS, "false") .build()); baseDataDir = Files.createTempDirectory("jophiel"); JophielConfiguration jophielConfig = new JophielConfiguration.Builder() .baseDataDir(baseDataDir.toString()) .mailerConfig(new MailerConfiguration.Builder() .host("localhost") .port(2500) .useSsl(false) .username("wiser") .password("wiser") .sender("[email protected]") .build()) .userRegistrationConfig(UserRegistrationConfiguration.DEFAULT) .userResetPasswordConfig(UserResetPasswordConfiguration.DEFAULT) .userAvatarConfig(UserAvatarConfiguration.DEFAULT) .superadminCreatorConfig(SuperadminCreatorConfiguration.DEFAULT) .build(); JophielApplicationConfiguration config = new JophielApplicationConfiguration( dbConfig, WebSecurityConfiguration.DEFAULT, jophielConfig); support = new DropwizardTestSupport<>(JophielApplication.class, config); support.before(); adminHeader = AuthHeader.of(createService(SessionService.class) .logIn(Credentials.of("superadmin", "superadmin")) .getToken()); }