Search in sources :

Example 66 with UnexpectedLiquibaseException

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

the class ExecutorService method getExecutor.

public Executor getExecutor(Database database) {
    if (!executors.containsKey(database)) {
        try {
            Executor executor = (Executor) ServiceLocator.getInstance().newInstance(Executor.class);
            executor.setDatabase(database);
            executors.put(database, executor);
        } catch (Exception e) {
            throw new UnexpectedLiquibaseException(e);
        }
    }
    return executors.get(database);
}
Also used : UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 67 with UnexpectedLiquibaseException

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

the class StandardObjectChangeFilter method parseFilter.

protected void parseFilter(String filter) {
    filter = StringUtils.trimToNull(filter);
    if (filter == null) {
        return;
    }
    for (String subfilter : filter.split("\\s*,\\s*")) {
        String[] split = subfilter.split(":");
        if (split.length == 1) {
            filters.add(new Filter(null, Pattern.compile(split[0]), filterType));
        } else {
            String className = StringUtils.upperCaseFirst(split[0]);
            className = "liquibase.structure.core." + className;
            try {
                Class<DatabaseObject> clazz = (Class<DatabaseObject>) Class.forName(className);
                filters.add(new Filter(clazz, Pattern.compile(split[1]), filterType));
            } catch (ClassNotFoundException e) {
                throw new UnexpectedLiquibaseException(e);
            }
        }
    }
}
Also used : DatabaseObject(liquibase.structure.DatabaseObject) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 68 with UnexpectedLiquibaseException

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

the class CompareControl method computeSchemas.

public static ComputedSchemas computeSchemas(String schemaNames, String referenceSchemaNames, String outputSchemaNames, String defaultCatalogName, String defaultSchemaName, String referenceDefaultCatalogName, String referenceDefaultSchemaName, Database database) {
    //Make sure either both schemaNames and referenceSchemaNames are set or both are null. If only one is set, make them equal
    if (schemaNames == null && referenceSchemaNames == null) {
        //they will be set to the defaults
        ;
    } else if (schemaNames == null && referenceSchemaNames != null) {
        schemaNames = referenceSchemaNames;
    } else if (schemaNames != null && referenceSchemaNames == null) {
        referenceSchemaNames = schemaNames;
    }
    if (schemaNames == null && outputSchemaNames != null) {
        if (defaultSchemaName == null) {
            schemaNames = database.getDefaultSchemaName();
        } else {
            schemaNames = defaultSchemaName;
        }
        referenceSchemaNames = schemaNames;
    }
    ComputedSchemas returnObj = new ComputedSchemas();
    if (referenceSchemaNames == null) {
        returnObj.finalSchemaComparisons = new CompareControl.SchemaComparison[] { new CompareControl.SchemaComparison(new CatalogAndSchema(referenceDefaultCatalogName, referenceDefaultSchemaName), new CatalogAndSchema(defaultCatalogName, defaultSchemaName)) };
        returnObj.finalTargetSchemas = new CatalogAndSchema[] { new CatalogAndSchema(defaultCatalogName, defaultSchemaName) };
    } else {
        List<SchemaComparison> schemaComparisons = new ArrayList<CompareControl.SchemaComparison>();
        List<CatalogAndSchema> referenceSchemas = new ArrayList<CatalogAndSchema>();
        List<CatalogAndSchema> targetSchemas = new ArrayList<CatalogAndSchema>();
        List<String> splitReferenceSchemaNames = StringUtils.splitAndTrim(referenceSchemaNames, ",");
        List<String> splitSchemaNames = StringUtils.splitAndTrim(schemaNames, ",");
        List<String> splitOutputSchemaNames = StringUtils.splitAndTrim(StringUtils.trimToNull(outputSchemaNames), ",");
        if (splitReferenceSchemaNames.size() != splitSchemaNames.size()) {
            throw new UnexpectedLiquibaseException("You must specify the same number of schemas in --schemas and --referenceSchemas");
        }
        if (splitOutputSchemaNames != null && splitOutputSchemaNames.size() != splitSchemaNames.size()) {
            throw new UnexpectedLiquibaseException("You must specify the same number of schemas in --schemas and --outputSchemasAs");
        }
        for (int i = 0; i < splitReferenceSchemaNames.size(); i++) {
            String referenceSchema = splitReferenceSchemaNames.get(i);
            String targetSchema = splitSchemaNames.get(i);
            String outputSchema = null;
            if (splitOutputSchemaNames != null) {
                outputSchema = splitOutputSchemaNames.get(i);
            }
            CatalogAndSchema correctedTargetSchema = new CatalogAndSchema(null, targetSchema).customize(database);
            CatalogAndSchema correctedReferenceSchema = new CatalogAndSchema(null, referenceSchema).customize(database);
            SchemaComparison comparison = new SchemaComparison(correctedReferenceSchema, correctedTargetSchema);
            comparison.setOutputSchemaAs(outputSchema);
            schemaComparisons.add(comparison);
            referenceSchemas.add(correctedReferenceSchema);
            targetSchemas.add(correctedTargetSchema);
        }
        returnObj.finalSchemaComparisons = schemaComparisons.toArray(new CompareControl.SchemaComparison[schemaComparisons.size()]);
        returnObj.finalTargetSchemas = targetSchemas.toArray(new CatalogAndSchema[targetSchemas.size()]);
    }
    return returnObj;
}
Also used : CatalogAndSchema(liquibase.CatalogAndSchema) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 69 with UnexpectedLiquibaseException

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

the class AbstractLiquibaseMojo method configureFieldsAndValues.

public void configureFieldsAndValues(ResourceAccessor fo) throws MojoExecutionException, MojoFailureException {
    // already specified.
    if (propertyFile != null) {
        getLog().info("Parsing Liquibase Properties File");
        getLog().info("  File: " + propertyFile);
        InputStream is;
        try {
            is = StreamUtil.singleInputStream(propertyFile, fo);
        } catch (IOException e) {
            throw new UnexpectedLiquibaseException(e);
        }
        if (is == null) {
            throw new MojoFailureException("Failed to resolve the properties file.");
        }
        parsePropertiesFile(is);
        getLog().info(MavenUtils.LOG_SEPARATOR);
    }
}
Also used : MojoFailureException(org.apache.maven.plugin.MojoFailureException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 70 with UnexpectedLiquibaseException

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

the class LiquibaseDatabaseDiff method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    ClassLoader cl = null;
    ResourceAccessor fileOpener;
    try {
        cl = getClassLoaderIncludingProjectClasspath();
        Thread.currentThread().setContextClassLoader(cl);
        ClassLoader artifactClassLoader = getMavenArtifactClassLoader();
        fileOpener = getFileOpener(artifactClassLoader);
    } catch (MojoExecutionException e) {
        throw new LiquibaseException("Could not create the class loader, " + e, e);
    }
    Database db = liquibase.getDatabase();
    Database referenceDatabase = CommandLineUtils.createDatabaseObject(fileOpener, referenceUrl, referenceUsername, referencePassword, referenceDriver, referenceDefaultCatalogName, referenceDefaultSchemaName, outputDefaultCatalog, outputDefaultSchema, null, null, propertyProviderClass, null, null, databaseChangeLogTableName, databaseChangeLogLockTableName);
    getLog().info("Performing Diff on database " + db.toString());
    if (diffChangeLogFile != null) {
        try {
            DiffOutputControl diffOutputControl = new DiffOutputControl(diffIncludeCatalog, diffIncludeSchema, diffIncludeTablespace, null).addIncludedSchema(new CatalogAndSchema(referenceDefaultCatalogName, referenceDefaultSchemaName));
            if (diffExcludeObjects != null && diffIncludeObjects != null) {
                throw new UnexpectedLiquibaseException("Cannot specify both excludeObjects and includeObjects");
            }
            if (diffExcludeObjects != null) {
                diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.EXCLUDE, diffExcludeObjects));
            }
            if (diffIncludeObjects != null) {
                diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.INCLUDE, diffIncludeObjects));
            }
            CommandLineUtils.doDiffToChangeLog(diffChangeLogFile, referenceDatabase, db, diffOutputControl, StringUtils.trimToNull(diffTypes));
            getLog().info("Differences written to Change Log File, " + diffChangeLogFile);
        } catch (IOException e) {
            throw new LiquibaseException(e);
        } catch (ParserConfigurationException e) {
            throw new LiquibaseException(e);
        }
    } else {
        CommandLineUtils.doDiff(referenceDatabase, db, StringUtils.trimToNull(diffTypes));
    }
}
Also used : ResourceAccessor(liquibase.resource.ResourceAccessor) StandardObjectChangeFilter(liquibase.diff.output.StandardObjectChangeFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Database(liquibase.database.Database) DiffOutputControl(liquibase.diff.output.DiffOutputControl) LiquibaseException(liquibase.exception.LiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CatalogAndSchema(liquibase.CatalogAndSchema) 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