use of liquibase.database.ObjectQuotingStrategy in project liquibase by liquibase.
the class SchemaSnapshotGenerator method snapshotObject.
@Override
protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException {
Database database = snapshot.getDatabase();
Schema match = null;
String catalogName = ((Schema) example).getCatalogName();
String schemaName = example.getName();
if (database.supportsSchemas()) {
if (catalogName == null) {
catalogName = database.getDefaultCatalogName();
}
if (schemaName == null) {
schemaName = database.getDefaultSchemaName();
}
} else {
if (database.supportsCatalogs()) {
if (catalogName == null && schemaName != null) {
catalogName = schemaName;
schemaName = null;
}
} else {
catalogName = null;
schemaName = null;
}
}
example = new Schema(catalogName, schemaName);
// use LEGACY quoting since we're dealing with system objects
ObjectQuotingStrategy currentStrategy = database.getObjectQuotingStrategy();
database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY);
try {
if (database.supportsSchemas()) {
for (String tableSchema : getDatabaseSchemaNames(database)) {
CatalogAndSchema schemaFromJdbcInfo = toCatalogAndSchema(tableSchema, database);
Catalog catalog = new Catalog(schemaFromJdbcInfo.getCatalogName());
Schema schema = new Schema(catalog, tableSchema);
if (DatabaseObjectComparatorFactory.getInstance().isSameObject(schema, example, snapshot.getSchemaComparisons(), database)) {
if (match == null) {
match = schema;
} else {
throw new InvalidExampleException("Found multiple catalog/schemas matching " + ((Schema) example).getCatalogName() + "." + example.getName());
}
}
}
} else {
Catalog catalog = new Catalog(catalogName);
match = new Schema(catalog, catalogName);
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
database.setObjectQuotingStrategy(currentStrategy);
}
if (match != null && (match.getName() == null || match.getName().equalsIgnoreCase(database.getDefaultSchemaName()))) {
match.setDefault(true);
}
return match;
}
use of liquibase.database.ObjectQuotingStrategy in project liquibase by liquibase.
the class DiffCommand method createTargetSnapshot.
protected DatabaseSnapshot createTargetSnapshot() throws DatabaseException, InvalidExampleException {
CatalogAndSchema[] schemas;
if (compareControl == null || compareControl.getSchemaComparisons() == null) {
schemas = new CatalogAndSchema[] { targetDatabase.getDefaultSchema() };
} else {
schemas = new CatalogAndSchema[compareControl.getSchemaComparisons().length];
int i = 0;
for (CompareControl.SchemaComparison comparison : compareControl.getSchemaComparisons()) {
CatalogAndSchema schema;
if (targetDatabase.supportsSchemas()) {
schema = new CatalogAndSchema(targetDatabase.getDefaultCatalogName(), comparison.getComparisonSchema().getSchemaName());
} else {
schema = new CatalogAndSchema(comparison.getComparisonSchema().getSchemaName(), comparison.getComparisonSchema().getSchemaName());
}
schemas[i++] = schema;
}
}
SnapshotControl snapshotControl = getTargetSnapshotControl();
if (snapshotControl == null) {
snapshotControl = new SnapshotControl(targetDatabase, snapshotTypes);
}
if (getSnapshotListener() != null) {
snapshotControl.setSnapshotListener(getSnapshotListener());
}
ObjectQuotingStrategy originalStrategy = referenceDatabase.getObjectQuotingStrategy();
try {
referenceDatabase.setObjectQuotingStrategy(ObjectQuotingStrategy.QUOTE_ALL_OBJECTS);
return SnapshotGeneratorFactory.getInstance().createSnapshot(schemas, targetDatabase, snapshotControl);
} finally {
referenceDatabase.setObjectQuotingStrategy(originalStrategy);
}
}
use of liquibase.database.ObjectQuotingStrategy in project liquibase by liquibase.
the class SnapshotCommand method run.
@Override
protected SnapshotCommandResult run() throws Exception {
SnapshotControl snapshotControl = new SnapshotControl(database);
snapshotControl.setSnapshotListener(snapshotListener);
CatalogAndSchema[] schemas = this.schemas;
if (schemas == null) {
schemas = new CatalogAndSchema[] { database.getDefaultSchema() };
}
ObjectQuotingStrategy originalQuotingStrategy = database.getObjectQuotingStrategy();
database.setObjectQuotingStrategy(ObjectQuotingStrategy.QUOTE_ALL_OBJECTS);
DatabaseSnapshot snapshot;
try {
snapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(schemas, database, snapshotControl);
} finally {
database.setObjectQuotingStrategy(originalQuotingStrategy);
}
snapshot.setMetadata(this.getSnapshotMetadata());
return new SnapshotCommandResult(snapshot);
}
Aggregations