Package com.celum.dbtool.installer

Source Code of com.celum.dbtool.installer.GroovyExecutor

/*****************************************************************************
* Copyright 2013 celum Slovakia s r.o.
*
* 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 com.celum.dbtool.installer;

import com.celum.dbtool.step.DbStep;
import com.celum.dbtool.step.StepType;
import groovy.lang.GroovyShell;
import groovy.lang.Script;

import java.io.Reader;
import java.sql.Connection;
import java.util.Map;
import java.util.logging.Logger;

/**
* This executor is attached to StepType.GROOVY and executes the
* groovy scripts
*/
public class GroovyExecutor extends Executor
{
    /** logger */
    private static Logger LOG = Logger.getLogger(GroovyExecutor.class.getName());

    /** groovy shell executes the groovy scripts */
    private final GroovyShell shell;

    /** determines entry point in groovy scripts */
    public final static String GROOVY_DBMAIN = "dbmain";

    /** holds all variables with values */
    private final Map<String, Object> variables;

    /** database connection */
    private final Connection dbConnection;


    /**
     * Constructor
     */
    public GroovyExecutor(Connection dbConnection, Map<String, Object> variables)
    {
        super(StepType.GROOVY);
        this.shell = new GroovyShell();
        this.dbConnection = dbConnection;
        this.variables = variables;
    }


    /**
     * executes the Groovy script
     */
    @Override
    public void execute(DbStep step)
    {
        LOG.info("[GROOVY STEP]:" + step.getName() + " (" + step.getVersion() + ")");
        Reader scriptReader = step.getStepReader();
        Script s = shell.parse(scriptReader);
        s.invokeMethod(GROOVY_DBMAIN, new Object[] {dbConnection, variables} );
    }
}
TOP

Related Classes of com.celum.dbtool.installer.GroovyExecutor

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.