Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2010-2016 Boxfuse GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flywaydb.core.internal.command;
import org.flywaydb.core.api.FlywayException;
import org.flywaydb.core.api.MigrationInfo;
import org.flywaydb.core.api.MigrationState;
import org.flywaydb.core.api.MigrationVersion;
import org.flywaydb.core.api.callback.FlywayCallback;
import org.flywaydb.core.api.resolver.MigrationExecutor;
import org.flywaydb.core.api.resolver.MigrationResolver;
import org.flywaydb.core.internal.dbsupport.DbSupport;
import org.flywaydb.core.internal.dbsupport.DbSupportFactory;
import org.flywaydb.core.internal.dbsupport.Schema;
import org.flywaydb.core.internal.info.MigrationInfoImpl;
import org.flywaydb.core.internal.info.MigrationInfoServiceImpl;
import org.flywaydb.core.internal.metadatatable.AppliedMigration;
import org.flywaydb.core.internal.metadatatable.MetaDataTable;
import org.flywaydb.core.internal.util.StopWatch;
import org.flywaydb.core.internal.util.TimeFormat;
import org.flywaydb.core.internal.util.jdbc.TransactionCallback;
import org.flywaydb.core.internal.util.jdbc.TransactionTemplate;
import org.flywaydb.core.internal.util.logging.Log;
import org.flywaydb.core.internal.util.logging.LogFactory;
import java.sql.Connection;
import java.sql.SQLException;
/**
* Main workflow for migrating the database.
*
* @author Axel Fontaine
*/
public class DbMigrate {
private static final Log LOG = LogFactory.getLog(DbMigrate.class);
/**
* The target version of the migration.
*/
private final MigrationVersion target;
/**
* Database-specific functionality.
*/
private final DbSupport dbSupport;
/**
* The database metadata table.
*/
private final MetaDataTable metaDataTable;
/**
* The schema containing the metadata table.
*/
private final Schema schema;
/**
* The migration resolver.
*/
private final MigrationResolver migrationResolver;
/**
* The connection to use.
*/
private final Connection connectionMetaDataTable;
/**
* The connection to use to perform the actual database migrations.
*/
private final Connection connectionUserObjects;
/**
* Flag whether to ignore future migrations or not.
*/
private final boolean ignoreFutureMigrations;
/**
* Flag whether to ignore failed future migrations or not.
*/
private final boolean ignoreFailedFutureMigration;
/**
* Allows migrations to be run "out of order".
*
If you already have versions 1 and 3 applied, and now a version 2 is found,
* it will be applied too instead of being ignored.
*
(default: {@code false})
*/
private final boolean outOfOrder;
/**
* This is a list of callbacks that fire before or after the migrate task is executed.
* You can add as many callbacks as you want. These should be set on the Flyway class
* by the end user as Flyway will set them automatically for you here.
*/
private final FlywayCallback[] callbacks;
/**
* The DB support for the user objects connection.
*/
private final DbSupport dbSupportUserObjects;
/**
* Creates a new database migrator.
*
* @param connectionMetaDataTable The connection to use.
* @param connectionUserObjects The connection to use to perform the actual database migrations.
* @param dbSupport Database-specific functionality.
* @param metaDataTable The database metadata table.
* @param migrationResolver The migration resolver.
* @param target The target version of the migration.
* @param ignoreFutureMigrations Flag whether to ignore future migrations or not.
* @param ignoreFailedFutureMigration Flag whether to ignore failed future migrations or not.
* @param outOfOrder Allows migrations to be run "out of order".
*/
public DbMigrate(Connection connectionMetaDataTable, Connection connectionUserObjects, DbSupport dbSupport,
MetaDataTable metaDataTable, Schema schema, MigrationResolver migrationResolver,
MigrationVersion target, boolean ignoreFutureMigrations, boolean ignoreFailedFutureMigration, boolean outOfOrder,
FlywayCallback[] callbacks) {
this.connectionMetaDataTable = connectionMetaDataTable;
this.connectionUserObjects = connectionUserObjects;
this.dbSupport = dbSupport;
this.metaDataTable = metaDataTable;
this.schema = schema;
this.migrationResolver = migrationResolver;
this.target = target;
this.ignoreFutureMigrations = ignoreFutureMigrations;
this.ignoreFailedFutureMigration = ignoreFailedFutureMigration;
this.outOfOrder = outOfOrder;
this.callbacks = callbacks;
dbSupportUserObjects = DbSupportFactory.createDbSupport(connectionUserObjects, false);
}
/**
* Starts the actual migration.
*
* @return The number of successfully applied migrations.
* @throws FlywayException when migration failed.
*/
public int migrate() throws FlywayException {
try {
for (final FlywayCallback callback : callbacks) {
new TransactionTemplate(connectionUserObjects).execute(new TransactionCallback