All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jpattern.orm.script.ScriptExecutor Maven / Gradle / Ivy

There is a newer version: 3.5.1
Show newest version
package com.jpattern.orm.script;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

import com.jpattern.logger.ILogger;
import com.jpattern.orm.exception.OrmException;
import com.jpattern.orm.logger.OrmLogger;
import com.jpattern.orm.session.SessionSqlPerformer;

/**
 * 
 * @author Francesco Cina
 *
 * 02/lug/2011
 */
public class ScriptExecutor implements IScriptExecutor {

	private final SessionSqlPerformer session;
	private final ILogger logger;

	public ScriptExecutor(SessionSqlPerformer session) {
		this.session = session;
		logger = OrmLogger.getOrmLogger(getClass());
	}
	
	@Override
	public void execute(String script) throws OrmException {
		Charset charset = Charset.defaultCharset();
		InputStream is = new ByteArrayInputStream(script.getBytes(charset));
		try {
			execute(is, charset);
		} catch (IOException e) {
			throw new OrmException(e);
		}
	}

	@Override
	public void execute(InputStream scriptStream) throws IOException, OrmException {
		execute(scriptStream, Charset.defaultCharset());
	}

	@Override
	public void execute(InputStream scriptStream, Charset charset) throws IOException, OrmException {
		logger.info("execute", "Begin script execution");
		IParser parser = new StreamParser(scriptStream, true, charset);
		SessionParserCallback spc = new SessionParserCallback(session);
		parser.parse(spc);
		logger.debug("execute", "End script execution");
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy