com.celum.dbtool.installer.GroovyExecutor Maven / Gradle / Ivy
/*****************************************************************************
* 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 javax.sql.DataSource;
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 variables;
/** database connection */
private final DataSource dataSource;
/**
* Constructor
*/
public GroovyExecutor(DataSource dataSource, Map variables)
{
super(StepType.GROOVY);
this.shell = new GroovyShell();
this.dataSource = dataSource;
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[] {dataSource, variables} );
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy