use of liquibase.database.Database in project liquibase by liquibase.
the class InternalGenerateChangelogCommandStep method run.
@Override
public void run(CommandResultsBuilder resultsBuilder) throws Exception {
CommandScope commandScope = resultsBuilder.getCommandScope();
outputBestPracticeMessage();
String changeLogFile = StringUtil.trimToNull(commandScope.getArgumentValue(CHANGELOG_FILE_ARG));
if (changeLogFile != null && changeLogFile.toLowerCase().endsWith(".sql")) {
Scope.getCurrentScope().getUI().sendMessage("\n" + INFO_MESSAGE + "\n");
Scope.getCurrentScope().getLog(getClass()).info("\n" + INFO_MESSAGE + "\n");
}
final Database referenceDatabase = commandScope.getArgumentValue(REFERENCE_DATABASE_ARG);
InternalSnapshotCommandStep.logUnsupportedDatabase(referenceDatabase, this.getClass());
DiffResult diffResult = createDiffResult(commandScope);
DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, commandScope.getArgumentValue(DIFF_OUTPUT_CONTROL_ARG));
changeLogWriter.setChangeSetAuthor(commandScope.getArgumentValue(AUTHOR_ARG));
changeLogWriter.setChangeSetContext(commandScope.getArgumentValue(CONTEXT_ARG));
changeLogWriter.setChangeSetPath(changeLogFile);
ObjectQuotingStrategy originalStrategy = referenceDatabase.getObjectQuotingStrategy();
try {
referenceDatabase.setObjectQuotingStrategy(ObjectQuotingStrategy.QUOTE_ALL_OBJECTS);
if (StringUtil.trimToNull(changeLogFile) != null) {
changeLogWriter.print(changeLogFile);
} else {
PrintStream outputStream = new PrintStream(resultsBuilder.getOutputStream());
try {
changeLogWriter.print(outputStream);
} finally {
outputStream.flush();
}
}
if (StringUtil.trimToNull(changeLogFile) != null) {
Scope.getCurrentScope().getUI().sendMessage("Generated changelog written to " + new File(changeLogFile).getAbsolutePath());
}
} finally {
referenceDatabase.setObjectQuotingStrategy(originalStrategy);
}
}
use of liquibase.database.Database in project liquibase by liquibase.
the class InternalSnapshotCommandStep method run.
@Override
public void run(CommandResultsBuilder resultsBuilder) throws Exception {
CommandScope commandScope = resultsBuilder.getCommandScope();
Database database = commandScope.getArgumentValue(DATABASE_ARG);
SnapshotListener snapshotListener = commandScope.getArgumentValue(SNAPSHOT_LISTENER_ARG);
CatalogAndSchema[] schemas = commandScope.getArgumentValue(SCHEMAS_ARG);
InternalSnapshotCommandStep.logUnsupportedDatabase(database, this.getClass());
SnapshotControl snapshotControl = new SnapshotControl(database);
snapshotControl.setSnapshotListener(snapshotListener);
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());
resultsBuilder.addResult("snapshot", snapshot);
}
use of liquibase.database.Database in project liquibase by liquibase.
the class DiffGeneratorFactory method compare.
public DiffResult compare(DatabaseSnapshot referenceSnapshot, DatabaseSnapshot comparisonSnapshot, CompareControl compareControl) throws DatabaseException {
Database referenceDatabase = referenceSnapshot.getDatabase();
if (comparisonSnapshot != null && referenceDatabase != null) {
if (referenceDatabase.getDefaultCatalogName() == null || referenceDatabase.getDefaultCatalogName().isEmpty()) {
referenceDatabase.setDefaultCatalogName(comparisonSnapshot.getDatabase().getDefaultCatalogName());
}
if (referenceDatabase.getDefaultSchemaName() == null || referenceDatabase.getDefaultSchemaName().isEmpty()) {
referenceDatabase.setDefaultSchemaName(comparisonSnapshot.getDatabase().getDefaultSchemaName());
}
}
Database comparisonDatabase;
if (comparisonSnapshot == null) {
comparisonDatabase = referenceSnapshot.getDatabase();
try {
comparisonSnapshot = new EmptyDatabaseSnapshot(referenceDatabase, referenceSnapshot.getSnapshotControl());
} catch (InvalidExampleException e) {
throw new UnexpectedLiquibaseException(e);
}
} else {
comparisonDatabase = comparisonSnapshot.getDatabase();
}
return getGenerator(referenceDatabase, comparisonDatabase).compare(referenceSnapshot, comparisonSnapshot, compareControl);
}
use of liquibase.database.Database in project liquibase by liquibase.
the class DiffResult method getChangedObject.
public ObjectDifferences getChangedObject(DatabaseObject example, CompareControl.SchemaComparison[] schemaComparisons) {
Database accordingTo = this.getComparisonSnapshot().getDatabase();
DatabaseObjectComparatorFactory comparator = DatabaseObjectComparatorFactory.getInstance();
for (Map.Entry<? extends DatabaseObject, ObjectDifferences> entry : getChangedObjects(example.getClass()).entrySet()) {
if (comparator.isSameObject(entry.getKey(), example, schemaComparisons, accordingTo)) {
return entry.getValue();
}
}
return null;
}
use of liquibase.database.Database in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByDerbyDatabase.
@Test
public void testAutoIncrementStartWithIncrementByDerbyDatabase() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof DerbyDatabase) {
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.ZERO, BigInteger.TEN));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0, INCREMENT BY 10))", generatedSql[0].toSql());
}
}
}
Aggregations