/*******************************************************************************
*	 All Rights reserved,Copyright (c) K-Opticom 
********************************************************************************
*＜プログラム内容＞
*	システム名		：eo顧客基幹システム
*	モジュール名	：JSYejbZM0031KRCK
*	ソースファイル名：JSYejbZM0031KRCK.java
*	作成者			：EK909281
*	日付			：2012年09月05日
*＜機能概要＞
*	関連チェック部品です。
*＜修正履歴＞
*	バージョン	修正日		修正者		修正内容
*	ｖ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
 *	execIZM0021D001_3
 *	execIZM0031C001_1
 *	execIZM0031C001_2
 *	execIZM0031C002_1
 *	execIZM0031C002_2
 *	execIZM0031D001_1
 *	execIZM0041C001_13
 *	execIZM0041C001_14
 *	execIZM0041D001_13
 *	execIZM0041D001_14
 *
 */

public class JSYejbZM0031KRCK implements KanrenCheckHandler {

	/**
	 * コンストラクタ
	 */

	public JSYejbZM0031KRCK() {
	}

	/**
	 * ロール関連チェックを行います。
	 * 
	 * @param inETMsg エンティティ
	 * @param inContext Agentから渡されたAgentDispatchContext
	 */

	public void invoke(CAANMsg inETMsg, AgentDispatchContext inContext) {

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "call:JSYejbZM0031KRCK.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.IZM0021D001)){
			/** ロール_権限登録振舞内部 */
			int Rtn = 0;
			Rtn = execIZM0021D001_3(inETMsg, inContext, "EC");

		}else if(eventID.equals(EventIDList.IZM0031C001)){
			/** ロール変更振舞内部 */
			int Rtn = 0;
			Rtn = execIZM0031C001_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIZM0031C001_2(inETMsg, inContext, "EB");
			}

		}else if(eventID.equals(EventIDList.IZM0031C002)){
			/** ロール削除振舞内部 */
			int Rtn = 0;
			Rtn = execIZM0031C002_1(inETMsg, inContext, "EA");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIZM0031C002_2(inETMsg, inContext, "EB");
			}

		}else if(eventID.equals(EventIDList.IZM0031D001)){
			/** ロール登録振舞内部 */
			int Rtn = 0;
			Rtn = execIZM0031D001_1(inETMsg, inContext, "EA");

		}else if(eventID.equals(EventIDList.IZM0041C001)){
			/** 権限グループ変更振舞内部 */
			int Rtn = 0;
			Rtn = execIZM0041C001_13(inETMsg, inContext, "EM");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIZM0041C001_14(inETMsg, inContext, "EN");
			}

		}else if(eventID.equals(EventIDList.IZM0041D001)){
			/** 権限グループ登録振舞内部 */
			int Rtn = 0;
			Rtn = execIZM0041D001_13(inETMsg, inContext, "EM");

			if(Rtn <= StatusCodes.WARNING){
				Rtn = execIZM0041D001_14(inETMsg, inContext, "EN");
			}

		}

		JSYejbLog.println(JSYejbLog.DEBUG, getClass(), "end:JSYejbZM0031KRCK.invoke");

	}

	/**
	 * IZM0021D001_制約ＮＯ3チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0021ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0021D001_3(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0021ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0021ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.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(ZM0021ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0021ETMsg.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(ZM0021ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0021ETMsg.STATUS)) {
			inETMsg.set(ZM0021ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0031C001_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0031ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0031C001_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0031ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0031ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.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(ZM0031ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0031ETMsg.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(ZM0031ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0031ETMsg.STATUS)) {
			inETMsg.set(ZM0031ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0031C001_制約ＮＯ2チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0031ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0031C001_2(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

			// 制約部品引数定義
			Object joken_1_prm_1 = "ZM0031";

			// 判定条件
			if(JPCModelCommon.succeededExclusiveLock(inETMsg, inContext, joken_1_prm_1 ) == false){
				inETMsg.set(ZM0031ETMsg.ROLE_CD_ERR, errFlag);
				if("W".equals(errFlag.substring(0,1))){
					rtn = StatusCodes.WARNING;
				} else {
					rtn = StatusCodes.RELATION_ERR;
				}
			}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0031ETMsg.STATUS)) {
			inETMsg.set(ZM0031ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0031C002_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0031ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0031C002_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0031ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0031ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.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(ZM0031ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0031ETMsg.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(ZM0031ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0031ETMsg.STATUS)) {
			inETMsg.set(ZM0031ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0031C002_制約ＮＯ2チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0031ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0031C002_2(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

			// 制約部品引数定義
			Object joken_1_prm_1 = "ZM0031";

			// 判定条件
			if(!(JPCModelCommon.succeededExclusiveLock(inETMsg, inContext, joken_1_prm_1 ) == true)){
				inETMsg.set(ZM0031ETMsg.ROLE_CD_ERR, errFlag);
				if("W".equals(errFlag.substring(0,1))){
					rtn = StatusCodes.WARNING;
				} else {
					rtn = StatusCodes.RELATION_ERR;
				}
			}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0031ETMsg.STATUS)) {
			inETMsg.set(ZM0031ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0031D001_制約ＮＯ1チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0031ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0031D001_1(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0031ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0031ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.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(ZM0031ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0031ETMsg.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(ZM0031ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0031ETMsg.STATUS)) {
			inETMsg.set(ZM0031ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0041C001_制約ＮＯ13チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0041ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0041C001_13(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0041ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0041ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.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(ZM0041ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0041ETMsg.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(ZM0041ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0041ETMsg.STATUS)) {
			inETMsg.set(ZM0041ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0041C001_制約ＮＯ14チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0041ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0041C001_14(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0041ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0041ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(ZM0041ETMsg.OPERATEDATE)){
				joken2_2 = new String(inETMsg.getObject(ZM0041ETMsg.OPERATEDATE).toString());
			}

			String joken3_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_TENDYMD);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " < ? ";
			}

			String joken_3 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken3_2 == null){
				joken_3 += " IS NULL ";
			}else{
				joken_3 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.getTableName()).append(" WHERE ")
				.append("(" + "(" + joken_1 + " AND " + joken_2 + " ) " + " AND " + joken_3 + " ) ");

			// ＳＱＬ文の解析
			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);
			}
			if(joken3_2 != null){
				CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken3_2);
			}

			// ＳＱＬ文の実行
			rsltQuery = pstmtQuery.executeQuery();

			if(rsltQuery.next()){
				// 判定条件
				if(rsltQuery.getLong("CNT")>0){
					inETMsg.set(ZM0041ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0041ETMsg.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(ZM0041ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0041ETMsg.STATUS)) {
			inETMsg.set(ZM0041ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0041D001_制約ＮＯ13チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0041ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0041D001_13(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0041ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0041ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.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(ZM0041ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0041ETMsg.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(ZM0041ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0041ETMsg.STATUS)) {
			inETMsg.set(ZM0041ETMsg.STATUS, rtn);
		}

		return rtn;

	}

	/**
	 * IZM0041D001_制約ＮＯ14チェック
	 *
	 * @param inETMsg チェック対象のETMsg(ZM0041ETMsg)
	 * @param inContext Agentから渡されたAgentDispatchContext
	 * @param errFlag ERRフラグ
	 * @return int チェック結果
	 */
	private int execIZM0041D001_14(CAANMsg inETMsg, AgentDispatchContext inContext, String errFlag){

		// ステータス
		int rtn = 0;

		Connection con = JSYejbConnection.getConnection(ZM0031ETMsg.getTableName());

		PreparedStatement pstmtQuery = null;
		ResultSet rsltQuery = null;
		StringBuffer sqlQuery = new StringBuffer();

		try{

			// ＳＱＬ引数定義
			String joken1_2 = null;
			if(!inETMsg.isNull(ZM0041ETMsg.ROLE_CD)){
				joken1_2 = new String(inETMsg.getObject(ZM0041ETMsg.ROLE_CD).toString());
			}

			String joken2_2 = null;
			if(!inETMsg.isNull(ZM0041ETMsg.OPERATEDATE)){
				joken2_2 = new String(inETMsg.getObject(ZM0041ETMsg.OPERATEDATE).toString());
			}

			String joken3_2 = "0";
			// 条件文定義
			String joken_1 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_CD);
			if(joken1_2 == null){
				joken_1 += " IS NULL ";
			}else{
				joken_1 += " = ? ";
			}

			String joken_2 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.ROLE_TENDYMD);
			if(joken2_2 == null){
				joken_2 += " IS NULL ";
			}else{
				joken_2 += " < ? ";
			}

			String joken_3 = ZM0031ETMsg.getDBColumnName(ZM0031ETMsg.MK_FLG);
			if(joken3_2 == null){
				joken_3 += " IS NULL ";
			}else{
				joken_3 += " = ? ";
			}


			// ＳＱＬ文の組み立て
			sqlQuery.append("SELECT COUNT(*) CNT FROM ").append(ZM0031ETMsg.getTableName()).append(" WHERE ")
				.append("(" + "(" + joken_1 + " AND " + joken_2 + " ) " + " AND " + joken_3 + " ) ");

			// ＳＱＬ文の解析
			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);
			}
			if(joken3_2 != null){
				CAANJDBCUtil.setParam(pstmtQuery, para_idx++ , joken3_2);
			}

			// ＳＱＬ文の実行
			rsltQuery = pstmtQuery.executeQuery();

			if(rsltQuery.next()){
				// 判定条件
				if(rsltQuery.getLong("CNT")>0){
					inETMsg.set(ZM0041ETMsg.ROLE_CD_ERR, errFlag);
					if("W".equals(errFlag.substring(0,1))){
						rtn = StatusCodes.WARNING;
					} else {
						rtn = StatusCodes.RELATION_ERR;
					}
				}
			}

		} catch(SQLException e) {
			inETMsg.set(ZM0041ETMsg.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(ZM0041ETMsg.STATUS, StatusCodes.FIND_DB_ERR);
				throw new CAANRuntimeException(e);
			}
		}
		
		// ステータスのセット
		if (rtn > inETMsg.getInt(ZM0041ETMsg.STATUS)) {
			inETMsg.set(ZM0041ETMsg.STATUS, rtn);
		}

		return rtn;

	}

}

