本文整理汇总了Java中liquibase.changelog.DatabaseChangeLog类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseChangeLog类的具体用法?Java DatabaseChangeLog怎么用?Java DatabaseChangeLog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseChangeLog类属于liquibase.changelog包,在下文中一共展示了DatabaseChangeLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException {
RawSQLChange change = new RawSQLChange();
try {
InputStream sqlStream = resourceAccessor.getResourceAsStream(physicalChangeLogLocation);
String sql = StreamUtil.getStreamContents(sqlStream, null);
change.setSql(sql);
} catch (IOException e) {
throw new ChangeLogParseException(e);
}
change.setResourceAccessor(resourceAccessor);
change.setSplitStatements(false);
change.setStripComments(false);
ChangeSet changeSet = new ChangeSet("raw", "includeAll", false, false, physicalChangeLogLocation, null, null, true);
changeSet.addChange(change);
DatabaseChangeLog changeLog = new DatabaseChangeLog();
changeLog.setPhysicalFilePath(physicalChangeLogLocation);
changeLog.addChangeSet(changeSet);
return changeLog;
}
示例2: check
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
DatabaseConnection connection = database.getConnection();
try {
String result = (String) ExecutorService.getInstance().getExecutor(database).queryForObject(new RawSqlStatement(getSql().replaceFirst(";$","")), String.class);
if (result == null) {
throw new PreconditionFailedException("No rows returned from SQL Precondition", changeLog, this);
}
if (!expectedResult.equals(result)) {
throw new PreconditionFailedException("SQL Precondition failed. Expected '"+expectedResult+"' got '"+result+"'", changeLog, this);
}
} catch (DatabaseException e) {
throw new PreconditionErrorException(e, changeLog, this);
}
}
示例3: check
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
try {
boolean checkPassed;
if (getForeignKeyTableName() == null) {
checkPassed = DatabaseSnapshotGeneratorFactory.getInstance().createSnapshot(database, getSchemaName(), null).getForeignKey(getForeignKeyName()) != null;
} else { //much faster if we can limit to correct table
checkPassed = DatabaseSnapshotGeneratorFactory.getInstance().getGenerator(database).getForeignKeyByForeignKeyTable(getSchemaName(), getForeignKeyTableName(), getForeignKeyName(), database) != null;
}
if (!checkPassed) {
String message = "Foreign Key " + database.escapeStringForDatabase(getForeignKeyName());
if (getForeignKeyTableName() != null) {
message += " on table "+ getForeignKeyTableName();
}
message += " does not exist";
throw new PreconditionFailedException(message, changeLog, this);
}
} catch (DatabaseException e) {
throw new PreconditionErrorException(e, changeLog, this);
}
}
示例4: check
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
DatabaseSnapshot snapshot;
try {
snapshot = DatabaseSnapshotGeneratorFactory.getInstance().createSnapshot(database, getSchemaName(), null);
} catch (DatabaseException e) {
throw new PreconditionErrorException(e, changeLog, this);
}
if (tableName != null) {
if (snapshot.getPrimaryKeyForTable(getTableName()) == null) {
throw new PreconditionFailedException("Primary Key does not exist on "+database.escapeStringForDatabase(getTableName()), changeLog, this);
}
} else if (primaryKeyName != null) {
if (snapshot.getPrimaryKey(getPrimaryKeyName()) == null) {
throw new PreconditionFailedException("Primary Key "+database.escapeStringForDatabase(getPrimaryKeyName())+" does not exist", changeLog, this);
}
} else {
throw new RuntimeException("primaryKeyExists precondition requires a tableName or primaryKeyName");
}
}
示例5: check
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
boolean allPassed = true;
List<FailedPrecondition> failures = new ArrayList<FailedPrecondition>();
for (Precondition precondition : getNestedPreconditions()) {
try {
precondition.check(database, changeLog, changeSet);
} catch (PreconditionFailedException e) {
failures.addAll(e.getFailedPreconditions());
allPassed = false;
break;
}
}
if (!allPassed) {
throw new PreconditionFailedException(failures);
}
}
示例6: check
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
try {
if (!DatabaseSnapshotGeneratorFactory.getInstance().getGenerator(database).hasIndex(getSchemaName(), getTableName(), getIndexName(), database, getColumnNames())) {
String name = "";
if (getIndexName() != null) {
name += database.escapeStringForDatabase(getIndexName());
}
if (StringUtils.trimToNull(getTableName()) != null) {
name += " on "+database.escapeStringForDatabase(getTableName());
if (StringUtils.trimToNull(getColumnNames()) != null) {
name += " columns "+getColumnNames();
}
}
throw new PreconditionFailedException("Index "+ name +" does not exist", changeLog, this);
}
} catch (DatabaseException e) {
throw new PreconditionErrorException(e, changeLog, this);
}
}
示例7: check
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
boolean onePassed = false;
List<FailedPrecondition> failures = new ArrayList<FailedPrecondition>();
for (Precondition precondition : getNestedPreconditions()) {
try {
precondition.check(database, changeLog, changeSet);
onePassed = true;
break;
} catch (PreconditionFailedException e) {
failures.addAll(e.getFailedPreconditions());
}
}
if (!onePassed) {
throw new PreconditionFailedException(failures);
}
}
示例8: parseAndGenerate
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
@Test
public void parseAndGenerate() throws Exception {
if (connection == null) {
return;
}
Database database = liquiBase.getDatabase();
ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
ChangeLogParameters changeLogParameters = new ChangeLogParameters();
DatabaseChangeLog changeLog = ChangeLogParserFactory.getInstance().getParser(changeLogFile, resourceAccessor).parse(changeLogFile,
changeLogParameters, resourceAccessor);
liquiBase.checkLiquibaseTables(false, changeLog, new Contexts(), new LabelExpression());
changeLog.validate(database);
List<ChangeSet> changeSets = changeLog.getChangeSets();
Change change = changeSets.get(0).getChanges().get(0);
Sql[] sql = SqlGeneratorFactory.getInstance().generateSql(change.generateStatements(database)[0], database);
String expected = "DROP SYNONYM new_synonym";
assertEquals(expected, sql[0].toSql());
}
示例9: parseAndGenerate
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
@Test
public void parseAndGenerate() throws Exception {
if (connection == null) {
return;
}
Database database = liquiBase.getDatabase();
ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
ChangeLogParameters changeLogParameters = new ChangeLogParameters();
DatabaseChangeLog changeLog = ChangeLogParserFactory.getInstance().getParser(changeLogFile, resourceAccessor).parse(changeLogFile,
changeLogParameters, resourceAccessor);
liquiBase.checkLiquibaseTables(false, changeLog, new Contexts(), new LabelExpression());
changeLog.validate(database);
List<ChangeSet> changeSets = changeLog.getChangeSets();
Change change = changeSets.get(0).getChanges().get(0);
Sql[] sql = SqlGeneratorFactory.getInstance().generateSql(change.generateStatements(database)[0], database);
String expected = "CREATE SYNONYM new_synonym FOR object";
assertEquals(expected, sql[0].toSql());
}
示例10: createLiquibase
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
protected Liquibase createLiquibase() {
ResourceAccessor resourceAccessor = new ResourceFactoryAccessor();
try {
Database liquibaseDB = createDatabase(dataSource.getConnection(), resourceAccessor);
DatabaseChangeLog changeLog = createDatabaseChangeLog(liquibaseDB, resourceAccessor);
return new Liquibase(changeLog, resourceAccessor, liquibaseDB);
} catch (SQLException | LiquibaseException e) {
throw new RuntimeException("Error creating liquibase", e);
}
}
示例11: createDatabaseChangeLog
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
protected DatabaseChangeLog createDatabaseChangeLog(Database database, ResourceAccessor resourceAccessor) {
DatabaseChangeLog changeLog = new DatabaseChangeLog();
changeLog.setChangeLogParameters(new ChangeLogParameters(database));
changeLogs.forEach(cl -> {
try {
LOGGER.info("Including change log: '{}'", cl.getResourceId());
changeLog.include(cl.getResourceId(), false, resourceAccessor, new ContextExpression());
} catch (LiquibaseException e) {
throw new RuntimeException("Error configuring Liquibase", e);
}
});
return changeLog;
}
示例12: testReadLiquibaseUsePerconaFlagYAML
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
@Test
public void testReadLiquibaseUsePerconaFlagYAML() throws Exception {
DatabaseChangeLog changelog = loadChangeLog("test-changelog.yaml");
Assert.assertEquals(2, changelog.getChangeSets().size());
ChangeSet addColumnChangeset = changelog.getChangeSets().get(1);
Change change = addColumnChangeset.getChanges().get(0);
Assert.assertEquals(PerconaAddColumnChange.class, change.getClass());
Assert.assertNotNull(((PerconaAddColumnChange)change).getUsePercona());
Assert.assertFalse(((PerconaAddColumnChange)change).getUsePercona());
}
示例13: testReadLiquibaseUsePerconaFlagXML
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
@Ignore("The original schema doesn't allow to add arbitrary attributes to the changes")
@Test
public void testReadLiquibaseUsePerconaFlagXML() throws Exception {
DatabaseChangeLog changelog = loadChangeLog("test-changelog.xml");
Assert.assertEquals(2, changelog.getChangeSets().size());
ChangeSet addColumnChangeset = changelog.getChangeSets().get(1);
Change change = addColumnChangeset.getChanges().get(0);
Assert.assertEquals(PerconaAddColumnChange.class, change.getClass());
Assert.assertNotNull(((PerconaAddColumnChange)change).getUsePercona());
Assert.assertFalse(((PerconaAddColumnChange)change).getUsePercona());
}
示例14: testReadLiquibaseUsePerconaFlagXMLPercona
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
@Test
public void testReadLiquibaseUsePerconaFlagXMLPercona() throws Exception {
DatabaseChangeLog changelog = loadChangeLog("test-changelog-percona.xml");
Assert.assertEquals(2, changelog.getChangeSets().size());
ChangeSet addColumnChangeset = changelog.getChangeSets().get(1);
Change change = addColumnChangeset.getChanges().get(0);
Assert.assertEquals(PerconaAddColumnChange.class, change.getClass());
Assert.assertNotNull(((PerconaAddColumnChange)change).getUsePercona());
Assert.assertFalse(((PerconaAddColumnChange)change).getUsePercona());
}
示例15: parseAndGenerate
import liquibase.changelog.DatabaseChangeLog; //导入依赖的package包/类
@Test
public void parseAndGenerate() throws Exception {
Database database = liquiBase.getDatabase();
ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
ChangeLogParameters changeLogParameters = new ChangeLogParameters();
DatabaseChangeLog changeLog = ChangeLogParserFactory.getInstance().getParser( changeLogFile, resourceAccessor ).parse( changeLogFile, changeLogParameters, resourceAccessor );
liquiBase.checkLiquibaseTables( true, changeLog, new Contexts() );
changeLog.validate( database );
List<ChangeSet> changeSets = changeLog.getChangeSets();
List<String> expectedQuery = new ArrayList<String>();
expectedQuery.add( String.format( "CREATE OR REPLACE VIEW %s.myview1 AS select 1 as One from dual", database.getLiquibaseSchemaName() ) );
expectedQuery.add( String.format( "CREATE OR REPLACE VIEW %s.myview2 AS select * from mytable", database.getLiquibaseSchemaName() ) );
expectedQuery.add( String.format( "CREATE OR REPLACE VIEW %s.myview2 AS select * from mytable where rownum = 1", database.getLiquibaseSchemaName() ) );
expectedQuery.add( String.format( "CREATE OR REPLACE VIEW %s.myview4 AS select 1 as One from dual", database.getLiquibaseSchemaName() ) );
expectedQuery.add( String.format( "CREATE OR REPLACE VIEW %s.myview3 AS select * from mytable", database.getLiquibaseSchemaName() ) );
expectedQuery.add( String.format( "CREATE OR REPLACE VIEW %s.myview3 AS select * from mytable where one like '%%'", database.getLiquibaseSchemaName() ) );
expectedQuery.add( String.format( "Drop materialized view myview2" ) );
int i = 0;
for ( ChangeSet changeSet : changeSets ) {
for ( Change change : changeSet.getChanges() ) {
Sql[] sql = SqlGeneratorFactory.getInstance().generateSql( change.generateStatements( database )[0], database );
if ( change instanceof CreateFlexibleViewChange ) {
for ( Sql s : sql ) {
System.out.println( "--------------------------------------------------------------------------------------------------------" );
System.out.println( "ACTUAL: " + s.toSql() );
System.out.println( "EXPECT: " + expectedQuery.get( i ) );
assertEquals( expectedQuery.get( i ), s.toSql() );
i++;
}
}
}
}
}