Search in sources :

Example 1 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class LiquibaseConfiguration method getConfiguration.

public ConfigurationContainer getConfiguration(String typeName) {
    for (Map.Entry<Class, ConfigurationContainer> entry : configurations.entrySet()) {
        if (entry.getKey().getName().equals(typeName)) {
            return entry.getValue();
        }
    }
    try {
        Class typeClass = Class.forName(typeName);
        configurations.put(typeClass, createConfiguration(typeClass));
        return configurations.get(typeClass);
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 2 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class LiquibaseConfiguration method createConfiguration.

protected <T extends ConfigurationContainer> T createConfiguration(Class<T> type) {
    try {
        T configuration = type.newInstance();
        configuration.init(configurationValueProviders);
        return configuration;
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException("Cannot create default configuration " + type.getName(), e);
    }
}
Also used : UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 3 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class H2Database method setConnection.

@Override
public void setConnection(DatabaseConnection conn) {
    Connection sqlConn = null;
    if (!(conn instanceof OfflineConnection)) {
        try {
            if (conn instanceof JdbcConnection) {
                Method wrappedConn = conn.getClass().getMethod("getWrappedConnection");
                wrappedConn.setAccessible(true);
                sqlConn = (Connection) wrappedConn.invoke(conn);
            }
        } catch (Exception e) {
            throw new UnexpectedLiquibaseException(e);
        }
        if (sqlConn != null) {
            Statement statement = null;
            ResultSet resultSet = null;
            try {
                statement = sqlConn.createStatement();
                resultSet = statement.executeQuery("SELECT SCHEMA()");
                String schemaName = null;
                if (resultSet.next()) {
                    schemaName = resultSet.getString(1);
                }
                if (schemaName != null) {
                    this.connectionSchemaName = schemaName;
                }
            } catch (SQLException e) {
                LogFactory.getLogger().info("Could not read current schema name: " + e.getMessage());
            } finally {
                JdbcUtils.close(resultSet, statement);
            }
        }
    }
    super.setConnection(conn);
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) DatabaseConnection(liquibase.database.DatabaseConnection) OfflineConnection(liquibase.database.OfflineConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) ResultSet(java.sql.ResultSet) JdbcConnection(liquibase.database.jvm.JdbcConnection) OfflineConnection(liquibase.database.OfflineConnection) Method(java.lang.reflect.Method) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) SQLException(java.sql.SQLException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParseException(java.text.ParseException) DatabaseException(liquibase.exception.DatabaseException) DateParseException(liquibase.exception.DateParseException)

Example 4 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class DatabaseChangeLog method expandExpressions.

protected void expandExpressions(ParsedNode parsedNode) {
    if (changeLogParameters == null) {
        return;
    }
    try {
        Object value = parsedNode.getValue();
        if (value != null && value instanceof String) {
            parsedNode.setValue(changeLogParameters.expandExpressions(parsedNode.getValue(String.class), this));
        }
        List<ParsedNode> children = parsedNode.getChildren();
        if (children != null) {
            for (ParsedNode child : children) {
                expandExpressions(child);
            }
        }
    } catch (ParsedNodeException e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 5 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class DatabaseChangeLog method handleChildNode.

protected void handleChildNode(ParsedNode node, ResourceAccessor resourceAccessor) throws ParsedNodeException, SetupException {
    expandExpressions(node);
    String nodeName = node.getName();
    if (nodeName.equals("changeSet")) {
        this.addChangeSet(createChangeSet(node, resourceAccessor));
    } else if (nodeName.equals("include")) {
        String path = node.getChildValue(null, "file", String.class);
        if (path == null) {
            throw new UnexpectedLiquibaseException("No 'file' attribute on 'include'");
        }
        path = path.replace('\\', '/');
        ContextExpression includeContexts = new ContextExpression(node.getChildValue(null, "context", String.class));
        try {
            include(path, node.getChildValue(null, "relativeToChangelogFile", false), resourceAccessor, includeContexts);
        } catch (LiquibaseException e) {
            throw new SetupException(e);
        }
    } else if (nodeName.equals("includeAll")) {
        String path = node.getChildValue(null, "path", String.class);
        String resourceFilterDef = node.getChildValue(null, "filter", String.class);
        if (resourceFilterDef == null) {
            resourceFilterDef = node.getChildValue(null, "resourceFilter", String.class);
        }
        IncludeAllFilter resourceFilter = null;
        if (resourceFilterDef != null) {
            try {
                resourceFilter = (IncludeAllFilter) Class.forName(resourceFilterDef).newInstance();
            } catch (Exception e) {
                throw new SetupException(e);
            }
        }
        String resourceComparatorDef = node.getChildValue(null, "resourceComparator", String.class);
        Comparator<?> resourceComparator = null;
        if (resourceComparatorDef != null) {
            try {
                resourceComparator = (Comparator<?>) Class.forName(resourceComparatorDef).newInstance();
            } catch (Exception e) {
                //take default comparator
                LogFactory.getInstance().getLog().info("no resourceComparator defined - taking default implementation");
                resourceComparator = getStandardChangeLogComparator();
            }
        }
        ContextExpression includeContexts = new ContextExpression(node.getChildValue(null, "context", String.class));
        includeAll(path, node.getChildValue(null, "relativeToChangelogFile", false), resourceFilter, node.getChildValue(null, "errorIfMissingOrEmpty", true), getStandardChangeLogComparator(), resourceAccessor, includeContexts);
    } else if (nodeName.equals("preConditions")) {
        this.preconditionContainer = new PreconditionContainer();
        try {
            this.preconditionContainer.load(node, resourceAccessor);
        } catch (ParsedNodeException e) {
            e.printStackTrace();
        }
    } else if (nodeName.equals("property")) {
        try {
            String context = node.getChildValue(null, "context", String.class);
            String dbms = node.getChildValue(null, "dbms", String.class);
            String labels = node.getChildValue(null, "labels", String.class);
            Boolean global = node.getChildValue(null, "global", Boolean.class);
            if (global == null) {
                // okay behave like liquibase < 3.4 and set global == true
                global = true;
            }
            String file = node.getChildValue(null, "file", String.class);
            if (file == null) {
                // direct referenced property, no file
                String name = node.getChildValue(null, "name", String.class);
                String value = node.getChildValue(null, "value", String.class);
                this.changeLogParameters.set(name, value, context, labels, dbms, global, this);
            } else {
                // read properties from the file
                Properties props = new Properties();
                InputStream propertiesStream = StreamUtil.singleInputStream(file, resourceAccessor);
                if (propertiesStream == null) {
                    LogFactory.getInstance().getLog().info("Could not open properties file " + file);
                } else {
                    props.load(propertiesStream);
                    for (Map.Entry entry : props.entrySet()) {
                        this.changeLogParameters.set(entry.getKey().toString(), entry.getValue().toString(), context, labels, dbms, global, this);
                    }
                }
            }
        } catch (IOException e) {
            throw new ParsedNodeException(e);
        }
    }
}
Also used : PreconditionContainer(liquibase.precondition.core.PreconditionContainer) InputStream(java.io.InputStream) ContextExpression(liquibase.ContextExpression) IOException(java.io.IOException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) SetupException(liquibase.exception.SetupException) UnknownChangelogFormatException(liquibase.exception.UnknownChangelogFormatException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ValidationFailedException(liquibase.exception.ValidationFailedException) LiquibaseException(liquibase.exception.LiquibaseException) SetupException(liquibase.exception.SetupException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Aggregations

UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)75 DatabaseException (liquibase.exception.DatabaseException)12 IOException (java.io.IOException)10 Database (liquibase.database.Database)10 DatabaseObject (liquibase.structure.DatabaseObject)10 LiquibaseException (liquibase.exception.LiquibaseException)9 InvalidExampleException (liquibase.snapshot.InvalidExampleException)9 CatalogAndSchema (liquibase.CatalogAndSchema)8 InputStream (java.io.InputStream)7 ParsedNodeException (liquibase.parser.core.ParsedNodeException)7 SQLException (java.sql.SQLException)6 DatabaseFunction (liquibase.statement.DatabaseFunction)6 SqlStatement (liquibase.statement.SqlStatement)6 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 Change (liquibase.change.Change)5 ColumnConfig (liquibase.change.ColumnConfig)5 Executor (liquibase.executor.Executor)5 Sql (liquibase.sql.Sql)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4