本文整理汇总了Java中liquibase.diff.DiffResult类的典型用法代码示例。如果您正苦于以下问题:Java DiffResult类的具体用法?Java DiffResult怎么用?Java DiffResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiffResult类属于liquibase.diff包,在下文中一共展示了DiffResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recordSchemaDifferencesBetweenHbm2ddlAndLiquibase
import liquibase.diff.DiffResult; //导入依赖的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: doGenerateChangeLog
import liquibase.diff.DiffResult; //导入依赖的package包/类
public static void doGenerateChangeLog(String changeLogFile, Database originalDatabase, String defaultSchemaName, String diffTypes, String author, String context, String dataDir) throws DatabaseException, IOException, ParserConfigurationException {
Diff diff = new Diff(originalDatabase, defaultSchemaName);
diff.setDiffTypes(diffTypes);
diff.addStatusListener(new OutDiffStatusListener());
DiffResult diffResult = diff.compare();
diffResult.setChangeSetAuthor(author);
diffResult.setChangeSetContext(context);
diffResult.setDataDir(dataDir);
if (StringUtils.trimToNull(changeLogFile) != null) {
diffResult.printChangeLog(changeLogFile, originalDatabase);
} else {
PrintStream outputStream = System.out;
diffResult.printChangeLog(outputStream, originalDatabase);
}
}
示例3: run
import liquibase.diff.DiffResult; //导入依赖的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);
}
}
}
示例4: testDiff
import liquibase.diff.DiffResult; //导入依赖的package包/类
@Test
public void testDiff() throws Exception {
if (database == null) {
return;
}
runCompleteChangeLog();
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, database, new CompareControl());
try {
assertTrue(diffResult.areEqual());
} catch (AssertionError e) {
new DiffToReport(diffResult, System.err).print();
throw e;
}
}
示例5: diff
import liquibase.diff.DiffResult; //导入依赖的package包/类
/**
* Compare 2 databases using diff liquibase function
*
* @param paasTestDbUrl
* @param paasTestDbUser
* @param paasTestDbPassword
* @param paasTestDb2Url
* @param paasTestDb2User
* @param paasTestDb2Password
* @return SimpleDiffResult containing a flag indicating if diffreneces have been found and a text representation of those differences
* @throws SQLException
* @throws LiquibaseException
* @throws IOException
* @throws ParserConfigurationException
*/
public DiffResult diff(String paasTestDbUrl, String paasTestDbUser, String paasTestDbPassword, String paasTestDb2Url, String paasTestDb2User,
String paasTestDb2Password) throws SQLException, LiquibaseException, IOException, ParserConfigurationException {
logger.debug("Running liquibase diff between db: " + paasTestDbUrl + " and db: " + paasTestDb2Url);
Database referenceDatabase = null;
Database targetDatabase = null;
try {
referenceDatabase = createDatabase(paasTestDbUrl, paasTestDbUser, paasTestDbPassword);
targetDatabase = createDatabase(paasTestDb2Url, paasTestDb2User, paasTestDb2Password);
final DiffGeneratorFactory generatorFactory = DiffGeneratorFactory.getInstance();
final CompareControl compareControl = new CompareControl();
final DiffResult diffResult = generatorFactory.compare(referenceDatabase, targetDatabase, compareControl);
boolean ignoreDefaultValueDifference = false;
if (ignoreDefaultValueDifference) {
Map<DatabaseObject, ObjectDifferences> changedObjects = diffResult.getChangedObjects();
for (DatabaseObject changedDbObject : changedObjects.keySet()) {
ObjectDifferences objectDifferences = changedObjects.get(changedDbObject);
if (objectDifferences.removeDifference("defaultValue")) {
logger.info("Ignoring default value for {}", changedDbObject.toString());
}
if (!objectDifferences.hasDifferences()) {
logger.info("removing {}, no difference left.", changedDbObject.toString());
changedObjects.remove(objectDifferences);
}
}
}
return diffResult;
} finally {
closeDatabase(referenceDatabase);
closeDatabase(targetDatabase);
}
}
示例6: doDiff
import liquibase.diff.DiffResult; //导入依赖的package包/类
public static void doDiff(Database referenceDatabase, Database targetDatabase) throws DatabaseException {
Diff diff = new Diff(referenceDatabase, targetDatabase);
diff.addStatusListener(new OutDiffStatusListener());
DiffResult diffResult = diff.compare();
System.out.println("");
System.out.println("Diff Results:");
diffResult.printResult(System.out);
}
示例7: doDiffToChangeLog
import liquibase.diff.DiffResult; //导入依赖的package包/类
public static void doDiffToChangeLog(String changeLogFile,
Database referenceDatabase,
Database targetDatabase)
throws DatabaseException, IOException, ParserConfigurationException {
Diff diff = new Diff(referenceDatabase, targetDatabase);
diff.addStatusListener(new OutDiffStatusListener());
DiffResult diffResult = diff.compare();
if (changeLogFile == null) {
diffResult.printChangeLog(System.out, targetDatabase);
} else {
diffResult.printChangeLog(changeLogFile, targetDatabase);
}
}
示例8: outputDiff
import liquibase.diff.DiffResult; //导入依赖的package包/类
@Override
protected void outputDiff(PrintStream writer, DiffResult diffResult, Database targetDatabase) throws Exception {
if (getChangeLogFile() == null) {
diffResult.printChangeLog(writer, targetDatabase);
} else {
diffResult.printChangeLog(getChangeLogFile(), targetDatabase);
}
}
示例9: execute
import liquibase.diff.DiffResult; //导入依赖的package包/类
@Override
public void execute() throws BuildException {
super.execute();
Liquibase liquibase = null;
try {
PrintStream writer = createPrintStream();
if (writer == null) {
throw new BuildException("generateChangeLog requires outputFile to be set");
}
liquibase = createLiquibase();
Database database = liquibase.getDatabase();
Diff diff = new Diff(database, getDefaultSchemaName());
if (getDiffTypes() != null) {
diff.setDiffTypes(getDiffTypes());
}
// diff.addStatusListener(new OutDiffStatusListener());
DiffResult diffResult = diff.compare();
diffResult.setDataDir(getDataDir());
if (getChangeLogFile() == null) {
diffResult.printChangeLog(writer, database);
} else {
diffResult.printChangeLog(getChangeLogFile(), database);
}
writer.flush();
writer.close();
} catch (Exception e) {
throw new BuildException(e);
} finally {
closeDatabase(liquibase);
}
}
示例10: testDiffExternalForeignKeys
import liquibase.diff.DiffResult; //导入依赖的package包/类
/**
* Test that diff is capable to detect foreign keys to external schemas that doesn't appear in the changelog
*/
@Test
public void testDiffExternalForeignKeys() throws Exception {
if (database == null) {
return;
}
Liquibase liquibase = createLiquibase(externalfkInitChangeLog);
liquibase.update(contexts);
DiffResult diffResult = liquibase.diff(database, null, new CompareControl());
DiffResultAssert.assertThat(diffResult).containsMissingForeignKeyWithName("fk_person_country");
}
示例11: generateChangeLog_noChanges
import liquibase.diff.DiffResult; //导入依赖的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());
}
示例12: generateMigrations
import liquibase.diff.DiffResult; //导入依赖的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;
}
示例13: hasDifference
import liquibase.diff.DiffResult; //导入依赖的package包/类
private boolean hasDifference(DiffResult diffResult) {
if (diffResult == null) {
return false;
}
return diffResult.getChangedObjects().size() > 0 || diffResult.getMissingObjects().size() > 0 || diffResult.getUnexpectedObjects().size() > 0;
}
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:7,代码来源:CompareChangeLogWithHibernateAutoCreateIT.java
示例14: diff
import liquibase.diff.DiffResult; //导入依赖的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);
}
}
示例15: outputDiff
import liquibase.diff.DiffResult; //导入依赖的package包/类
protected void outputDiff(PrintStream writer, DiffResult diffResult, Database targetDatabase) throws Exception {
diffResult.printResult(writer);
}