package eu.dnetlib.dlms.jdbc.server;

import java.sql.SQLException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Required;

import eu.dnetlib.dlms.jdbc.ContextInterface;
import eu.dnetlib.dlms.jdbc.parser.AbstractParserFactory;

/**
 * Abstract class of the main engine of the system.
 * <p>
 * It has factories to generate parser and executor for the DOL language.
 * </p>
 * 
 * @author alessia
 */
public abstract class AbstractDOLEngine {

	/**
	 * Context of the parsing and executions led by this engine. TODO: remove this property if we decided to associate
	 * the context to the connection instead of the engine.
	 */
	private ContextInterface theContext;
	/**
	 * Factory to create instances of AbstractDOLParser class that will parse statement in DOL.
	 */
	private AbstractParserFactory parserFactory;
	/**
	 * Factory to create instances of AbstractDOLExecuter class that will execute statements in DOL.
	 */
	private AbstractExecuterFactory executerFactory;

	/**
	 * Parses and executes the given string in Doroty language.
	 * 
	 * @param dolString
	 *            the DOL String to parse and execute
	 * @param paramMap
	 *            map of String, ParamInfo. It holds the parameters supplied for the dolString.
	 * @throws SQLException
	 *             parsing or executing the DOL command
	 * @return an AbstractDOLExecuter instance that can be use to retrieve the execution results.
	 */
	public abstract AbstractDOLExecuter execute(String dolString, Map<String, ParamInfo> paramMap) throws SQLException;

	public void setTheContext(final ContextInterface theContext) {
		this.theContext = theContext;
	}

	public ContextInterface getTheContext() {
		return this.theContext;
	}

	public AbstractParserFactory getParserFactory() {
		return this.parserFactory;
	}

	@Required
	public void setParserFactory(final AbstractParserFactory parserFactory) {
		this.parserFactory = parserFactory;
	}

	public AbstractExecuterFactory getExecuterFactory() {
		return this.executerFactory;
	}

	@Required
	public void setExecuterFactory(final AbstractExecuterFactory executerFactory) {
		this.executerFactory = executerFactory;
	}

}
