use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class IntXMLChangeLogSAXParserTest method sampleChangeLogs.
@Test
public void sampleChangeLogs() throws Exception {
new XMLChangeLogSAXParser().parse("changelogs/cache/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/db2/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/derby/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/firebird/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/h2/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/hsqldb/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/maxdb/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/mysql/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/oracle/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/pgsql/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/sybase/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/asany/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
new XMLChangeLogSAXParser().parse("changelogs/unsupported/complete/root.changelog.xml", new ChangeLogParameters(), new JUnitResourceAccessor());
}
use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class InternalDropAllCommandStep method parseChangeLogFile.
private DatabaseChangeLog parseChangeLogFile(String changeLogFile) throws LiquibaseException {
ResourceAccessor resourceAccessor = Scope.getCurrentScope().getResourceAccessor();
ChangeLogParser parser = ChangeLogParserFactory.getInstance().getParser(changeLogFile, resourceAccessor);
ChangeLogParameters changeLogParameters = new ChangeLogParameters();
return parser.parse(changeLogFile, changeLogParameters, resourceAccessor);
}
use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class CreateViewChange method generateStatements.
@Override
public SqlStatement[] generateStatements(Database database) {
List<SqlStatement> statements = new ArrayList<>();
boolean replaceIfExists = false;
if ((getReplaceIfExists() != null) && getReplaceIfExists()) {
replaceIfExists = true;
}
boolean fullDefinition = false;
if (this.fullDefinition != null) {
fullDefinition = this.fullDefinition;
}
String selectQuery;
String path = getPath();
if (path == null) {
selectQuery = StringUtil.trimToNull(getSelectQuery());
} else {
try {
InputStream stream = openSqlStream();
if (stream == null) {
throw new IOException(FileUtil.getFileNotFoundMessage(path));
}
selectQuery = StreamUtil.readStreamAsString(stream, encoding);
if (getChangeSet() != null) {
ChangeLogParameters parameters = getChangeSet().getChangeLogParameters();
if (parameters != null) {
selectQuery = parameters.expandExpressions(selectQuery, getChangeSet().getChangeLog());
}
}
} catch (IOException e) {
throw new UnexpectedLiquibaseException(e);
}
}
if (!supportsReplaceIfExistsOption(database) && replaceIfExists) {
statements.add(new DropViewStatement(getCatalogName(), getSchemaName(), getViewName()));
statements.add(createViewStatement(getCatalogName(), getSchemaName(), getViewName(), selectQuery, false).setFullDefinition(fullDefinition));
} else {
statements.add(createViewStatement(getCatalogName(), getSchemaName(), getViewName(), selectQuery, replaceIfExists).setFullDefinition(fullDefinition));
}
if ((database instanceof OracleDatabase) && (StringUtil.trimToNull(remarks) != null)) {
SetTableRemarksStatement remarksStatement = new SetTableRemarksStatement(catalogName, schemaName, viewName, remarks);
if (SqlGeneratorFactory.getInstance().supports(remarksStatement, database)) {
statements.add(remarksStatement);
}
}
return statements.toArray(new SqlStatement[statements.size()]);
}
use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class CreateProcedureChange method generateStatements.
@Override
public SqlStatement[] generateStatements(Database database) {
String endDelimiter = ";";
if (database instanceof OracleDatabase) {
endDelimiter = "\n/";
} else if (database instanceof AbstractDb2Database) {
endDelimiter = "";
}
String procedureText;
String path = getPath();
if (path == null) {
procedureText = StringUtil.trimToNull(getProcedureText());
} else {
if (getChangeSet() == null) {
// only try to read a file when inside a changest. Not when analyizing supported
procedureText = "NO CHANGESET";
} else {
try {
InputStream stream = openSqlStream();
if (stream == null) {
throw new IOException(FileUtil.getFileNotFoundMessage(path));
}
procedureText = StreamUtil.readStreamAsString(stream, encoding);
if (getChangeSet() != null) {
ChangeLogParameters parameters = getChangeSet().getChangeLogParameters();
if (parameters != null) {
procedureText = parameters.expandExpressions(procedureText, getChangeSet().getChangeLog());
}
}
} catch (IOException e) {
throw new UnexpectedLiquibaseException(e);
}
}
}
return generateStatements(procedureText, endDelimiter, database);
}
use of liquibase.changelog.ChangeLogParameters 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");
}
Aggregations