Search in sources :

Example 16 with ChangeLogParameters

use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.

the class RegisterChangelogCommandStep 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 17 with ChangeLogParameters

use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.

the class SQLFileChange method getSql.

@Override
@DatabaseChangeProperty(isChangeProperty = false)
public String getSql() {
    String sql = super.getSql();
    if (sql == null) {
        InputStream sqlStream;
        try {
            sqlStream = openSqlStream();
            if (sqlStream == null) {
                return null;
            }
            String content = StreamUtil.readStreamAsString(sqlStream, getEncoding());
            if (getChangeSet() != null) {
                ChangeLogParameters parameters = getChangeSet().getChangeLogParameters();
                if (parameters != null) {
                    content = parameters.expandExpressions(content, getChangeSet().getChangeLog());
                }
            }
            return content;
        } catch (IOException e) {
            throw new UnexpectedLiquibaseException(e);
        }
    } else {
        return sql;
    }
}
Also used : InputStream(java.io.InputStream) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) IOException(java.io.IOException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) DatabaseChangeProperty(liquibase.change.DatabaseChangeProperty)

Example 18 with ChangeLogParameters

use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.

the class LiquibaseRollbackOneUpdateSQL method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    // 
    // Check the Pro license
    // 
    boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
    if (!hasProLicense) {
        throw new LiquibaseException("The 'rollbackOneUpdateSQL' command requires a valid Liquibase Pro license. Get a free Pro license key at https://liquibase.com/protrial and add liquibase.pro.licenseKey=<yourKey> into your defaults file or use --pro-license-key=<yourKey> before your command in the CLI.");
    }
    Database database = liquibase.getDatabase();
    CommandScope liquibaseCommand = new CommandScope("internalRollbackOneUpdateSQL");
    Map<String, Object> argsMap = getCommandArgsObjectMap(liquibase);
    Writer outputWriter = null;
    try {
        outputWriter = createOutputWriter();
        argsMap.put("outputWriter", outputWriter);
    } catch (IOException ioe) {
        throw new LiquibaseException("Error executing rollbackOneChangeSetSQL.  Unable to create output writer.", ioe);
    }
    ChangeLogParameters clp = new ChangeLogParameters(database);
    argsMap.put("changeLogParameters", clp);
    if (force != null && !Boolean.parseBoolean(force)) {
        throw new LiquibaseException("Invalid value for --force.  You must specify 'liquibase.force=true' to use rollbackOneUpdateSQL.");
    }
    argsMap.put("force", Boolean.TRUE);
    argsMap.put("liquibase", liquibase);
    for (Map.Entry<String, Object> entry : argsMap.entrySet()) {
        liquibaseCommand.addArgumentValue(entry.getKey(), entry.getValue());
    }
    liquibaseCommand.execute();
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) CommandScope(liquibase.command.CommandScope) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with ChangeLogParameters

use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.

the class LiquibaseRollbackOneChangeSetMojo method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    // 
    // Call the base class method so that
    // Hub settings will be made
    // 
    super.performLiquibaseTask(liquibase);
    // 
    // Check the Pro license
    // 
    boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
    if (!hasProLicense) {
        throw new LiquibaseException("The command 'rollbackOneChangeSet' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com." + "Add liquibase.pro.licenseKey as a Maven property or add liquibase.pro.licenseKey=<yourKey> into your defaults file.");
    }
    Database database = liquibase.getDatabase();
    CommandScope liquibaseCommand = new CommandScope("internalRollbackOneChangeSet");
    Map<String, Object> argsMap = getCommandArgsObjectMap(liquibase);
    ChangeLogParameters clp = new ChangeLogParameters(database);
    argsMap.put("changeLogParameters", clp);
    if (force == null || (force != null && !Boolean.parseBoolean(force))) {
        throw new LiquibaseException("Invalid value for --force.  You must specify 'liquibase.force=true' to use rollbackOneChangeSet.");
    }
    argsMap.put("force", Boolean.TRUE);
    argsMap.put("liquibase", liquibase);
    argsMap.put("liquibaseProLicenseKey", liquibaseProLicenseKey);
    for (Map.Entry<String, Object> entry : argsMap.entrySet()) {
        liquibaseCommand.addArgumentValue(entry.getKey(), entry.getValue());
    }
    liquibaseCommand.execute();
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) Map(java.util.Map) HashMap(java.util.HashMap)

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