/*******************************************************************************
*	 All Rights reserved,Copyright (c) K-Opticom 
********************************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：JSYejbKK0501KRCK
*	ソースファイル名：JSYejbKK0501KRCK.java
*	作成者			：EKek0014
*	日付			：2011年12月11日
*＜機能概要＞
*	関連チェック部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	ｖ1.00.00
*
********************************************************************************/

package eo.ejb.cbm.entity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
import com.fujitsu.futurity.model.ejb.common.JSYejbLog;
import com.fujitsu.futurity.model.ejb.common.JSYejbConnection;
import com.fujitsu.futurity.model.ejb.common.StatusCodes;
import com.fujitsu.futurity.model.ejb.common.fw.AgentDispatchContext;
import eo.ejb.common.EventIDList;
import com.fujitsu.futurity.model.ejb.common.fw.KanrenCheckHandler;
import eo.ejb.common.JPCModelCommon;

import com.fujitsu.futurity.model.base.CAANConnectionMgr;
import com.fujitsu.futurity.model.base.CAANJDBCUtil;
import com.fujitsu.futurity.model.base.CAANMsg;
import com.fujitsu.futurity.model.base.CAANRuntimeException;

/**
 * 口座関連チェッククラスです。
 * ＜メソッド一覧＞
 * invoke
 *	execIKK0491D001_8
 *	execIKK0491D004_4
 *	execIKK0491D006_7
 *	execIKK0501D001_1
 *	execIKK0501D001_3
 *	execIKK0501D002_1
 *	execIKK0501D002_2
 *	execIKK0501D003_1
 *	execIKK0501D003_2
 *	execIKK0501D004_1
 *	execIKK0501D004_2
 *	execIKK0501D005_1
 *	execIKK0501D005_2
 *	execIKK0501D006_1
 *	execIKK0501D006_2
 *	execIKK0501D006_3
 *	execIKK1091D001_4
 *
 */

public class JSYejbKK0501KRCK implements KanrenCheckHandler {

	/**
	 * コンストラクタ
	 */

	public JSYejbKK0501KRCK() {
	}

	/**
	 * 口座関連チェックを行います。
	 * 
	 * @param inETMsg エンティティ
	 * @param inContext Agentから渡されたAgentDispatchContext
	 */

	public void invoke(CAANMsg inETMsg, AgentDispatchContext inContext) {

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "call:JSYejbKK0501KRCK.invoke");

		// inETMsgのチェック
		if(inETMsg == null) {
			throw new CAANRuntimeException("inETMsgがnullです。");
		}

		// 振舞IDの取り出し
		String eventID = inETMsg.getString("eventID");
		if(eventID == null) {
			throw new CAANRuntimeException("振舞IDがnullです。");
		}

		// 処理の振り分け
		// イベントの振り分け
		if(eventID.equals(EventIDList.IKK0491D001)){
			/** 請求契約登録振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0491D001_8(inETMsg, inContext, "EA");

		}else if(eventID.equals(EventIDList.IKK0491D004)){
			/** 請求支払先変更振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0491D004_4(inETMsg, inContext, "EA");

		}else if(eventID.equals(EventIDList.IKK0491D006)){
			/** 請求契約登録（予約情報入力）振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0491D006_7(inETMsg, inContext, "EA");

		}else if(eventID.equals(EventIDList.IKK0501D001)){
			/** 口座内容変更振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0501D001_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIKK0501D001_3(inETMsg, inContext, "EB");
			}

		}else if(eventID.equals(EventIDList.IKK0501D002)){
			/** 口振手続キャンセル振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0501D002_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIKK0501D002_2(inETMsg, inContext, "EB");
			}

		}else if(eventID.equals(EventIDList.IKK0501D003)){
			/** 口振審査結果OK登録振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0501D003_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIKK0501D003_2(inETMsg, inContext, "EB");
			}

		}else if(eventID.equals(EventIDList.IKK0501D004)){
			/** 口振審査結果NG登録振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0501D004_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIKK0501D004_2(inETMsg, inContext, "EB");
			}

		}else if(eventID.equals(EventIDList.IKK0501D005)){
			/** 口振手続振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0501D005_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIKK0501D005_2(inETMsg, inContext, "EB");
			}

		}else if(eventID.equals(EventIDList.IKK0501D006)){
			/** 口振審査依頼振舞内部 */
			int Rtn = 0;
			Rtn = execIKK0501D006_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIKK0501D006_2(inETMsg, inContext, "EB");
			}

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIKK0501D006_3(inETMsg, inContext, "EA");
			}

		}else if(eventID.equals(EventIDList.IKK1091D001)){
			/** 進捗登録振舞内部 */
			int Rtn = 0;
			Rtn = execIKK1091D001_4(inETMsg, inContext, "EA");

		}

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "end:JSYejbKK0501KRCK.invoke");

	}

	/**
	 * IKK0491D001_制約ＮＯ8チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0491ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0491D001_8(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0491ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0491ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken3_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_3 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken3_2 == null){
				joken_3 += " IS NULL ";
			}else{
				joken_3 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0491ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_3 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken3_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken3_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0491ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0491ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0491ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0491ETMsg.STATUS)) {
			inETMsg.set(KK0491ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0491D004_制約ＮＯ4チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0491ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0491D004_4(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0491ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0491ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0491ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0491ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0491ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0491ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0491ETMsg.STATUS)) {
			inETMsg.set(KK0491ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0491D006_制約ＮＯ7チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0491ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0491D006_7(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0491ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0491ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken3_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_3 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken3_2 == null){
				joken_3 += " IS NULL ";
			}else{
				joken_3 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0491ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_3 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken3_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken3_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0491ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0491ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0491ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0491ETMsg.STATUS)) {
			inETMsg.set(KK0491ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D001_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D001_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D001_制約ＮＯ3チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D001_3(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)){
				joken2_2 = new String(inETMsg.getObject(KK0501ETMsg.GENE_ADD_DTM).toString());
			}

			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.GENE_ADD_DTM);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA) && !inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(rsltQuery.getLong("CNT")>0){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D002_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D002_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D002_制約ＮＯ2チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D002_2(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)){
				joken2_2 = new String(inETMsg.getObject(KK0501ETMsg.GENE_ADD_DTM).toString());
			}

			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.GENE_ADD_DTM);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA) && !inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(rsltQuery.getLong("CNT")>0){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D003_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D003_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D003_制約ＮＯ2チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D003_2(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)){
				joken2_2 = new String(inETMsg.getObject(KK0501ETMsg.GENE_ADD_DTM).toString());
			}

			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.GENE_ADD_DTM);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA) && !inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(rsltQuery.getLong("CNT")>0){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D004_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D004_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D004_制約ＮＯ2チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D004_2(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)){
				joken2_2 = new String(inETMsg.getObject(KK0501ETMsg.GENE_ADD_DTM).toString());
			}

			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.GENE_ADD_DTM);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA) && !inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(rsltQuery.getLong("CNT")>0){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D005_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D005_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)){
				joken2_2 = new String(inETMsg.getObject(KK0501ETMsg.GENE_ADD_DTM).toString());
			}

			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.GENE_ADD_DTM);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA) && !inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(rsltQuery.getLong("CNT")>0){
						inETMsg.set(KK0501ETMsg.BANK_CD_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D005_制約ＮＯ2チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D005_2(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append(joken_1);

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(rsltQuery.getLong("CNT")>0){
						inETMsg.set(KK0501ETMsg.BANK_CD_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D006_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D006_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D006_制約ＮＯ2チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D006_2(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK0501ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)){
				joken2_2 = new String(inETMsg.getObject(KK0501ETMsg.GENE_ADD_DTM).toString());
			}

			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.GENE_ADD_DTM);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA) && !inETMsg.isNull(KK0501ETMsg.GENE_ADD_DTM)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(rsltQuery.getLong("CNT")>0){
						inETMsg.set(KK0501ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK0501ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK0501D006_制約ＮＯ3チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK0501ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK0501D006_3(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

			// チェック条件定数
			// 制約部品引数定義
			Object joken_1_prm_1 = "KK0501";

			// チェック条件
			if (!inETMsg.isNull(KK0501ETMsg.SEIKY_WAY_NO_KOZA) && !inETMsg.isNull(KK0501ETMsg.UPD_DTM)) { 
			// 判定条件
			if(JPCModelCommon.succeededExclusiveLockForGene(inETMsg, inContext, joken_1_prm_1 ) == false){
					inETMsg.set(KK0501ETMsg.UPD_DTM_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK0501ETMsg.STATUS)) {
			inETMsg.set(KK0501ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IKK1091D001_制約ＮＯ4チェック
	 *
	 * @param inETMsg チェック対象のETMsg(KK1091ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIKK1091D001_4(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(KK0501ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// チェック条件定数
			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(KK1091ETMsg.SEIKY_WAY_NO_KOZA)){
				joken1_2 = new String(inETMsg.getObject(KK1091ETMsg.SEIKY_WAY_NO_KOZA).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.SEIKY_WAY_NO_KOZA);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = KK0501ETMsg.getDBColumnName(KK0501ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}

			// チェック条件
			if (!inETMsg.isNull(KK1091ETMsg.SEIKY_WAY_NO_KOZA)) { 

				// ＳＱＬ文の組み立て
				sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(KK0501ETMsg.getTableName()).append(" WHERE ")
					.append("(" + joken_1 + " AND " + joken_2 + " ) ");

				// ＳＱＬ文の解析
				pstmtQuery = con.prepareStatement(sqlQuery.toString());

				// パラメータの設定
				int para_idx = 1;
				if(joken1_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken1_2);
				}
				if(joken2_2 != null){
					CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken2_2);
				}

				// ＳＱＬ文の実行
				rsltQuery = pstmtQuery.executeQuery();

				if(rsltQuery.next()){
				// 判定条件
					if(!(rsltQuery.getLong("CNT")>0)){
						inETMsg.set(KK1091ETMsg.SEIKY_WAY_NO_KOZA_ERR, errFlag);
						if("W".equals(errFlag.substring(0,1))){
							rtn = StatusCodes.WARNING;
						} else {
							rtn = StatusCodes.RELATION_ERR;
						}
					}
				}

			}

		} catch(SQLException e) {
			inETMsg.set(KK1091ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
			throw new CAANRuntimeException(e);
		} finally {
			// このメソッドで確保した資源の解放
			try {
				if(rsltQuery != null) {
					rsltQuery.close();
				}
				if(pstmtQuery != null) {
					pstmtQuery.close();
				}
				if(con != null) {
					CAANConnectionMgr.getInstance().close(con);
				}
			} catch(SQLException e) {
				inETMsg.set(KK1091ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(KK1091ETMsg.STATUS)) {
			inETMsg.set(KK1091ETMsg.STATUS, rtn);
		}

		return rtn;

	}

}

