/*****************************************************************************
* 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.sql.LogInterceptor;
import com.celum.dbtool.sql.Sql;
import com.celum.dbtool.sql.SqlQueryStrategy;
import com.celum.dbtool.sql.VelocityInterceptor;
import com.celum.dbtool.step.DbStep;
import com.celum.dbtool.step.StepType;
import java.sql.Connection;
import java.util.Map;
import java.util.logging.Logger;
/**
* Implementation executes SQL steps.
*/
public class SqlExecutor extends Executor
{
/** logger */
private static Logger LOG = Logger.getLogger(SqlExecutor.class.getName());
/** holds all variables with values */
private final Map<String, Object> variables;
/** database connection */
private final Connection dbConnection;
/**
* Constructor
*/
public SqlExecutor(Connection dbConnection, Map<String, Object> variables)
{
super(StepType.SQL);
this.variables = variables;
this.dbConnection = dbConnection;
}
/**
*
* @param step
*/
@Override
public void execute(DbStep step)
{
LOG.info("[SQL STEP]:" + step.getName() + " (" + step.getVersion() + ")");
Sql.fromReader(step.getStepReader())
.interceptingWith(new VelocityInterceptor(variables), new LogInterceptor())
.execute(dbConnection);
}
}