Search in sources :

Example 6 with ChangeLogParameters

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());
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) JUnitResourceAccessor(liquibase.test.JUnitResourceAccessor) XMLChangeLogSAXParser(liquibase.parser.core.xml.XMLChangeLogSAXParser) Test(org.junit.Test)

Example 7 with ChangeLogParameters

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);
}
Also used : ResourceAccessor(liquibase.resource.ResourceAccessor) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) ChangeLogParser(liquibase.parser.ChangeLogParser)

Example 8 with ChangeLogParameters

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()]);
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) SqlStatement(liquibase.statement.SqlStatement) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) SetTableRemarksStatement(liquibase.statement.core.SetTableRemarksStatement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DropViewStatement(liquibase.statement.core.DropViewStatement) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 9 with ChangeLogParameters

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) IOException(java.io.IOException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 10 with ChangeLogParameters

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");
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ArrayList(java.util.ArrayList) ChangeLogSerializer(liquibase.serializer.ChangeLogSerializer) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) ChangeLogParser(liquibase.parser.ChangeLogParser) FileOutputStream(java.io.FileOutputStream) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) File(java.io.File)

Aggregations

ChangeLogParameters (liquibase.changelog.ChangeLogParameters)19 Database (liquibase.database.Database)7 LiquibaseException (liquibase.exception.LiquibaseException)7 ResourceAccessor (liquibase.resource.ResourceAccessor)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)5 ChangeLogParser (liquibase.parser.ChangeLogParser)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InputStream (java.io.InputStream)3 ChangeSet (liquibase.changelog.ChangeSet)3 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)3 XMLChangeLogSAXParser (liquibase.parser.core.xml.XMLChangeLogSAXParser)3 CompositeResourceAccessor (liquibase.resource.CompositeResourceAccessor)3 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2