use of org.flywaydb.core.internal.dbsupport.JdbcTemplate in project flyway by flyway.
the class FlywayMediumTest method callback.
@Test
public void callback() throws Exception {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_callback;DB_CLOSE_DELAY=-1", "sa", "", null, "SET AUTOCOMMIT OFF");
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setSqlMigrationPrefix("");
flyway.setLocations("migration/callback");
flyway.migrate();
assertEquals("1", flyway.info().current().getVersion().toString());
assertEquals(MigrationState.SUCCESS, flyway.info().current().getState());
assertEquals("Mr Callback", new JdbcTemplate(dataSource.getConnection(), 0).queryForString("SELECT name FROM test_user"));
}
use of org.flywaydb.core.internal.dbsupport.JdbcTemplate in project flyway by flyway.
the class FlywayMediumTest method baselineAfterInit.
@Test
public void baselineAfterInit() throws Exception {
DriverDataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_baseline_init;DB_CLOSE_DELAY=-1", "sa", "", null);
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setSchemas("new1");
flyway.setLocations("migration/validate");
flyway.baseline();
new JdbcTemplate(dataSource.getConnection(), 0).executeStatement("UPDATE \"new1\".\"schema_version\" SET \"type\"='BASELINE' WHERE \"type\"='BASELINE'");
assertEquals("1", flyway.info().current().getVersion().toString());
assertEquals(MigrationType.BASELINE, flyway.info().current().getType());
flyway.baseline();
assertEquals("1", flyway.info().current().getVersion().toString());
assertEquals(MigrationType.BASELINE, flyway.info().current().getType());
}
use of org.flywaydb.core.internal.dbsupport.JdbcTemplate in project flyway by flyway.
the class SqlScriptFlywayCallback method execute.
private void execute(String key, Connection connection) {
SqlScript sqlScript = scripts.get(key);
if (sqlScript != null) {
LOG.info("Executing SQL callback: " + key);
sqlScript.execute(new JdbcTemplate(connection, 0));
}
}
use of org.flywaydb.core.internal.dbsupport.JdbcTemplate in project flyway by flyway.
the class ConcurrentMigrationTestCase method migrateConcurrently.
@Test
public void migrateConcurrently() throws Exception {
Runnable runnable = new Runnable() {
public void run() {
try {
createFlyway().migrate();
} catch (Exception e) {
LOG.error("Migrate failed", e);
error = e.getMessage();
}
}
};
Thread[] threads = new Thread[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; i++) {
threads[i] = new Thread(runnable);
}
for (int i = 0; i < NUM_THREADS; i++) {
threads[i].start();
}
for (int i = 0; i < NUM_THREADS; i++) {
threads[i].join();
}
assertNull(error, error);
final MigrationInfo[] applied = flyway.info().applied();
int expected = 4;
if (applied[0].getType() == MigrationType.SCHEMA) {
expected++;
}
if (needsBaseline()) {
expected++;
}
assertEquals(expected, applied.length);
assertEquals("2.0", flyway.info().current().getVersion().toString());
assertEquals(0, flyway.migrate());
Connection connection = null;
try {
connection = concurrentMigrationDataSource.getConnection();
assertEquals(2, new JdbcTemplate(connection, 0).queryForInt("SELECT COUNT(*) FROM " + schemaQuoted + ".test_user"));
} finally {
JdbcUtils.closeConnection(connection);
}
}
use of org.flywaydb.core.internal.dbsupport.JdbcTemplate in project flyway by flyway.
the class MySQLMigrationTestCase method lockOnConnectionReUse.
/**
* Tests whether locking problems occur when Flyway's DB connection gets reused.
*/
@Test
public void lockOnConnectionReUse() throws SQLException {
DataSource twoConnectionsDataSource = new TwoConnectionsDataSource(flyway.getDataSource());
flyway.setDataSource(twoConnectionsDataSource);
flyway.setLocations(getBasedir());
flyway.migrate();
Connection connection1 = twoConnectionsDataSource.getConnection();
Connection connection2 = twoConnectionsDataSource.getConnection();
assertEquals(2, new JdbcTemplate(connection1, 0).queryForInt("SELECT COUNT(*) FROM test_user"));
assertEquals(2, new JdbcTemplate(connection2, 0).queryForInt("SELECT COUNT(*) FROM test_user"));
}
Aggregations