use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.
the class MetaDataTableImpl method upgradeIfNecessary.
@Override
public boolean upgradeIfNecessary() {
if (table.exists() && table.hasColumn("version_rank")) {
new TransactionTemplate(jdbcTemplate.getConnection()).execute(new Callable<Object>() {
@Override
public Void call() {
lock(new Callable<Object>() {
@Override
public Object call() throws Exception {
LOG.info("Upgrading metadata table " + table + " to the Flyway 4.0 format ...");
String resourceName = "org/flywaydb/core/internal/dbsupport/" + dbSupport.getDbName() + "/upgradeMetaDataTable.sql";
String source = new ClassPathResource(resourceName, getClass().getClassLoader()).loadAsString("UTF-8");
Map<String, String> placeholders = new HashMap<String, String>();
placeholders.put("schema", table.getSchema().getName());
placeholders.put("table", table.getName());
String sourceNoPlaceholders = new PlaceholderReplacer(placeholders, "${", "}").replacePlaceholders(source);
SqlScript sqlScript = new SqlScript(sourceNoPlaceholders, dbSupport);
sqlScript.execute(jdbcTemplate);
return null;
}
});
return null;
}
});
return true;
}
return false;
}
use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.
the class FlywayMediumTest method setUp.
@BeforeClass
public static void setUp() throws IOException {
oldClassLoader = getClassLoader();
String jar = new ClassPathResource("no-directory-entries.jar", getClassLoader()).getLocationOnDisk();
assertTrue(new File(jar).isFile());
ClassUtils.addJarOrDirectoryToClasspath(jar);
}
use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.
the class EnterpriseDBSqlScriptSmallTest method parseSqlStatements.
@Test
public void parseSqlStatements() throws Exception {
String source = new ClassPathResource("migration/dbsupport/enterprisedb/sql/placeholders/V1__Placeholders.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
assertEquals(3, sqlStatements.size());
assertEquals(18, sqlStatements.get(0).getLineNumber());
assertEquals(27, sqlStatements.get(1).getLineNumber());
assertEquals(32, sqlStatements.get(2).getLineNumber());
assertEquals("COMMIT", sqlStatements.get(2).getSql());
}
use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.
the class EnterpriseDBSqlScriptSmallTest method parseSqlStatementsWithInlineCommentsInsidePlSqlBlocks.
@Test
public void parseSqlStatementsWithInlineCommentsInsidePlSqlBlocks() throws Exception {
String source = new ClassPathResource("migration/dbsupport/enterprisedb/sql/function/V2__FunctionWithConditionals.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
assertEquals(1, sqlStatements.size());
assertEquals(18, sqlStatements.get(0).getLineNumber());
assertTrue(sqlStatements.get(0).getSql().contains("/* for the rich */"));
}
use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.
the class EnterpriseDBSqlScriptSmallTest method parseFunctionsAndProcedures.
@Test
public void parseFunctionsAndProcedures() throws Exception {
String source = new ClassPathResource("migration/dbsupport/enterprisedb/sql/function/V1__Function.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
assertEquals(5, sqlStatements.size());
assertEquals(18, sqlStatements.get(0).getLineNumber());
assertEquals(33, sqlStatements.get(1).getLineNumber());
assertEquals(41, sqlStatements.get(2).getLineNumber());
assertEquals(43, sqlStatements.get(3).getLineNumber());
assertEquals(51, sqlStatements.get(4).getLineNumber());
assertEquals("COMMIT", sqlStatements.get(4).getSql());
}
Aggregations