Search in sources :

Example 11 with TransactionTemplate

use of org.flywaydb.core.internal.util.jdbc.TransactionTemplate in project flyway by flyway.

the class Flyway method info.

/**
     * <p>Retrieves the complete information about all the migrations including applied, pending and current migrations with
     * details and status.</p>
     * <img src="https://flywaydb.org/assets/balsamiq/command-info.png" alt="info">
     *
     * @return All migrations sorted by version, oldest first.
     * @throws FlywayException when the info retrieval failed.
     */
public MigrationInfoService info() {
    return execute(new Command<MigrationInfoService>() {

        public MigrationInfoService execute(final Connection connectionMetaDataTable, MigrationResolver migrationResolver, MetaDataTable metaDataTable, final DbSupport dbSupport, final Schema[] schemas, FlywayCallback[] flywayCallbacks) {
            try {
                for (final FlywayCallback callback : flywayCallbacks) {
                    new TransactionTemplate(connectionMetaDataTable).execute(new Callable<Object>() {

                        @Override
                        public Object call() throws SQLException {
                            dbSupport.changeCurrentSchemaTo(schemas[0]);
                            callback.beforeInfo(connectionMetaDataTable);
                            return null;
                        }
                    });
                }
                MigrationInfoServiceImpl migrationInfoService = new MigrationInfoServiceImpl(migrationResolver, metaDataTable, target, outOfOrder, true, true, true);
                migrationInfoService.refresh();
                for (final FlywayCallback callback : flywayCallbacks) {
                    new TransactionTemplate(connectionMetaDataTable).execute(new Callable<Object>() {

                        @Override
                        public Object call() throws SQLException {
                            dbSupport.changeCurrentSchemaTo(schemas[0]);
                            callback.afterInfo(connectionMetaDataTable);
                            return null;
                        }
                    });
                }
                return migrationInfoService;
            } finally {
                dbSupport.restoreCurrentSchema();
            }
        }
    });
}
Also used : MigrationInfoServiceImpl(org.flywaydb.core.internal.info.MigrationInfoServiceImpl) MigrationInfoService(org.flywaydb.core.api.MigrationInfoService) MetaDataTable(org.flywaydb.core.internal.metadatatable.MetaDataTable) Schema(org.flywaydb.core.internal.dbsupport.Schema) Connection(java.sql.Connection) TransactionTemplate(org.flywaydb.core.internal.util.jdbc.TransactionTemplate) Callable(java.util.concurrent.Callable) FlywayCallback(org.flywaydb.core.api.callback.FlywayCallback) SqlScriptFlywayCallback(org.flywaydb.core.internal.callback.SqlScriptFlywayCallback) DbSupport(org.flywaydb.core.internal.dbsupport.DbSupport) MigrationResolver(org.flywaydb.core.api.resolver.MigrationResolver) CompositeMigrationResolver(org.flywaydb.core.internal.resolver.CompositeMigrationResolver)

Aggregations

TransactionTemplate (org.flywaydb.core.internal.util.jdbc.TransactionTemplate)11 SQLException (java.sql.SQLException)7 FlywayCallback (org.flywaydb.core.api.callback.FlywayCallback)7 StopWatch (org.flywaydb.core.internal.util.StopWatch)6 FlywayException (org.flywaydb.core.api.FlywayException)4 MigrationInfoServiceImpl (org.flywaydb.core.internal.info.MigrationInfoServiceImpl)4 Callable (java.util.concurrent.Callable)2 MigrationVersion (org.flywaydb.core.api.MigrationVersion)2 Schema (org.flywaydb.core.internal.dbsupport.Schema)2 AppliedMigration (org.flywaydb.core.internal.metadatatable.AppliedMigration)2 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 MigrationInfoService (org.flywaydb.core.api.MigrationInfoService)1 MigrationExecutor (org.flywaydb.core.api.resolver.MigrationExecutor)1 MigrationResolver (org.flywaydb.core.api.resolver.MigrationResolver)1 SqlScriptFlywayCallback (org.flywaydb.core.internal.callback.SqlScriptFlywayCallback)1 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)1 FlywaySqlException (org.flywaydb.core.internal.dbsupport.FlywaySqlException)1 SqlScript (org.flywaydb.core.internal.dbsupport.SqlScript)1 MigrationInfoImpl (org.flywaydb.core.internal.info.MigrationInfoImpl)1