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);
}
}
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);
}
}
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);
}
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);
}
}
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;
}
Aggregations