Search in sources :

Example 71 with UnexpectedLiquibaseException

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

the class LiquibaseGenerateChangeLogMojo method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    ClassLoader cl = null;
    try {
        cl = getClassLoaderIncludingProjectClasspath();
        Thread.currentThread().setContextClassLoader(cl);
    } catch (MojoExecutionException e) {
        throw new LiquibaseException("Could not create the class loader, " + e, e);
    }
    Database database = liquibase.getDatabase();
    getLog().info("Generating Change Log from database " + database.toString());
    try {
        DiffOutputControl diffOutputControl = new DiffOutputControl(outputDefaultCatalog, outputDefaultSchema, true, null);
        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.doGenerateChangeLog(outputChangeLogFile, database, defaultCatalogName, defaultSchemaName, StringUtils.trimToNull(diffTypes), StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataDir), diffOutputControl);
        getLog().info("Output written to Change Log file, " + outputChangeLogFile);
    } catch (IOException e) {
        throw new LiquibaseException(e);
    } catch (ParserConfigurationException e) {
        throw new LiquibaseException(e);
    }
}
Also used : 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) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 72 with UnexpectedLiquibaseException

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

the class StandardLockService method destroy.

@Override
public void destroy() throws DatabaseException {
    try {
        if (SnapshotGeneratorFactory.getInstance().has(new Table().setName(database.getDatabaseChangeLogLockTableName()).setSchema(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName()), database)) {
            ExecutorService.getInstance().getExecutor(database).execute(new DropTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName(), false));
            hasDatabaseChangeLogLockTable = null;
        }
        reset();
    } catch (InvalidExampleException e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : InvalidExampleException(liquibase.snapshot.InvalidExampleException) Table(liquibase.structure.core.Table) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 73 with UnexpectedLiquibaseException

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

the class AbstractResourceAccessor method convertToPath.

protected String convertToPath(String relativeTo, String path) {
    if (StringUtils.trimToNull(relativeTo) == null) {
        return path;
    }
    URL baseUrl = toClassLoader().getResource(relativeTo);
    if (baseUrl == null) {
        throw new UnexpectedLiquibaseException("Cannot find base path '" + relativeTo + "'");
    }
    String base;
    if (baseUrl.toExternalForm().startsWith("file:")) {
        File baseFile = new File(baseUrl.getPath());
        if (!baseFile.exists()) {
            throw new UnexpectedLiquibaseException("Base file '" + baseFile.getAbsolutePath() + "' does not exist");
        }
        if (baseFile.isFile()) {
            baseFile = baseFile.getParentFile();
        }
        base = baseFile.toURI().getPath();
    } else if (baseUrl.toExternalForm().startsWith("jar:file:")) {
        return convertToPath(new File(relativeTo).getParent() + '/' + path);
    } else {
        base = relativeTo;
    }
    String separator = "";
    if (!base.endsWith("/") && !path.startsWith("/")) {
        separator = "/";
    }
    if (base.endsWith("/") && path.startsWith("/")) {
        base = base.substring(0, base.length() - 1);
    }
    return convertToPath(base + separator + path);
}
Also used : UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) File(java.io.File) URL(java.net.URL)

Example 74 with UnexpectedLiquibaseException

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

the class AbstractResourceAccessor method init.

protected void init() {
    try {
        Enumeration<URL> baseUrls;
        ClassLoader classLoader = toClassLoader();
        if (classLoader != null) {
            if (classLoader instanceof URLClassLoader) {
                baseUrls = new Vector<URL>(Arrays.asList(((URLClassLoader) classLoader).getURLs())).elements();
                while (baseUrls.hasMoreElements()) {
                    addRootPath(baseUrls.nextElement());
                }
            }
            baseUrls = classLoader.getResources("");
            while (baseUrls.hasMoreElements()) {
                addRootPath(baseUrls.nextElement());
            }
        }
    } catch (IOException e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) URL(java.net.URL)

Example 75 with UnexpectedLiquibaseException

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

the class AbstractDatabaseObject method getSerializableFieldValue.

@Override
public Object getSerializableFieldValue(String field) {
    if (field.equals("snapshotId")) {
        return snapshotId;
    }
    if (!attributes.containsKey(field)) {
        throw new UnexpectedLiquibaseException("Unknown field " + field);
    }
    Object value = attributes.get(field);
    try {
        if (value instanceof Schema) {
            Schema clone = new Schema(((Schema) value).getCatalogName(), ((Schema) value).getName());
            clone.setSnapshotId(((DatabaseObject) value).getSnapshotId());
            return clone;
        } else if (value instanceof DatabaseObject) {
            DatabaseObject clone = (DatabaseObject) value.getClass().newInstance();
            clone.setName(((DatabaseObject) value).getName());
            clone.setSnapshotId(((DatabaseObject) value).getSnapshotId());
            return clone;
        }
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
    return value;
}
Also used : Schema(liquibase.structure.core.Schema) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParsedNodeException(liquibase.parser.core.ParsedNodeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ParseException(java.text.ParseException)

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