use of liquibase.resource.ClassLoaderResourceAccessor in project liquibase by liquibase.
the class XMLChangeLogSerializerTest method createNode_SQLFileChange.
@Test
public void createNode_SQLFileChange() throws Exception {
String fileName = "liquibase/change/core/SQLFileTestData.sql";
SQLFileChange change = new SQLFileChange();
ClassLoaderResourceAccessor opener = new ClassLoaderResourceAccessor();
change.setPath(fileName);
Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change);
assertEquals("sqlFile", element.getTagName());
assertEquals(fileName, element.getAttribute("path"));
}
use of liquibase.resource.ClassLoaderResourceAccessor in project liquibase by liquibase.
the class ConvertCommandStep method run.
@Override
public void run(CommandResultsBuilder resultsBuilder) throws Exception {
CommandScope commandScope = resultsBuilder.getCommandScope();
String src = commandScope.getArgumentValue(SRC_ARG);
String out = commandScope.getArgumentValue(OUT_ARG);
String classpath = commandScope.getArgumentValue(CLASSPATH_ARG);
List<ResourceAccessor> openers = new ArrayList<>();
openers.add(new FileSystemResourceAccessor());
openers.add(new ClassLoaderResourceAccessor());
if (classpath != null) {
openers.add(new FileSystemResourceAccessor(new File(classpath)));
}
ResourceAccessor resourceAccessor = new CompositeResourceAccessor(openers);
ChangeLogParser sourceParser = ChangeLogParserFactory.getInstance().getParser(src, resourceAccessor);
ChangeLogSerializer outSerializer = ChangeLogSerializerFactory.getInstance().getSerializer(out);
DatabaseChangeLog changeLog = sourceParser.parse(src, new ChangeLogParameters(), resourceAccessor);
File outFile = new File(out);
if (!outFile.exists()) {
outFile.getParentFile().mkdirs();
}
try (FileOutputStream outputStream = new FileOutputStream(outFile)) {
outSerializer.write(changeLog.getChangeSets(), outputStream);
}
Scope.getCurrentScope().getUI().sendMessage("Converted successfully");
}
use of liquibase.resource.ClassLoaderResourceAccessor in project liquibase by liquibase.
the class OfflineChangeLogHistoryServiceTest method createService.
/**
* Create OfflineChangeLogHistoryService and register LoggingExecutor
*/
private OfflineChangeLogHistoryService createService(Writer writer, String outputLiquibaseSql) {
HsqlDatabase database = new HsqlDatabase();
File changeLogCsvFile = new File(temporaryFolder.getRoot(), CHANGE_LOG_CSV);
OfflineConnection connection = new OfflineConnection("offline:hsqldb?changeLogFile=" + changeLogCsvFile.getAbsolutePath() + "&outputLiquibaseSql=" + outputLiquibaseSql, new ClassLoaderResourceAccessor());
database.setConnection(connection);
connection.attached(database);
OfflineChangeLogHistoryService changeLogHistoryService = (OfflineChangeLogHistoryService) ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database);
//
// Create the new LoggingExecutor and give it the original Executor as a delegator
// We also set the LoggingExecutor as the JDBC Executor
//
LoggingExecutor loggingExecutor = new LoggingExecutor(Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database), writer, database);
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("logging", database, loggingExecutor);
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, loggingExecutor);
return changeLogHistoryService;
}
use of liquibase.resource.ClassLoaderResourceAccessor in project gocd by gocd.
the class DatabaseMigrator method migrate.
public void migrate(Connection connection) throws SQLException {
try {
log.info("Upgrading database, this might take a while depending on the size of the database.");
List<String> messages = Arrays.asList(repeat("*", "", 72), "WARNING: Shutting down your server at this point will lead to a database corruption. Please wait until the database upgrade completes.", repeat("*", "", 72));
for (String message : messages) {
System.err.println(message);
log.info(message);
}
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Liquibase liquibase = new Liquibase("db-migration-scripts/liquibase.xml", new ClassLoaderResourceAccessor(getClass().getClassLoader()), database);
liquibase.update(new Contexts());
System.err.println("INFO: Database upgrade completed successfully.");
log.info("Database upgrade completed successfully.");
DataMigrationRunner.run(connection);
} catch (LiquibaseException e) {
String message = "Unable to create database upgrade script for database. The problem was: " + e.getMessage();
if (e.getCause() != null) {
message += ". The cause was: " + e.getCause().getMessage();
}
log.error(message, e);
System.err.println(message);
e.printStackTrace(System.err);
throw new SQLException("Unable to migrate the database", e);
}
}
use of liquibase.resource.ClassLoaderResourceAccessor in project liquibase by liquibase.
the class ServiceLocatorTest method setup.
@Before
public void setup() throws Exception {
CompositeResourceAccessor resourceAccessor = new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), TestContext.getInstance().getTestResourceAccessor());
serviceLocator = ServiceLocator.getInstance();
serviceLocator.setResourceAccessor(resourceAccessor);
}
Aggregations