use of liquibase.CatalogAndSchema in project liquibase by liquibase.
the class DropAllTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
try {
if (StringUtils.trimToNull(schemas) != null) {
List<String> schemaNames = StringUtils.splitAndTrim(this.schemas, ",");
List<CatalogAndSchema> schemas = new ArrayList<CatalogAndSchema>();
for (String name : schemaNames) {
schemas.add(new CatalogAndSchema(catalog, name));
}
liquibase.dropAll(schemas.toArray(new CatalogAndSchema[schemas.size()]));
} else {
liquibase.dropAll();
}
} catch (LiquibaseException e) {
throw new BuildException("Unable to drop all objects from database. " + e.toString(), e);
}
}
use of liquibase.CatalogAndSchema in project liquibase by liquibase.
the class GenerateChangeLogTask method executeWithLiquibaseClassloader.
@Override
public void executeWithLiquibaseClassloader() throws BuildException {
Liquibase liquibase = getLiquibase();
Database database = liquibase.getDatabase();
CatalogAndSchema catalogAndSchema = buildCatalogAndSchema(database);
DiffOutputControl diffOutputControl = getDiffOutputControl();
DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffOutputControl);
for (ChangeLogOutputFile changeLogOutputFile : changeLogOutputFiles) {
String encoding = getOutputEncoding(changeLogOutputFile);
PrintStream printStream = null;
try {
FileResource outputFile = changeLogOutputFile.getOutputFile();
ChangeLogSerializer changeLogSerializer = changeLogOutputFile.getChangeLogSerializer();
log("Writing change log file " + outputFile.toString(), Project.MSG_INFO);
printStream = new PrintStream(outputFile.getOutputStream(), true, encoding);
liquibase.generateChangeLog(catalogAndSchema, diffToChangeLog, printStream, changeLogSerializer);
} catch (UnsupportedEncodingException e) {
throw new BuildException("Unable to generate a change log. Encoding [" + encoding + "] is not supported.", e);
} catch (IOException e) {
throw new BuildException("Unable to generate a change log. Error creating output stream.", e);
} catch (ParserConfigurationException e) {
throw new BuildException("Unable to generate a change log. Error configuring parser.", e);
} catch (DatabaseException e) {
throw new BuildException("Unable to generate a change log. " + e.toString(), e);
} finally {
FileUtils.close(printStream);
}
}
}
use of liquibase.CatalogAndSchema in project liquibase by liquibase.
the class CommandLineUtils method doGenerateChangeLog.
public static void doGenerateChangeLog(String changeLogFile, Database originalDatabase, CatalogAndSchema[] schemas, String snapshotTypes, String author, String context, String dataDir, DiffOutputControl diffOutputControl) throws DatabaseException, IOException, ParserConfigurationException, InvalidExampleException, LiquibaseException {
CompareControl.SchemaComparison[] comparisons = new CompareControl.SchemaComparison[schemas.length];
int i = 0;
for (CatalogAndSchema schema : schemas) {
comparisons[i++] = new CompareControl.SchemaComparison(schema, schema);
}
CompareControl compareControl = new CompareControl(comparisons, snapshotTypes);
diffOutputControl.setDataDir(dataDir);
GenerateChangeLogCommand command = (GenerateChangeLogCommand) CommandFactory.getInstance().getCommand("generateChangeLog");
command.setReferenceDatabase(originalDatabase).setSnapshotTypes(snapshotTypes).setOutputStream(System.out).setCompareControl(compareControl);
command.setChangeLogFile(changeLogFile).setDiffOutputControl(diffOutputControl);
command.setAuthor(author).setContext(context);
try {
command.execute();
} catch (CommandExecutionException e) {
throw new LiquibaseException(e);
}
}
use of liquibase.CatalogAndSchema in project liquibase by liquibase.
the class FindForeignKeyConstraintsGeneratorMySQL method generateSql.
@Override
public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
CatalogAndSchema schema = new CatalogAndSchema(statement.getBaseTableCatalogName(), statement.getBaseTableSchemaName()).customize(database);
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
sb.append("RC.TABLE_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append(", ");
sb.append("KCU.COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append(", ");
sb.append("RC.REFERENCED_TABLE_NAME ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME).append(", ");
sb.append("KCU.REFERENCED_COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME).append(", ");
sb.append("RC.CONSTRAINT_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append(" ");
sb.append("FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC,");
sb.append(" INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU ");
sb.append("WHERE RC.TABLE_NAME = KCU.TABLE_NAME ");
sb.append("AND RC.CONSTRAINT_SCHEMA = KCU.CONSTRAINT_SCHEMA ");
sb.append("AND RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME ");
sb.append("AND RC.TABLE_NAME = '").append(statement.getBaseTableName()).append("' ");
sb.append("AND RC.CONSTRAINT_SCHEMA = '").append(schema.getCatalogName()).append("'");
sb.append("AND KCU.TABLE_SCHEMA = '").append(schema.getCatalogName()).append("'");
return new Sql[] { new UnparsedSql(sb.toString()) };
}
use of liquibase.CatalogAndSchema in project liquibase by liquibase.
the class AbstractIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
openConnection(url);
if (database != null) {
if (!database.getConnection().getAutoCommit()) {
database.rollback();
}
SnapshotGeneratorFactory.resetAll();
ExecutorService.getInstance().reset();
LockServiceFactory.getInstance().resetAll();
LockServiceFactory.getInstance().getLockService(database).init();
ChangeLogHistoryServiceFactory.getInstance().resetAll();
if (database.getConnection() != null) {
((JdbcConnection) database.getConnection()).getUnderlyingConnection().createStatement().executeUpdate("drop table " + database.getDatabaseChangeLogLockTableName());
database.commit();
}
SnapshotGeneratorFactory.resetAll();
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
database.dropDatabaseObjects(CatalogAndSchema.DEFAULT);
if (database.supportsSchemas()) {
database.dropDatabaseObjects(new CatalogAndSchema((String) null, DatabaseTestContext.ALT_SCHEMA));
}
if (supportsAltCatalogTests()) {
if (database.supportsSchemas() && database.supportsCatalogs()) {
database.dropDatabaseObjects(new CatalogAndSchema(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA));
} else if (database.supportsCatalogs()) {
database.dropDatabaseObjects(new CatalogAndSchema(DatabaseTestContext.ALT_SCHEMA, null));
}
}
database.commit();
SnapshotGeneratorFactory.resetAll();
}
}
Aggregations