/*
 * MosP - Mind Open Source Project    http://www.mosp.jp/
 * Copyright (C) MIND Co., Ltd.       http://www.e-mind.co.jp/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jp.mosp.workflow.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.google.appengine.api.datastore.Query;

import jp.cloudzero.mosp.exception.CloudzeroUnsupportedException;
import jp.getset.gae.bigtable.PreparedStatement;
import jp.mosp.common.common.BaseDao;
import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospException;
import jp.mosp.kintai.common.dao.CtWorkflowDao;
import jp.mosp.workflow.dto.KtHolidayRequestDto;

/**
 * KT_HOLIDAY_REQUEST(休暇申請テーブル)のDAOクラス 。
 */
public class KtHolidayRequestDao extends BaseDao {
	
	// テーブル名及びキー列名
	/**
	 * KT_HOLIDAY_REQUEST(休暇申請テーブル)。
	 */
	public static final String	TABLE				= "KT_HOLIDAY_REQUEST";
	
	/**
	 * KEY_1 = VOUCHER(休暇申請伝票番号)。
	 */
	public static final String	KEY_1				= "VOUCHER";
	
	// 列名
	/**
	 * VOUCHER(休暇申請伝票番号)。
	 */
	public static final String	COL_VOUCHER			= "VOUCHER";
	/**
	 * WORKFLOW(ワークフロー番号)。
	 */
	public static final String	COL_WORKFLOW		= "WORKFLOW";
	/**
	 * K_CODE(社員コード)。
	 */
	public static final String	COL_K_CODE			= "K_CODE";
	/**
	 * HOLIDAY_DATE(休暇日)。
	 */
	public static final String	COL_HOLIDAY_DATE	= "HOLIDAY_DATE";
	/**
	 * START_TIME(休暇開始時間)。
	 */
	public static final String	COL_START_TIME		= "START_TIME";
	/**
	 * END_TIME(休暇終了時間)。
	 */
	public static final String	COL_END_TIME		= "END_TIME";
	/**
	 * REASON(休暇理由)。
	 */
	public static final String	COL_REASON			= "REASON";
	/**
	 * HOLIDAY_TYPE(有給区分)。
	 */
	public static final String	COL_HOLIDAY_TYPE	= "HOLIDAY_TYPE";
	/**
	 * OCCUR_DATE_1(発生年月日1)。
	 */
	public static final String	COL_OCCUR_DATE_1	= "OCCUR_DATE_1";
	/**
	 * USE_HOUR_1(利用時間1)。
	 */
	public static final String	COL_USE_TIME_1		= "USE_TIME_1";
	/**
	 * OCCUR_DATE_2(発生年月日2)。
	 */
	public static final String	COL_OCCUR_DATE_2	= "OCCUR_DATE_2";
	/**
	 * USE_HOUR_2(利用時間2)。
	 */
	public static final String	COL_USE_TIME_2		= "USE_TIME_2";
	/**
	 * SUBSTITUTE_DATE(充当日)。
	 */
	public static final String	COL_SUBSTITUTE_DATE	= "SUBSTITUTE_DATE";
	/**
	 * CAUSE_COMMENT(事由)。
	 */
	public static final String	COL_CAUSE_COMMENT	= "CAUSE_COMMENT";
	/**
	 * DELETE_FLAG(削除フラグ)。
	 */
	public static final String	COL_DELETE_FLAG		= "DELETE_FLAG";
	

	/**
	 * コンストラクタ。
	 */
	public KtHolidayRequestDao() {
		super();
		INSERT_DATE = "INSERT_DATE";
		INSERT_USER = "INSERT_USER";
		UPDATE_DATE = "UPDATE_DATE";
		UPDATE_USER = "UPDATE_USER";
	}
	
	/**
	 * 検索結果取得(DTOのList)
	 * @return List 検索リスト
	 * @throws SQLException SQL例外が発生した場合
	 */
	private List<KtHolidayRequestDto> mappingAll() throws SQLException {
		List<KtHolidayRequestDto> all = new ArrayList<KtHolidayRequestDto>();
		while (rs.next()) {
			all.add(mapping());
		}
		return all;
	}
	
	/**
	 * 検索結果取得(DTO)
	 * @return CtHolidayRequestDto CT_HOLIDAY_REQUESTレコード
	 * @throws SQLException SQL例外が発生した場合
	 */
	private KtHolidayRequestDto mapping() throws SQLException {
		KtHolidayRequestDto dto = new KtHolidayRequestDto();
		dto.setVoucher(rs.getInt(COL_VOUCHER));
		dto.setWorkflow(rs.getLong(COL_WORKFLOW));
		dto.setKCode(rs.getString(COL_K_CODE));
		dto.setHolidayDate(rs.getDate(COL_HOLIDAY_DATE));
		dto.setStartTime(rs.getInt(COL_START_TIME));
		dto.setEndTime(rs.getInt(COL_END_TIME));
		dto.setReason(rs.getString(COL_REASON));
		dto.setHolidayType(rs.getString(COL_HOLIDAY_TYPE));
		dto.setOccurDate1(rs.getString(COL_OCCUR_DATE_1));
		dto.setUseTime1(rs.getInt(COL_USE_TIME_1));
		dto.setOccurDate2(rs.getString(COL_OCCUR_DATE_2));
		dto.setUseTime2(rs.getInt(COL_USE_TIME_2));
		dto.setSubstituteDate(rs.getString(COL_SUBSTITUTE_DATE));
		dto.setCauseComment(rs.getString(COL_CAUSE_COMMENT));
		dto.setDeleteFlag(rs.getInt(COL_DELETE_FLAG));
		mappingCommonInfo(dto);
		return dto;
	}
	
	/**
	 * 全データ取得
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findAll() throws SQLException, IllegalAccessException, NoSuchFieldException {
		try {
			prepareStatement(getSelectQuery(getClass()) + getOrderForKey(getClass()));
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * キーによるデータ取得
	 * @param voucher 休暇申請伝票番号
	 * @return CtHolidayRequestDto 検索結果(DTO)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public KtHolidayRequestDto findForKey(int voucher) throws SQLException, IllegalAccessException,
			NoSuchFieldException {
		try {
			index = 1;
			prepareStatement(getSelectQuery(getClass()) + getConditionForKey(getClass()));
			setParam(index++, voucher);
			executeQuery();
			KtHolidayRequestDto dto = null;
			if (rs.next()) {
				dto = mapping();
				mappingCommonInfo(dto);
			}
			return dto;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * キーによる行ロック取得
	 * @param voucher 休暇申請伝票番号
	 * @return CtHolidayRequestDto 検索結果(DTO)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public KtHolidayRequestDto findForUpdate(int voucher) throws SQLException, IllegalAccessException,
			NoSuchFieldException {
		try {
			index = 1;
			prepareStatement(getSelectQuery(getClass()) + getConditionForKey(getClass()) + getForUpdate());
			setParam(index++, voucher);
			executeQuery();
			KtHolidayRequestDto dto = null;
			if (rs.next()) {
				dto = mapping();
				mappingCommonInfo(dto);
			}
			return dto;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param voucher 休暇申請伝票番号
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findForCondition(int voucher) throws SQLException, IllegalAccessException,
			NoSuchFieldException {
		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append(" WHERE ");
		sb.append(COL_VOUCHER);
		sb.append(" = ? ");
		this.pob.appendWhere(COL_VOUCHER, Query.FilterOperator.EQUAL);
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString() + getOrderForKey(getClass()));
			setParam(index++, voucher);
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param kCode 対象社員コード
	 * @param startDate 対象開始年月日
	 * @param endDate 対象終了年月日
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findForCondition(String kCode, Date startDate, Date endDate) throws SQLException,
			IllegalAccessException, NoSuchFieldException {
		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append(" WHERE ");
		sb.append(COL_DELETE_FLAG);
		sb.append(" = " + MospConst.DELETE_FLAG_OFF);
		sb.append(" AND ");
		sb.append(COL_K_CODE);
		sb.append(" = ? ");
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" >= ? ");
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" <= ? ");
		this.pob.appendWhere(COL_DELETE_FLAG, Query.FilterOperator.EQUAL, MospConst.DELETE_FLAG_OFF);
		this.pob.appendWhere(COL_K_CODE, Query.FilterOperator.EQUAL);
		this.pob.appendWhere(COL_HOLIDAY_DATE, Query.FilterOperator.GREATER_THAN_OR_EQUAL);
		this.pob.appendWhere(COL_HOLIDAY_DATE, Query.FilterOperator.LESS_THAN_OR_EQUAL);
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString() + getOrderForKey(getClass()));
			setParam(index++, kCode);
			setParam(index++, startDate);
			setParam(index++, endDate);
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param kCode 対象社員コード
	 * @param startDate 対象開始年月日
	 * @param endDate 対象終了年月日
	 * @param layer 
	 * @param status 
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findForCondition(String kCode, Date startDate, Date endDate, int layer,
			String status) throws SQLException, IllegalAccessException, NoSuchFieldException {
		throw new CloudzeroUnsupportedException();
/*		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append(" WHERE ");
		sb.append(COL_DELETE_FLAG);
		sb.append(" = " + MospConst.DELETE_FLAG_OFF);
		sb.append(" AND ");
		sb.append(COL_K_CODE);
		sb.append(" = ? ");
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" >= ? ");
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" <= ? ");
		this.pob.appendWhere(COL_DELETE_FLAG, Query.FilterOperator.EQUAL, MospConst.DELETE_FLAG_OFF);
		this.pob.appendWhere(COL_K_CODE, Query.FilterOperator.EQUAL);
		this.pob.appendWhere(COL_HOLIDAY_DATE, Query.FilterOperator.GREATER_THAN_OR_EQUAL);
		this.pob.appendWhere(COL_HOLIDAY_DATE, Query.FilterOperator.LESS_THAN_OR_EQUAL);
		if (status.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_WORKFLOW);
			sb.append(" IN (");
			sb.append(CtWorkflowDao.getSubQueryWorkflowStatus());
			sb.append(") ");
		}
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString() + getOrderForKey(getClass()));
			setParam(index++, kCode);
			setParam(index++, startDate);
			setParam(index++, endDate);
			if (status.length() != 0) {
				setParam(index++, layer);
				setParam(index++, status);
			}
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}*/
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param kCode 対象社員コード
	 * @param reason 
	 * @param startDate 対象開始年月日
	 * @param endDate 対象終了年月日
	 * @param layer 
	 * @param status 
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findForCondition(String kCode, String reason, Date startDate, Date endDate,
			int layer, String status) throws SQLException, IllegalAccessException, NoSuchFieldException {
		throw new CloudzeroUnsupportedException();
/*		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append(" WHERE ");
		sb.append(COL_DELETE_FLAG);
		sb.append(" = " + MospConst.DELETE_FLAG_OFF);
		sb.append(" AND ");
		sb.append(COL_K_CODE);
		sb.append(" = ? ");
		sb.append(" AND ");
		sb.append(COL_REASON);
		sb.append(" = ? ");
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" >= ? ");
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" <= ? ");
		if (status.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_WORKFLOW);
			sb.append(" IN (");
			sb.append(CtWorkflowDao.getSubQueryWorkflowStatus());
			sb.append(") ");
		}
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString() + getOrderForKey(getClass()));
			setParam(index++, kCode);
			setParam(index++, reason);
			setParam(index++, startDate);
			setParam(index++, endDate);
			if (status.length() != 0) {
				setParam(index++, layer);
				setParam(index++, status);
			}
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}*/
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param kCode 対象社員コード
	 * @param targetDate 対象年月日
	 * @param reason 対象休暇理由
	 * @param holidayType 対象休暇種類コード
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findForCondition(String kCode, String reason, String holidayType, Date targetDate)
			throws SQLException, IllegalAccessException, NoSuchFieldException {
		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append(" WHERE ");
		sb.append(COL_DELETE_FLAG);
		sb.append(" = " + MospConst.DELETE_FLAG_OFF);
		sb.append(" AND ");
		sb.append(COL_K_CODE);
		sb.append(" = ? ");
		this.pob.appendWhere(COL_DELETE_FLAG, Query.FilterOperator.EQUAL, MospConst.DELETE_FLAG_OFF);
		this.pob.appendWhere(COL_K_CODE, Query.FilterOperator.EQUAL);
		if (reason.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_REASON);
			sb.append(" = ? ");
			this.pob.appendWhere(COL_REASON, Query.FilterOperator.EQUAL);
		}
		if (holidayType.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_HOLIDAY_TYPE);
			sb.append(" = ? ");
			this.pob.appendWhere(COL_HOLIDAY_TYPE, Query.FilterOperator.EQUAL);
		}
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" = ? ");
		this.pob.appendWhere(COL_HOLIDAY_DATE, Query.FilterOperator.EQUAL);
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString() + getOrderForKey(getClass()));
			setParam(index++, kCode);
			if (reason.length() != 0) {
				setParam(index++, reason);
			}
			if (holidayType.length() != 0) {
				setParam(index++, holidayType);
			}
			setParam(index++, targetDate);
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param kCode 対象社員コード
	 * @param startDate 対象開始年月日
	 * @param endDate 対象終了年月日
	 * @param reason 対象休暇理由
	 * @param holidayType 対象休暇種類コード
	 * @param layer 承認階層
	 * @param status 承認状況
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findForCondition(String kCode, Date startDate, Date endDate, String reason,
			String holidayType, int layer, String status) throws SQLException, IllegalAccessException,
			NoSuchFieldException {
		throw new CloudzeroUnsupportedException();
/*		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append(" WHERE ");
		sb.append(COL_DELETE_FLAG);
		sb.append(" = " + MospConst.DELETE_FLAG_OFF);
		sb.append(" AND ");
		sb.append(COL_K_CODE);
		sb.append(" = ? ");
		if (reason.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_REASON);
			sb.append(" = ? ");
		}
		if (holidayType.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_HOLIDAY_TYPE);
			sb.append(" = ? ");
		}
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" >= ? ");
		sb.append(" AND ");
		sb.append(COL_HOLIDAY_DATE);
		sb.append(" <= ? ");
		if (status.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_WORKFLOW);
			sb.append(" IN (");
			sb.append(CtWorkflowDao.getSubQueryWorkflowStatus());
			sb.append(") ");
		}
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString() + getOrderForKey(getClass()));
			setParam(index++, kCode);
			if (reason.length() != 0) {
				setParam(index++, reason);
			}
			if (holidayType.length() != 0) {
				setParam(index++, holidayType);
			}
			setParam(index++, startDate);
			setParam(index++, endDate);
			if (status.length() != 0) {
				setParam(index++, layer);
				setParam(index++, status);
			}
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}*/
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param kCode 対象社員コード
	 * @param holidaydate
	 * @return CtHolidayRequestDto 検索結果(DTO)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public KtHolidayRequestDto findForHolidayDate(String kCode, Date holidaydate) throws SQLException,
			IllegalAccessException, NoSuchFieldException {
		try {
			index = 1;
			StringBuffer sb = new StringBuffer();
			sb.append(" WHERE ");
			sb.append(COL_DELETE_FLAG);
			sb.append(" = " + MospConst.DELETE_FLAG_OFF);
			sb.append(" AND ");
			sb.append(COL_K_CODE);
			sb.append(" = ? ");
			sb.append(" AND ");
			sb.append(COL_HOLIDAY_DATE);
			sb.append(" = ? ");
			this.pob.appendWhere(COL_DELETE_FLAG, Query.FilterOperator.EQUAL, MospConst.DELETE_FLAG_OFF);
			this.pob.appendWhere(COL_K_CODE, Query.FilterOperator.EQUAL);
			this.pob.appendWhere(COL_HOLIDAY_DATE, Query.FilterOperator.EQUAL);
			prepareStatement(getSelectQuery(getClass()) + sb.toString());
			setParam(index++, kCode);
			setParam(index++, holidaydate);
			executeQuery();
			KtHolidayRequestDto dto = null;
			if (rs.next()) {
				dto = mapping();
				mappingCommonInfo(dto);
			}
			return dto;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * 条件文によるデータ取得
	 * @param kCode 対象社員コード
	 * @param reason 
	 * @param yearMonth 
	 * @param layer 
	 * @param status 
	 * @return List 検索結果(DTOのList)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public List<KtHolidayRequestDto> findForOccur(String kCode, String reason, String yearMonth, int layer,
			String status) throws SQLException, IllegalAccessException, NoSuchFieldException {
		throw new CloudzeroUnsupportedException();
/*		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append(" WHERE ");
		sb.append(COL_DELETE_FLAG);
		sb.append(" = " + MospConst.DELETE_FLAG_OFF);
		sb.append(" AND ");
		sb.append(COL_K_CODE);
		sb.append(" = ? ");
		sb.append(" AND ");
		sb.append(COL_REASON);
		sb.append(" = ? ");
		sb.append(" AND ");
		sb.append("(");
		sb.append(COL_OCCUR_DATE_1);
		sb.append(" = ?");
		sb.append(" OR ");
		sb.append(COL_OCCUR_DATE_2);
		sb.append(" = ?");
		sb.append(")");
		if (status.length() != 0) {
			sb.append(" AND ");
			sb.append(COL_WORKFLOW);
			sb.append(" IN (");
			sb.append(CtWorkflowDao.getSubQueryWorkflowStatus());
			sb.append(") ");
		}
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString() + getOrderForKey(getClass()));
			setParam(index++, kCode);
			setParam(index++, reason);
			setParam(index++, yearMonth);
			setParam(index++, yearMonth);
			if (status.length() != 0) {
				setParam(index++, layer);
				setParam(index++, status);
			}
			executeQuery();
			return mappingAll();
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}*/
	}
	
	/**
	 * max値取得
	 * @return String　最大連番
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 */
	public String findForMax() throws SQLException, IllegalAccessException, NoSuchFieldException {
		try {
			String maxVaoucher = "";
			index = 1;
			StringBuffer sb = new StringBuffer();
			sb.append("SELECT MAX(");
			sb.append(COL_VOUCHER);
			sb.append(") FROM ");
			sb.append(TABLE);
			
			this.setPreparedStatement(PreparedStatement.Mode.SELECT);
			this.pob.appendOperationMax(COL_VOUCHER);
			
			prepareStatement(sb.toString());
			executeQuery();
			if (rs.next()) {
				maxVaoucher = String.valueOf(rs.getInt(1));
			}
			return maxVaoucher;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * データ挿入
	 * @param dto 挿入対象DTO
	 * @return int 挿入結果(件数)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 * @throws MospException  	MosP例外処理が発生した場合
	 */
	public int insert(KtHolidayRequestDto dto) throws SQLException, IllegalAccessException, NoSuchFieldException,
			MospException {
		try {
			index = 1;
			prepareStatement(getInsertQuery(getClass()));
			setParams(dto, true);
			executeUpdate();
			chkInsert(1);
			return cnt;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * データ更新
	 * @param dto 更新対象DTO
	 * @return int 更新結果(件数)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 * @throws MospException  	MosP例外処理が発生した場合
	 */
	public int update(KtHolidayRequestDto dto) throws SQLException, IllegalAccessException, NoSuchFieldException,
			MospException {
		try {
			index = 1;
			prepareStatement(getUpdateQuery(getClass()));
			setParams(dto, false);
			setParam(index++, dto.getVoucher());
			executeUpdate();
			chkUpdate(1);
			return cnt;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * データ削除
	 * @param dto 更新対象DTO
	 * @return int 削除結果(件数)
	 * @throws SQLException 			SQL例外が発生した場合
	 * @throws IllegalAccessException 	メソッドにアクセスできない場合
	 * @throws NoSuchFieldException 	フィールドが見つからなかった場合
	 * @throws MospException  	MosP例外処理が発生した場合
	 */
	public int delete(KtHolidayRequestDto dto) throws SQLException, IllegalAccessException, NoSuchFieldException,
			MospException {
		try {
			index = 1;
			prepareStatement(getDeleteQuery(getClass()));
			setParam(index++, dto.getVoucher());
			executeUpdate();
			chkDelete(1);
			return cnt;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
	/**
	 * パラメータ設定
	 * @param dto 更新対象DTO
	 * @param isInsert 挿入文フラグ(true：挿入文、false：更新文)
	 * @throws SQLException SQL例外が発生した場合
	 */
	private void setParams(KtHolidayRequestDto dto, boolean isInsert) throws SQLException {
		setParam(index++, dto.getVoucher());
		setParam(index++, dto.getWorkflow());
		setParam(index++, dto.getKCode());
		setParam(index++, dto.getHolidayDate());
		setParam(index++, dto.getStartTime());
		setParam(index++, dto.getEndTime());
		setParam(index++, dto.getReason());
		setParam(index++, dto.getHolidayType());
		setParam(index++, dto.getOccurDate1());
		setParam(index++, dto.getUseTime1());
		setParam(index++, dto.getOccurDate2());
		setParam(index++, dto.getUseTime2());
		setParam(index++, dto.getSubstituteDate());
		setParam(index++, dto.getCauseComment());
		setParam(index++, dto.getDeleteFlag());
		setCommonParams(isInsert);
	}
	
}
