package org.seasar.dao.impl;

import javax.sql.DataSource;

import org.seasar.dao.CommandContext;
import org.seasar.extension.jdbc.ResultSetFactory;
import org.seasar.extension.jdbc.ResultSetHandler;
import org.seasar.extension.jdbc.SelectHandler;
import org.seasar.extension.jdbc.impl.BasicSelectHandler;

/**
 * @author higa
 *  
 */
public class SelectDynamicCommand extends AbstractDynamicCommand {

	private ResultSetHandler resultSetHandler_;
	private ResultSetFactory resultSetFactory_;

	public SelectDynamicCommand(DataSource dataSource,
			ResultSetHandler resultSetHandler,
			ResultSetFactory resultSetFactory) {

		super(dataSource);
		resultSetHandler_ = resultSetHandler;
		resultSetFactory_ = resultSetFactory;
	}

	public ResultSetHandler getResultSetHandler() {
		return resultSetHandler_;
	}

	public Object execute(Object[] args) {
		CommandContext ctx = apply(args);
		SelectHandler selectHandler = new BasicSelectHandler(getDataSource(),
				ctx.getSql(), resultSetHandler_, resultSetFactory_);
		return selectHandler.execute(ctx.getBindVariables());
	}
}