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