本文整理汇总了Java中liquibase.diff.output.changelog.DiffToChangeLog类的典型用法代码示例。如果您正苦于以下问题:Java DiffToChangeLog类的具体用法?Java DiffToChangeLog怎么用?Java DiffToChangeLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiffToChangeLog类属于liquibase.diff.output.changelog包,在下文中一共展示了DiffToChangeLog类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recordSchemaDifferencesBetweenHbm2ddlAndLiquibase
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
public void recordSchemaDifferencesBetweenHbm2ddlAndLiquibase() throws SQLException, LiquibaseException,
IOException, ParserConfigurationException {
Database referenceConnection = createDatabase(liquibaseDataSource.getConnection());
Database comparisonConnection = createDatabase(hbm2ddlDataSource.getConnection());
Liquibase liquibaseObject =
new Liquibase("liquibase/changelog-master.xml", new ClassLoaderResourceAccessor(), referenceConnection);
liquibaseObject.dropAll();
liquibaseObject.update("");
DiffResult result =
DiffGeneratorFactory.getInstance().compare(comparisonConnection, referenceConnection, new CompareControl());
DiffToChangeLog changeLog = new DiffToChangeLog(result, new DiffOutputControl(false, false, false));
changeLog.print(new File("target/schemaDifferences.xml").getAbsolutePath(), new XMLChangeLogSerializer());
changeLog.print(System.out);
}
示例2: run
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
@Override
protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception {
// The existing database with migrations managed by Liquibase.
DataSourceFactory outdatedDb = configuration.getDatabaseConfig();
try (CloseableLiquibase outdatedLiquibase = createLiquibase(outdatedDb)) {
// A temporary database that starts out empty and then gets the autogenerated Ebean table definitions applied.
DataSourceFactory freshDb = EbeanConfigUtils.clone(outdatedDb);
String url = outdatedDb.getUrl();
freshDb.setUrl(url.substring(0, url.lastIndexOf("/")) + "/migrationdiff");
// Creating the Ebean server makes it apply its table definitions to the database immediately.
ServerConfig serverConfig = EbeanConfigUtils.createServerConfig(freshDb);
serverConfig.setDdlGenerate(true);
serverConfig.setDdlRun(true);
EbeanServer ebeanServer = EbeanServerFactory.create(serverConfig);
try (CloseableLiquibase freshLiquibase = createLiquibase(freshDb)) {
// Create and print the differences between the two databases, i.e. a migration that should be applied to update to the newest Ebean definitions.
DiffResult diff = outdatedLiquibase.diff(freshLiquibase.getDatabase(), outdatedLiquibase.getDatabase(), CompareControl.STANDARD);
DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diff, new DiffOutputControl(false, false, true));
diffToChangeLog.print(System.out);
}
}
}
示例3: run
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void run(Namespace namespace, Liquibase liquibase) throws Exception
{
String subChangeLogFile = namespace.getString("subChangeLogFile");
liquibase.generateChangeLog(new CatalogAndSchema(null, null), new DiffToChangeLog(new DiffOutputControl()),
new PrintStream(subChangeLogFile));
}
示例4: toChangeLog
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
private String toChangeLog(DiffToChangeLog diffToChangeLog) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(out, true, "UTF-8");
diffToChangeLog.setChangeSetAuthor("jhipster");
diffToChangeLog.print(printStream);
printStream.close();
return out.toString("UTF-8");
}
示例5: generateChangeLog_noChanges
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
@Test
public void generateChangeLog_noChanges() throws Exception{
if (database == null) {
return;
}
runCompleteChangeLog();
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, database, new CompareControl());
DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, new DiffOutputControl(false, false, false));
assertEquals(0, changeLogWriter.generateChangeSets().size());
}
示例6: generateMigrations
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
private File generateMigrations(final Database referenceDatabase, final Database targetDatabase)
throws LiquibaseException, IOException {
if (!resourcesDir.exists()) {
resourcesDir.mkdirs();
}
if (!migrationsDir.exists()) {
migrationsDir.mkdirs();
}
if (masterChangeLogFile.exists()) {
LOG.info("Checking current database state");
validateDatabaseState(targetDatabase);
} else {
LOG.info("Creating new master changelog");
writeChangeSets(masterChangeLogFile, emptyList());
}
@SuppressWarnings("unchecked")
final SnapshotControl snapshotControl = new SnapshotControl(
referenceDatabase,
liquibase.structure.core.Schema.class,
liquibase.structure.core.Table.class,
liquibase.structure.core.Column.class,
liquibase.structure.core.PrimaryKey.class,
liquibase.structure.core.Index.class);
LOG.info("Executing diff");
final CompareControl compareControl = new CompareControl(snapshotControl.getTypesToInclude());
final DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(
referenceDatabase,
targetDatabase,
compareControl);
LOG.info("Converting diff to changelog");
final DiffOutputControl diffOutputControl = new DiffOutputControl(false, false, true, null);
final DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffResult, diffOutputControl);
diffToChangeLog.setChangeSetAuthor(System.getProperty("user.name"));
final List<ChangeSet> changeSets = filterChangeSets(diffToChangeLog.generateChangeSets());
LOG.info("Found {} changes", changeSets.size());
if (changeSets.isEmpty()) {
return null;
}
final File generatedChangeLogFile = new File(migrationsDir, generateFileName(masterChangeLogFile));
LOG.info("Writing new changelog: {}", generatedChangeLogFile);
writeChangeSets(generatedChangeLogFile, changeSets);
LOG.info("Add migration to master changelog: {}", masterChangeLogFile);
addIncludeFile(generatedChangeLogFile);
LOG.info("Cleaning changelog");
cleanXmlFile(masterChangeLogFile);
cleanXmlFile(generatedChangeLogFile);
LOG.info("Diff complete");
return generatedChangeLogFile;
}
示例7: diff
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
/**
* Diffs database schema against new changes in JPA model and returns Liquibase diff XML file as String.
*
* @param persistenceUnit the persistence unit
* @param propertiesCategory the properties category
* @return the Liquibase diff XML file as String.
*/
public static String diff(final String persistenceUnit, final String propertiesCategory) {
try {
final String originalDllGeneration = PropertiesUtil.getProperty(propertiesCategory, PersistenceUnitProperties.DDL_GENERATION);
final String originalJdbcUrl = PropertiesUtil.getProperty(
propertiesCategory, PersistenceUnitProperties.JDBC_URL);
final String refJdbcUrl = PropertiesUtil.getProperty(
propertiesCategory, PersistenceUnitProperties.JDBC_URL) + "ref";
// Construct schema according to liquibase changelog.
PropertiesUtil.setProperty(propertiesCategory, PersistenceUnitProperties.DDL_GENERATION, "none");
final EntityManagerFactory factory = getEntityManagerFactory(persistenceUnit, propertiesCategory);
removeEntityManagerFactory(persistenceUnit, propertiesCategory);
// Empty ref schema
PropertiesUtil.setProperty(propertiesCategory, PersistenceUnitProperties.JDBC_URL, refJdbcUrl);
dropDatabaseObjects(persistenceUnit, propertiesCategory);
// Construct ref schema according to liquibase changelog.
getEntityManagerFactory(persistenceUnit, propertiesCategory).close();
removeEntityManagerFactory(persistenceUnit, propertiesCategory);
// Update ref schema according to JPA changes.
PropertiesUtil.setProperty(propertiesCategory, PersistenceUnitProperties.DDL_GENERATION, "create-or-extend-tables");
PropertiesUtil.setProperty(propertiesCategory, PersistenceUnitProperties.JDBC_URL, refJdbcUrl);
final EntityManagerFactory refFactory = newEntityManagerFactory(persistenceUnit, propertiesCategory);
// Reset original settings.
PropertiesUtil.setProperty(propertiesCategory, PersistenceUnitProperties.DDL_GENERATION, originalDllGeneration);
PropertiesUtil.setProperty(propertiesCategory, PersistenceUnitProperties.JDBC_URL, originalJdbcUrl);
final String changeLog = PropertiesUtil.getProperty(
propertiesCategory, "liquibase-change-log");
final EntityManager entityManager = factory.createEntityManager();
final EntityManager refEntityManager = refFactory.createEntityManager();
entityManager.getTransaction().begin();
refEntityManager.getTransaction().begin();
final Connection connection = entityManager.unwrap(Connection.class);
final Connection refConnection = refEntityManager.unwrap(Connection.class);
final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
final Database refDatabase = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(refConnection));
final Liquibase liquibase = new Liquibase(changeLog, new ClassLoaderResourceAccessor(), database);
final DiffResult diffResult = liquibase.diff(refDatabase, database, CompareControl.STANDARD);
final ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
final PrintStream printStream=new PrintStream(byteArrayOutputStream);
final DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffResult, new DiffOutputControl());
diffToChangeLog.print(printStream);
entityManager.getTransaction().rollback();
refEntityManager.getTransaction().rollback();
return byteArrayOutputStream.toString();
} catch(final Exception e) {
throw new SiteException("Error diffing liquibase and JPA schemas.", e);
}
}
示例8: run
import liquibase.diff.output.changelog.DiffToChangeLog; //导入依赖的package包/类
@Override
public void run(Namespace namespace, Liquibase liquibase) throws Exception {
final Set<Class<? extends DatabaseObject>> compareTypes = new HashSet<>();
if (namespace.getBoolean("columns")) {
compareTypes.add(Column.class);
}
if (namespace.getBoolean("data")) {
compareTypes.add(Data.class);
}
if (namespace.getBoolean("foreign-keys")) {
compareTypes.add(ForeignKey.class);
}
if (namespace.getBoolean("indexes")) {
compareTypes.add(Index.class);
}
if (namespace.getBoolean("primary-keys")) {
compareTypes.add(PrimaryKey.class);
}
if (namespace.getBoolean("sequences")) {
compareTypes.add(Sequence.class);
}
if (namespace.getBoolean("tables")) {
compareTypes.add(Table.class);
}
if (namespace.getBoolean("unique-constraints")) {
compareTypes.add(UniqueConstraint.class);
}
if (namespace.getBoolean("views")) {
compareTypes.add(View.class);
}
final DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(liquibase.getDatabase(), null,
new CompareControl(compareTypes));
final DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffResult, new DiffOutputControl());
final String filename = namespace.getString("output");
if (filename != null) {
try (PrintStream file = new PrintStream(filename, Charsets.UTF_8.name())) {
diffToChangeLog.print(file);
}
} else {
diffToChangeLog.print(System.out);
}
}