For IntelliJ IDEA,
Android Studio or Eclipse



@Provides @Singleton // Note: we need to inject the pooled DataSource here, not the (direct) one from EmbeddedDB protected GlobalLocker provideGlobalLocker(final DataSource dataSource, final EmbeddedDB embeddedDB) throws IOException { if (EmbeddedDB.DBEngine.MYSQL.equals(embeddedDB.getDBEngine())) { return new MySqlGlobalLocker(dataSource); } else if (EmbeddedDB.DBEngine.POSTGRESQL.equals(embeddedDB.getDBEngine())) { return new PostgreSQLGlobalLocker(dataSource); } else { return new MemoryGlobalLocker(); } }
@BeforeClass(groups = "slow") public void beforeClass() throws Exception { final Injector g = Guice.createInjector(Stage.PRODUCTION, new TestUtilModuleWithEmbeddedDB(configSource)); g.injectMembers(this); if (DBEngine.MYSQL.equals(helper.getDBEngine())) { Assert.assertTrue(locker instanceof MySqlGlobalLocker); } else if (DBEngine.POSTGRESQL.equals(helper.getDBEngine())) { Assert.assertTrue(locker instanceof PostgreSQLGlobalLocker); } else { Assert.assertTrue(locker instanceof MemoryGlobalLocker); } Assert.assertTrue(locker.isFree("a", "b")); }
protected void executePostStartupScripts(final String resourcesBase) throws IOException { try { final String databaseSpecificDDL = streamToString(Resources.getResource(resourcesBase + "/" + "ddl-" + instance.getDBEngine().name().toLowerCase() + ".sql").openStream()); instance.executeScript(databaseSpecificDDL); } catch (final IllegalArgumentException e) { // No engine-specific DDL } final String ddl = streamToString(Resources.getResource(resourcesBase + "/ddl.sql").openStream()); instance.executeScript(ddl); }
protected synchronized void executeEngineSpecificScripts() throws IOException, SQLException { switch (instance.getDBEngine()) { case POSTGRESQL: final int port = URI.create(instance.getJdbcConnectionString().substring(5)).getPort(); final GenericStandaloneDB postgreSQLDBConnection = new PostgreSQLStandaloneDB(instance.getDatabaseName(), "postgres", "postgres", "jdbc:postgresql://localhost:" + port + "/postgres"); postgreSQLDBConnection.initialize(); postgreSQLDBConnection.start(); try { // Setup permissions required by the PostgreSQL-specific DDL postgreSQLDBConnection.executeScript("alter role " + instance.getUsername() + " with superuser;"); } finally { postgreSQLDBConnection.stop(); } break; default: break; } }
embeddedDB.start(); if (embeddedDB.getDBEngine() == EmbeddedDB.DBEngine.POSTGRESQL) { embeddedDB.executeScript("CREATE DOMAIN datetime AS timestamp without time zone;" + "CREATE OR REPLACE FUNCTION last_insert_id() RETURNS BIGINT AS $$\n" +
protected DataSource createHikariDataSource() throws IOException { switch(getDBEngine()) { case MYSQL: dataSourceClassName = "org.mariadb.jdbc.MySQLDataSource";
protected synchronized void executePostStartupScripts() throws IOException { final String databaseSpecificDDL = "org/killbill/billing/util/" + "ddl-" + instance.getDBEngine().name().toLowerCase() + ".sql"; installDDLSilently(databaseSpecificDDL);
@Provides @Singleton // Note: we need to inject the pooled DataSource here, not the (direct) one from EmbeddedDB protected GlobalLocker provideGlobalLocker(final DataSource dataSource, final EmbeddedDB embeddedDB) throws IOException { if (EmbeddedDB.DBEngine.MYSQL.equals(embeddedDB.getDBEngine())) { return new MySqlGlobalLocker(dataSource); } else if (EmbeddedDB.DBEngine.POSTGRESQL.equals(embeddedDB.getDBEngine())) { return new PostgreSQLGlobalLocker(dataSource); } else { return new MemoryGlobalLocker(); } }
@Provides @Singleton // Note: we need to inject the pooled DataSource here, not the (direct) one from EmbeddedDB protected GlobalLocker provideGlobalLocker(final DataSource dataSource, final EmbeddedDB embeddedDB) throws IOException { if (EmbeddedDB.DBEngine.MYSQL.equals(embeddedDB.getDBEngine())) { return new MySqlGlobalLocker(dataSource); } else if (EmbeddedDB.DBEngine.POSTGRESQL.equals(embeddedDB.getDBEngine())) { return new PostgreSQLGlobalLocker(dataSource); } else { return new MemoryGlobalLocker(); } }
protected DataSource createHikariDataSource() throws IOException { switch(getDBEngine()) { case MYSQL: dataSourceClassName = "org.mariadb.jdbc.MySQLDataSource";
embeddedDB.start(); if (embeddedDB.getDBEngine() == EmbeddedDB.DBEngine.POSTGRESQL) { embeddedDB.executeScript("CREATE DOMAIN datetime AS timestamp without time zone;" + "CREATE OR REPLACE FUNCTION last_insert_id() RETURNS BIGINT AS $$\n" +
embeddedDB.start(); if (embeddedDB.getDBEngine() == EmbeddedDB.DBEngine.POSTGRESQL) { embeddedDB.executeScript("CREATE DOMAIN datetime AS timestamp without time zone;" + "CREATE OR REPLACE FUNCTION last_insert_id() RETURNS BIGINT AS $$\n" +