Package com.celum.dbtool.mojo

Source Code of com.celum.dbtool.mojo.MigrateMojo

package com.celum.dbtool.mojo;

import com.celum.dbtool.Db;
import com.celum.dbtool.resource.DbStepResource;
import com.celum.dbtool.resource.DirResource;
import com.celum.dbtool.resource.PackageResource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import java.io.File;

/**
* @author Zdenko Vrabel (zdenko.vrabel@celum.com)
*
* @goal migrate
*/
public class MigrateMojo extends AbstractDbMojo
{

    /**
     * @parameter default-value="${basedir}/src/main/sql"
     */
    protected File migrationScripts;


    /**
     * @parameter
     */
    protected String migrationPackage;


    /**
     * @parameter default-value="PATCH"
     */
    protected String patchTable;


    /**
     * @parameter default-value="true"
     */
    protected boolean selfInitEnabled;


    @Override
    public void execute() throws MojoExecutionException, MojoFailureException
    {
        try {
            registerVersionFactoryFromSettings();
            Db.withJdbcConnection(getConnection(appAccount))
              .createDefaultMigrationConfiguration(this.patchTable)
              .withSelfInitIf(this.selfInitEnabled)
              .andDbSteps(getResource())
              .patch();
        } catch (Exception e) {
            getLog().error(e);
        }
    }


    private DbStepResource getResource()
    {
        if (migrationPackage != null && !migrationPackage.isEmpty()) {
            return new PackageResource(migrationPackage, getClassLoaderWithCompiledClasses());
        } else {
            return new DirResource(migrationScripts);
        }
    }
}
TOP

Related Classes of com.celum.dbtool.mojo.MigrateMojo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.