Search in sources :

Example 1 with StandardChangeLogHistoryService

use of liquibase.changelog.StandardChangeLogHistoryService in project spring-boot by spring-projects.

the class LiquibaseEndpoint method invoke.

@Override
public List<LiquibaseReport> invoke() {
    List<LiquibaseReport> reports = new ArrayList<>();
    DatabaseFactory factory = DatabaseFactory.getInstance();
    StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
    for (Map.Entry<String, SpringLiquibase> entry : this.liquibases.entrySet()) {
        try {
            DataSource dataSource = entry.getValue().getDataSource();
            JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
            try {
                Database database = factory.findCorrectDatabaseImplementation(connection);
                reports.add(new LiquibaseReport(entry.getKey(), service.queryDatabaseChangeLogTable(database)));
            } finally {
                connection.close();
            }
        } catch (Exception ex) {
            throw new IllegalStateException("Unable to get Liquibase changelog", ex);
        }
    }
    return reports;
}
Also used : LiquibaseReport(org.springframework.boot.actuate.endpoint.LiquibaseEndpoint.LiquibaseReport) ArrayList(java.util.ArrayList) JdbcConnection(liquibase.database.jvm.JdbcConnection) StandardChangeLogHistoryService(liquibase.changelog.StandardChangeLogHistoryService) DataSource(javax.sql.DataSource) DatabaseFactory(liquibase.database.DatabaseFactory) SpringLiquibase(liquibase.integration.spring.SpringLiquibase) Database(liquibase.database.Database) Map(java.util.Map)

Example 2 with StandardChangeLogHistoryService

use of liquibase.changelog.StandardChangeLogHistoryService in project spring-boot by spring-projects.

the class LiquibaseEndpoint method createReport.

private LiquibaseBean createReport(SpringLiquibase liquibase, DatabaseFactory factory) {
    try {
        DataSource dataSource = liquibase.getDataSource();
        JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
        Database database = null;
        try {
            database = factory.findCorrectDatabaseImplementation(connection);
            String defaultSchema = liquibase.getDefaultSchema();
            if (StringUtils.hasText(defaultSchema)) {
                database.setDefaultSchemaName(defaultSchema);
            }
            database.setDatabaseChangeLogTableName(liquibase.getDatabaseChangeLogTable());
            database.setDatabaseChangeLogLockTableName(liquibase.getDatabaseChangeLogLockTable());
            StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
            service.setDatabase(database);
            return new LiquibaseBean(service.getRanChangeSets().stream().map(ChangeSet::new).collect(Collectors.toList()));
        } finally {
            if (database != null) {
                database.close();
            } else {
                connection.close();
            }
        }
    } catch (Exception ex) {
        throw new IllegalStateException("Unable to get Liquibase change sets", ex);
    }
}
Also used : Database(liquibase.database.Database) JdbcConnection(liquibase.database.jvm.JdbcConnection) StandardChangeLogHistoryService(liquibase.changelog.StandardChangeLogHistoryService) RanChangeSet(liquibase.changelog.RanChangeSet) DataSource(javax.sql.DataSource)

Aggregations

DataSource (javax.sql.DataSource)2 StandardChangeLogHistoryService (liquibase.changelog.StandardChangeLogHistoryService)2 Database (liquibase.database.Database)2 JdbcConnection (liquibase.database.jvm.JdbcConnection)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 RanChangeSet (liquibase.changelog.RanChangeSet)1 DatabaseFactory (liquibase.database.DatabaseFactory)1 SpringLiquibase (liquibase.integration.spring.SpringLiquibase)1 LiquibaseReport (org.springframework.boot.actuate.endpoint.LiquibaseEndpoint.LiquibaseReport)1