package jp.terasoluna.batch.functionsample.b005;

import jp.terasoluna.fw.batch.blogic.AbstractTransactionBLogic;
import jp.terasoluna.fw.batch.blogic.vo.BLogicParam;
import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.dao.UpdateDAO;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * ログ関連ジョブのサンプル<br>
 * <br>
 * 
 * 事前準備：EMPLOYEEテーブルを作成しておくこと<br>
 * <br>
 * サンプル内容：AOPによるログ出力サンプル。
 * 
 * 
 */
public class B005001BLogic extends AbstractTransactionBLogic {

	private Log log = LogFactory.getLog(B005001BLogic.class);

	private static final int BATCH_NORMAL_END = 0;

	@Autowired
	@Qualifier("queryDAO")
	private QueryDAO queryDAO = null;

	@Autowired
	@Qualifier("updateDAO")
	private UpdateDAO updateDAO = null;

	@Override
	public int doMain(BLogicParam arg0) {

		int count = queryDAO.executeForObject("B005001.selectEmployeeCount",
				null, Integer.class);

		B005001Param newUser = new B005001Param();

		newUser.setId(count + 1);
		newUser.setFamilyName("山田");
		newUser.setFirstName("次郎");
		newUser.setAge(45);

		updateDAO.execute("B005001.insertEmployee", newUser);

		return BATCH_NORMAL_END;
	}

}
