/// <summary> /// B層のシステム例外による異常終了の後処理を実装するUOCメソッド。 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <param name="bsEx">BusinessSystemException</param> /// <remarks>業務コード親クラス1から利用される派生の末端</remarks> protected override void UOC_ABEND(BaseParameterValue parameterValue, BaseReturnValue returnValue, BusinessSystemException bsEx) { // システム例外発生時の処理を実装 // TODO: // nullチェック if (this.perfRec == null) { // なにもしない } else { // 性能測定終了 this.perfRec.EndsPerformanceRecord(); // ACCESSログ出力----------------------------------------------- MyParameterValue myPV = (MyParameterValue)parameterValue; // ------------ // メッセージ部 // ------------ // ユーザ名, IPアドレス, レイヤ, // 画面名, コントロール名, メソッド名, 処理名 // 処理時間(実行時間), 処理時間(CPU時間) // エラーメッセージID, エラーメッセージ等 // ------------ string strLogMessage = "," + myPV.User.UserName + "," + myPV.User.IPAddress + "," + "<<-----" + "," + myPV.ScreenId + "," + myPV.ControlId + "," + myPV.MethodName + "," + myPV.ActionType + "," + this.perfRec.ExecTime + "," + this.perfRec.CpuTime + "," + bsEx.messageID + "," + bsEx.Message + "\r\n" + bsEx.StackTrace; // bsEX // Log4Netへログ出力 LogIF.ErrorLog("ACCESS", strLogMessage); } // ------------------------------------------------------------- }
/// <summary> /// B層の業務例外による異常終了の後処理を実装するUOCメソッド。 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <param name="baEx">BusinessApplicationException</param> /// <remarks>業務コード親クラス1から利用される派生の末端</remarks> protected override void UOC_ABEND(BaseParameterValue parameterValue, BaseReturnValue returnValue, BusinessApplicationException baEx) { // 業務例外発生時の処理を実装 // TODO: // nullチェック if (this.perfRec == null) { // なにもしない } else { // 性能測定終了 this.perfRec.EndsPerformanceRecord(); // ACCESSログ出力----------------------------------------------- MyParameterValue myPV = (MyParameterValue)parameterValue; // ------------ // メッセージ部 // ------------ // ユーザ名, 画面名, コントロール名 メソッド名, 処理名 // 処理時間(実行時間), 処理時間(CPU時間) // エラーメッセージID, エラーメッセージ等 // ------------ string strLogMessage = "," + myPV.User.UserName + "," + myPV.ScreenId + "," + myPV.ControlId + "," + myPV.MethodName + "," + myPV.ActionType + "," + this.perfRec.ExecTime + "," + this.perfRec.CpuTime + "," + baEx.messageID + "," + baEx.Message; // baEX // Log4Netへログ出力 LogIF.WarnLog("ACCESS", strLogMessage); } // ------------------------------------------------------------- }
/// <summary>自動振り分け処理</summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> protected override void UOC_DoAction(BaseParameterValue parameterValue, ref BaseReturnValue returnValue) { // メソッド名を生成 string methodName = "UOC_" + parameterValue.MethodName; #region レイトバインドする object[] paramSet = new object[] { parameterValue }; try { // Latebind Latebind.InvokeMethod(this, methodName, paramSet); } catch (System.Reflection.TargetInvocationException rtEx) { // InnerExceptionのスタックトレースを保存しておく(以下のリスローで消去されるため)。 this.OriginalStackTrace = rtEx.InnerException.StackTrace; // InnerExceptionを投げなおす。 throw rtEx.InnerException; } finally { // レイトバインドにおいて、 // ・ 戻り値(in)の場合、下位で生成した戻り値インスタンスは戻らない。 // ・ 戻り値(ref, out)の場合、例外発生時は戻り値インスタンスは戻らない。 // という問題がある。 // ∴ (特に後者の対応のため、) // メンバ変数を使用して戻り値インスタンスを戻す。 returnValue = this.ReturnValue; } #endregion }
/// <summary>ASP.NET WebAPI JSON-RPCの個別Webメソッドの共通部</summary> /// <param name="serviceName">サービス名</param> /// <param name="parameterValue">引数</param> /// <returns> /// AsyncRetVal(非同期化のため) /// ・WsErrorInfo:返すべきエラーの情報 /// ・ReturnValue:戻り値 /// </returns> private async Task <AsyncRetVal> Call( string serviceName, BaseParameterValue parameterValue) { // ステータス string status = "-"; #region 呼出し制御関係の変数 // アセンブリ名 string assemblyName = ""; // クラス名 string className = ""; #endregion #region 引数・戻り値関係の変数 BaseReturnValue returnValue = null; // エラー情報(XMLフォーマット) Dictionary <string, string> wsErrorInfo = new Dictionary <string, string>(); // エラー情報(ログ出力用) string errorType = ""; // 2009/09/15-この行 string errorMessageID = ""; string errorMessage = ""; string errorToString = ""; #endregion try { // 開始ログの出力 LogIF.InfoLog("SERVICE-IF", FxLiteral.SIF_STATUS_START); #region 前解決 // ★ status = FxLiteral.SIF_STATUS_NAME_SERVICE; // 名前解決(インプロセス) JsonController.IPR_NS.NameResolution(serviceName, out assemblyName, out className); #endregion #region 引数の.NETオブジェクト化(UOC) // ★ status = FxLiteral.SIF_STATUS_DESERIALIZE; // 引数クラスをパラメタ セットに格納 object[] paramSet = new object[] { parameterValue, DbEnum.IsolationLevelEnum.User }; #endregion #region 認証処理(UOC) // MyBaseApiControllerに実装する。 #endregion #region B層・D層呼出し // ★ status = FxLiteral.SIF_STATUS_INVOKE; try { // B層・D層呼出し try { // B層・D層呼出し Task <BaseReturnValue> result = (Task <BaseReturnValue>)Latebind.InvokeMethod( assemblyName, className, FxLiteral.TRANSMISSION_INPROCESS_ASYNC_METHOD_NAME, paramSet); returnValue = await result; } catch (System.Reflection.TargetInvocationException rtEx) { //// InnerExceptionを投げなおす。 //throw rtEx.InnerException; // スタックトレースを保って InnerException を throw ExceptionDispatchInfo.Capture(rtEx.InnerException).Throw(); } } catch (System.Reflection.TargetInvocationException rtEx) { // InnerExceptionを投げなおす。 throw rtEx.InnerException; } #endregion // ★ status = ""; // 戻り値を返す。 return(new AsyncRetVal { WsErrorInfo = null, ReturnValue = returnValue }); } //catch (BusinessApplicationException baEx) //{ // ここには来ない↑ //} catch (BusinessSystemException bsEx) { // エラー情報を設定する。 // システム例外 wsErrorInfo["ErrorType"] = FxEnum.ErrorType.BusinessSystemException.ToString(); wsErrorInfo["MessageID"] = bsEx.messageID; wsErrorInfo["Message"] = bsEx.Message; // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.BusinessSystemException.ToString(); // 2009/09/15-この行 errorMessageID = bsEx.messageID; errorMessage = bsEx.Message; errorToString = bsEx.ToString(); // エラー情報を戻す。 return(new AsyncRetVal { WsErrorInfo = wsErrorInfo, ReturnValue = returnValue }); } catch (FrameworkException fxEx) { // エラー情報を設定する。 // フレームワーク例外 // ★ インナーエクセプション情報は消失 wsErrorInfo["ErrorType"] = FxEnum.ErrorType.FrameworkException.ToString(); wsErrorInfo["MessageID"] = fxEx.messageID; wsErrorInfo["Message"] = fxEx.Message; // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.FrameworkException.ToString(); // 2009/09/15-この行 errorMessageID = fxEx.messageID; errorMessage = fxEx.Message; errorToString = fxEx.ToString(); // エラー情報を戻す。 return(new AsyncRetVal { WsErrorInfo = wsErrorInfo, ReturnValue = returnValue }); } catch (Exception ex) { // エラー情報を設定する。 // フレームワーク例外 // ★ インナーエクセプション情報は消失 wsErrorInfo["ErrorType"] = FxEnum.ErrorType.ElseException.ToString(); wsErrorInfo["MessageID"] = "-"; wsErrorInfo["Message"] = ex.ToString(); // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.ElseException.ToString(); // 2009/09/15-この行 errorMessageID = "-"; errorMessage = ex.Message; // どちらを戻すべきか? // Muの場合は、Messageがデフォ errorToString = ex.Message; //errorToString = ex.ToString(); // エラー情報を戻す。 return(new AsyncRetVal { WsErrorInfo = wsErrorInfo, ReturnValue = returnValue }); } finally { // 用途によってSessionを解放するかどうかを検討。 //// Sessionステートレス //Session.Clear(); //Session.Abandon(); // 終了ログの出力 if (status == "") { // 終了ログ出力 LogIF.InfoLog("SERVICE-IF", "正常終了"); } else { // 終了ログ出力 LogIF.ErrorLog("SERVICE-IF", "異常終了" + ":" + status + "\r\n" + "エラー タイプ:" + errorType + "\r\n" // 2009/09/15-この行 + "エラー メッセージID:" + errorMessageID + "\r\n" + "エラー メッセージ:" + errorMessage + "\r\n" + errorToString + "\r\n"); } } }
/// <summary> /// WCFの.NETオブジェクトのバイナリ転送用Soap Webメソッド /// </summary> /// <param name="serviceName">サービス名</param> /// <param name="contextObject">コンテキスト</param> /// <param name="parameterValueObject">引数</param> /// <param name="returnValueObject">戻り値</param> /// <returns>返すべきエラーの情報</returns> /// <remarks>値は全て.NETオブジェクトをバイナリシリアライズしたバイト配列データ</remarks> public byte[] DotNETOnlineWS( string serviceName, ref byte[] contextObject, byte[] parameterValueObject, out byte[] returnValueObject) { // ステータス string status = "-"; // 初期化のため returnValueObject = null; #region 呼出し制御関係の変数 // アセンブリ名 string assemblyName = ""; // クラス名 string className = ""; #endregion #region 引数・戻り値関係の変数 // コンテキスト情報 object context; // 2009/09/29-この行 // 引数・戻り値の.NETオブジェクト BaseParameterValue parameterValue = null; BaseReturnValue returnValue = null; // エラー情報(クライアント側で復元するため) WSErrorInfo wsErrorInfo = new WSErrorInfo(); // エラー情報(ログ出力用) string errorType = ""; // 2009/09/15-この行 string errorMessageID = ""; string errorMessage = ""; string errorToString = ""; #endregion try { // 開始ログの出力 LogIF.InfoLog("SERVICE-IF", FxLiteral.SIF_STATUS_START); #region 前解決 // ★ status = FxLiteral.SIF_STATUS_NAME_SERVICE; // 名前解決(インプロセス) WCFHTTPSvcForFx.IPR_NS.NameResolution(serviceName, out assemblyName, out className); #endregion #region 引数のデシリアライズ // ★ status = FxLiteral.SIF_STATUS_DESERIALIZE; // コンテキストクラスの.NETオブジェクト化 context = BinarySerialize.BytesToObject(contextObject); // 2009/09/29-この行 // ※ コンテキストの利用方法は任意だが、サービスインターフェイス上での利用に止める。 // 引数クラスの.NETオブジェクト化 parameterValue = (BaseParameterValue)BinarySerialize.BytesToObject(parameterValueObject); // 引数クラスをパラメタ セットに格納 object[] paramSet = new object[] { parameterValue, DbEnum.IsolationLevelEnum.User }; #endregion #region 認証処理のUOC // ★ status = FxLiteral.SIF_STATUS_AUTHENTICATION; string access_token = (string)context; if (!string.IsNullOrEmpty(access_token)) { string sub = ""; List <string> roles = null; List <string> scopes = null; JObject jobj = null; if (JwtToken.Verify(access_token, out sub, out roles, out scopes, out jobj)) { // 認証成功 Debug.WriteLine("認証成功"); } else { // 認証失敗(認証必須ならエラーにする。 } } else { // 認証失敗(認証必須ならエラーにする。 } //contextObject = BinarySerialize.ObjectToBytes(hogehoge); // 更新可能だが...。 #endregion #region B層・D層呼出し // ★ status = FxLiteral.SIF_STATUS_INVOKE; // #17-start try { // B層・D層呼出し //returnValue = (BaseReturnValue)Latebind.InvokeMethod( // AppDomain.CurrentDomain.BaseDirectory + "\\bin\\" + assemblyName + ".dll", // className, FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, paramSet); returnValue = (BaseReturnValue)Latebind.InvokeMethod( assemblyName, className, FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, paramSet); } catch (System.Reflection.TargetInvocationException rtEx) { //// InnerExceptionを投げなおす。 //throw rtEx.InnerException; // スタックトレースを保って InnerException を throw ExceptionDispatchInfo.Capture(rtEx.InnerException).Throw(); } // #17-end #endregion #region 戻り値のシリアライズ // ★ status = FxLiteral.SIF_STATUS_SERIALIZE; returnValueObject = BinarySerialize.ObjectToBytes(returnValue); #endregion // ★ status = ""; // 戻り値を返す。 return(null); } catch (BusinessSystemException bsEx) { // システム例外 // エラー情報を設定する。 wsErrorInfo.ErrorType = FxEnum.ErrorType.BusinessSystemException; wsErrorInfo.ErrorMessageID = bsEx.messageID; wsErrorInfo.ErrorMessage = bsEx.Message; // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.BusinessSystemException.ToString(); // 2009/09/15-この行 errorMessageID = bsEx.messageID; errorMessage = bsEx.Message; errorToString = bsEx.ToString(); // エラー情報を戻す。 return(BinarySerialize.ObjectToBytes(wsErrorInfo)); } catch (FrameworkException fxEx) { // フレームワーク例外 // ★ インナーエクセプション情報は消失 // エラー情報を設定する。 wsErrorInfo.ErrorType = FxEnum.ErrorType.FrameworkException; wsErrorInfo.ErrorMessageID = fxEx.messageID; wsErrorInfo.ErrorMessage = fxEx.Message; // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.FrameworkException.ToString(); // 2009/09/15-この行 errorMessageID = fxEx.messageID; errorMessage = fxEx.Message; errorToString = fxEx.ToString(); // エラー情報を戻す。 return(BinarySerialize.ObjectToBytes(wsErrorInfo)); } catch (Exception ex) { // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.ElseException.ToString(); // 2009/09/15-この行 errorMessageID = "-"; errorMessage = ex.Message; errorToString = ex.ToString(); throw; // SoapExceptionになって伝播 } finally { // Sessionステートレス //HttpContext.Current.Session.Clear(); //HttpContext.Current.Session.Abandon(); // 終了ロクの出力 if (status == "") { // 終了ログ出力 LogIF.InfoLog("SERVICE-IF", "正常終了"); } else { // 終了ログ出力 LogIF.ErrorLog("SERVICE-IF", "異常終了" + ":" + status + "\r\n" + "エラー タイプ:" + errorType + "\r\n" // 2009/09/15-この行 + "エラー メッセージID:" + errorMessageID + "\r\n" + "エラー メッセージ:" + errorMessage + "\r\n" + errorToString); } } }
/// <summary>業務処理を実装</summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> protected override void UOC_DoAction(BaseParameterValue parameterValue, ref BaseReturnValue returnValue) { // 戻り値を生成しておく。 returnValue = new MyReturnValue(); // 自動トランザクションで開始したトランザクションを閉じる。 this.GetDam().CommitTransaction(); // コネクションを閉じる。 this.GetDam().ConnectionClose(); // データアクセス制御クラスをクリア。 this.SetDam(null); // Dam用ワーク BaseDam damWork; // 共通Dao CmnDao cmnDao; // SQLの戻り値を受ける object obj; #region SQL Server #region SQL_NT // Damを生成 damWork = new DamSqlSvr(); // Damを初期化 BaseLogic.InitDam("SQL_NT", damWork); // Damを設定 this.SetDam("SQL_NT", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("SQL_NT")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('SQL_NT', 'SQL_NT')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("SQL_NT").CommitTransaction(); //this.GetDam("SQL_NT").ConnectionClose(); #endregion #region SQL_UC // Damを生成 damWork = new DamSqlSvr(); // Damを初期化 BaseLogic.InitDam("SQL_UC", damWork); // Damを設定 this.SetDam("SQL_UC", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("SQL_UC")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('SQL_UC', 'SQL_UC')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("SQL_UC").CommitTransaction(); //this.GetDam("SQL_UC").ConnectionClose(); #endregion #region SQL_RC // Damを生成 damWork = new DamSqlSvr(); // Damを初期化 BaseLogic.InitDam("SQL_RC", damWork); // Damを設定 this.SetDam("SQL_RC", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("SQL_RC")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('SQL_RC', 'SQL_RC')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("SQL_RC").CommitTransaction(); //this.GetDam("SQL_RC").ConnectionClose(); #endregion #region SQL_RR // Damを生成 damWork = new DamSqlSvr(); // Damを初期化 BaseLogic.InitDam("SQL_RR", damWork); // Damを設定 this.SetDam("SQL_RR", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("SQL_RR")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('SQL_RR', 'SQL_RR')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("SQL_RR").CommitTransaction(); //this.GetDam("SQL_RR").ConnectionClose(); #endregion #region SQL_SZ // Damを生成 damWork = new DamSqlSvr(); // Damを初期化 BaseLogic.InitDam("SQL_SZ", damWork); // Damを設定 this.SetDam("SQL_SZ", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("SQL_SZ")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('SQL_SZ', 'SQL_SZ')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("SQL_SZ").CommitTransaction(); //this.GetDam("SQL_SZ").ConnectionClose(); #endregion #region SQL_SS // Damを生成 damWork = new DamSqlSvr(); // Damを初期化 BaseLogic.InitDam("SQL_SS", damWork); // Damを設定 this.SetDam("SQL_SS", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("SQL_SS")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('SQL_SS', 'SQL_SS')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("SQL_SS").CommitTransaction(); //this.GetDam("SQL_SS").ConnectionClose(); #endregion #region SQL_DF // Damを生成 damWork = new DamSqlSvr(); // Damを初期化 BaseLogic.InitDam("SQL_DF", damWork); // Damを設定 this.SetDam("SQL_DF", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("SQL_DF")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('SQL_DF', 'SQL_DF')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("SQL_DF").CommitTransaction(); //this.GetDam("SQL_DF").ConnectionClose(); #endregion #endregion #region Oracle #region ODP2_NT // Damを生成 damWork = new DamOraOdp(); // Damを初期化 BaseLogic.InitDam("ODP2_NT", damWork); // Damを設定 this.SetDam("ODP2_NT", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("ODP2_NT")); cmnDao.SQLText = "INSERT INTO Shippers(ShipperID, CompanyName, Phone) VALUES(TS_ShipperID.NEXTVAL, 'ODP2_NT', 'ODP2_NT')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("ODP2_NT").CommitTransaction(); //this.GetDam("ODP2_NT").ConnectionClose(); #endregion #region ODP2_UC // ★ サポートされない分離レベル #endregion #region ODP2_RC // Damを生成 damWork = new DamOraOdp(); // Damを初期化 BaseLogic.InitDam("ODP2_RC", damWork); // Damを設定 this.SetDam("ODP2_RC", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("ODP2_RC")); cmnDao.SQLText = "INSERT INTO Shippers(ShipperID, CompanyName, Phone) VALUES(TS_ShipperID.NEXTVAL, 'ODP2_RC', 'ODP2_RC')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("ODP2_RC").CommitTransaction(); //this.GetDam("ODP2_RC").ConnectionClose(); #endregion #region ODP2_RR // ★ サポートされない分離レベル #endregion #region ODP2_SZ // Damを生成 damWork = new DamOraOdp(); // Damを初期化 BaseLogic.InitDam("ODP2_SZ", damWork); // Damを設定 this.SetDam("ODP2_SZ", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("ODP2_SZ")); cmnDao.SQLText = "INSERT INTO Shippers(ShipperID, CompanyName, Phone) VALUES(TS_ShipperID.NEXTVAL, 'ODP2_SZ', 'ODP2_SZ')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("ODP2_SZ").CommitTransaction(); //this.GetDam("ODP2_SZ").ConnectionClose(); #endregion #region ODP2_SS // ★ サポートされない分離レベル #endregion #region ODP2_DF // Damを生成 damWork = new DamOraOdp(); // Damを初期化 BaseLogic.InitDam("ODP2_DF", damWork); // Damを設定 this.SetDam("ODP2_DF", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("ODP2_DF")); cmnDao.SQLText = "INSERT INTO Shippers(ShipperID, CompanyName, Phone) VALUES(TS_ShipperID.NEXTVAL, 'ODP2_DF', 'ODP2_DF')"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("ODP2_DF").CommitTransaction(); //this.GetDam("ODP2_DF").ConnectionClose(); #endregion #endregion #region DB2 #region DB2_NT //// Damを生成 //damWork = new DamDB2(); //// Damを初期化 //BaseLogic.InitDam("DB2_NT", damWork); //// Damを設定 //this.SetDam("DB2_NT", damWork); //// インサート //// Damを直接使用することもできるが、 //// 通常は、データアクセスにはDaoを使用する。 //cmnDao = new CmnDao(this.GetDam("DB2_NT")); //cmnDao.SQLText = "INSERT INTO Shippers (ShipperID, CompanyName, Phone) VALUES(NEXTVAL for TS_ShipperID, 'DB2_NT', 'DB2_NT')"; //obj = (object)cmnDao.ExecSelectScalar(); ////this.GetDam("DB2_NT").CommitTransaction(); ////this.GetDam("DB2_NT").ConnectionClose(); #endregion #region DB2_UC //// Damを生成 //damWork = new DamDB2(); //// Damを初期化 //BaseLogic.InitDam("DB2_UC", damWork); //// Damを設定 //this.SetDam("DB2_UC", damWork); //// インサート //// Damを直接使用することもできるが、 //// 通常は、データアクセスにはDaoを使用する。 //cmnDao = new CmnDao(this.GetDam("DB2_UC")); //cmnDao.SQLText = "INSERT INTO Shippers (ShipperID, CompanyName, Phone) VALUES(NEXTVAL for TS_ShipperID, 'DB2_UC', 'DB2_UC')"; //obj = (object)cmnDao.ExecSelectScalar(); ////this.GetDam("DB2_UC").CommitTransaction(); ////this.GetDam("DB2_UC").ConnectionClose(); #endregion #region DB2_RC //// Damを生成 //damWork = new DamDB2(); //// Damを初期化 //BaseLogic.InitDam("DB2_RC", damWork); //// Damを設定 //this.SetDam("DB2_RC", damWork); //// インサート //// Damを直接使用することもできるが、 //// 通常は、データアクセスにはDaoを使用する。 //cmnDao = new CmnDao(this.GetDam("DB2_UC")); //cmnDao.SQLText = "INSERT INTO Shippers (ShipperID, CompanyName, Phone) VALUES(NEXTVAL for TS_ShipperID, 'DB2_RC', 'DB2_RC')"; //obj = (object)cmnDao.ExecSelectScalar(); ////this.GetDam("DB2_RC").CommitTransaction(); ////this.GetDam("DB2_RC").ConnectionClose(); #endregion #region DB2_RR //// Damを生成 //damWork = new DamDB2(); //// Damを初期化 //BaseLogic.InitDam("DB2_RR", damWork); //// Damを設定 //this.SetDam("DB2_RR", damWork); //// インサート //// Damを直接使用することもできるが、 //// 通常は、データアクセスにはDaoを使用する。 //cmnDao = new CmnDao(this.GetDam("DB2_RR")); //cmnDao.SQLText = "INSERT INTO Shippers (ShipperID, CompanyName, Phone) VALUES(NEXTVAL for TS_ShipperID, 'DB2_RR', 'DB2_RR')"; //obj = (object)cmnDao.ExecSelectScalar(); ////this.GetDam("DB2_RR").CommitTransaction(); ////this.GetDam("DB2_RR").ConnectionClose(); #endregion #region DB2_SZ //// Damを生成 //damWork = new DamDB2(); //// Damを初期化 //BaseLogic.InitDam("DB2_SZ", damWork); //// Damを設定 //this.SetDam("DB2_SZ", damWork); //// インサート //// Damを直接使用することもできるが、 //// 通常は、データアクセスにはDaoを使用する。 //cmnDao = new CmnDao(this.GetDam("DB2_SZ")); //cmnDao.SQLText = "INSERT INTO Shippers (ShipperID, CompanyName, Phone) VALUES(NEXTVAL for TS_ShipperID, 'DB2_SZ', 'DB2_SZ')"; //obj = (object)cmnDao.ExecSelectScalar(); ////this.GetDam("DB2_SZ").CommitTransaction(); ////this.GetDam("DB2_SZ").ConnectionClose(); #endregion #region DB2_SS // ★ サポートされない分離レベル #endregion #region DB2_DF //// Damを生成 //damWork = new DamDB2(); //// Damを初期化 //BaseLogic.InitDam("DB2_DF", damWork); //// Damを設定 //this.SetDam("DB2_DF", damWork); //// インサート //// Damを直接使用することもできるが、 //// 通常は、データアクセスにはDaoを使用する。 //cmnDao = new CmnDao(this.GetDam("DB2_DF")); //cmnDao.SQLText = "INSERT INTO Shippers (ShipperID, CompanyName, Phone) VALUES(NEXTVAL for TS_ShipperID, 'DB2_DF', 'DB2_DF')"; //obj = (object)cmnDao.ExecSelectScalar(); ////this.GetDam("DB2_DF").CommitTransaction(); ////this.GetDam("DB2_DF").ConnectionClose(); #endregion #endregion #region MySQL #region MCN_NT // Damを生成 damWork = new DamMySQL(); // Damを初期化 BaseLogic.InitDam("MCN_NT", damWork); // Damを設定 this.SetDam("MCN_NT", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("MCN_NT")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('MCN_NT', 'MCN_NT');"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("MCN_NT").CommitTransaction(); //this.GetDam("MCN_NT").ConnectionClose(); #endregion #region MCN_UC // Damを生成 damWork = new DamMySQL(); // Damを初期化 BaseLogic.InitDam("MCN_UC", damWork); // Damを設定 this.SetDam("MCN_UC", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("MCN_UC")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('MCN_UC', 'MCN_UC');"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("MCN_UC").CommitTransaction(); //this.GetDam("MCN_UC").ConnectionClose(); #endregion #region MCN_RC // Damを生成 damWork = new DamMySQL(); // Damを初期化 BaseLogic.InitDam("MCN_RC", damWork); // Damを設定 this.SetDam("MCN_RC", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("MCN_RC")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('MCN_RC', 'MCN_RC');"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("MCN_RC").CommitTransaction(); //this.GetDam("MCN_RC").ConnectionClose(); #endregion #region MCN_RR // Damを生成 damWork = new DamMySQL(); // Damを初期化 BaseLogic.InitDam("MCN_RR", damWork); // Damを設定 this.SetDam("MCN_RR", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("MCN_RR")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('MCN_RR', 'MCN_RR');"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("MCN_RR").CommitTransaction(); //this.GetDam("MCN_RR").ConnectionClose(); #endregion #region MCN_SZ // Damを生成 damWork = new DamMySQL(); // Damを初期化 BaseLogic.InitDam("MCN_SZ", damWork); // Damを設定 this.SetDam("MCN_SZ", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("MCN_SZ")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('MCN_SZ', 'MCN_SZ');"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("MCN_SZ").CommitTransaction(); //this.GetDam("MCN_SZ").ConnectionClose(); #endregion #region MCN_SS // ★ サポートされない分離レベル #endregion #region MCN_DF // Damを生成 damWork = new DamMySQL(); // Damを初期化 BaseLogic.InitDam("MCN_DF", damWork); // Damを設定 this.SetDam("MCN_DF", damWork); // インサート // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam("MCN_DF")); cmnDao.SQLText = "INSERT INTO Shippers(CompanyName, Phone) VALUES('MCN_DF', 'MCN_DF');"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam("MCN_DF").CommitTransaction(); //this.GetDam("MCN_DF").ConnectionClose(); #endregion #endregion #region 終了時の状態選択 #region Damの状態選択 if ((parameterValue.ActionType.Split('%'))[2] == "UT") { // トランザクションあり } else if ((parameterValue.ActionType.Split('%'))[2] == "NT") { // トランザクションなし // → まえもってロールバックしておく #region ロールバック this.GetDam("SQL_NT").RollbackTransaction(); this.GetDam("SQL_UC").RollbackTransaction(); this.GetDam("SQL_RC").RollbackTransaction(); this.GetDam("SQL_RR").RollbackTransaction(); this.GetDam("SQL_SZ").RollbackTransaction(); this.GetDam("SQL_SS").RollbackTransaction(); this.GetDam("SQL_DF").RollbackTransaction(); this.GetDam("ODP2_NT").RollbackTransaction(); //this.GetDam("ODP2_UC").RollbackTransaction(); this.GetDam("ODP2_RC").RollbackTransaction(); //this.GetDam("ODP2_RR").RollbackTransaction(); this.GetDam("ODP2_SZ").RollbackTransaction(); //this.GetDam("ODP2_SS").RollbackTransaction(); this.GetDam("ODP2_DF").RollbackTransaction(); this.GetDam("DB2_NT").RollbackTransaction(); this.GetDam("DB2_UC").RollbackTransaction(); this.GetDam("DB2_RC").RollbackTransaction(); this.GetDam("DB2_RR").RollbackTransaction(); this.GetDam("DB2_SZ").RollbackTransaction(); //this.GetDam("DB2_SS").RollbackTransaction(); this.GetDam("DB2_DF").RollbackTransaction(); this.GetDam("MCN_NT").RollbackTransaction(); this.GetDam("MCN_UC").RollbackTransaction(); this.GetDam("MCN_RC").RollbackTransaction(); this.GetDam("MCN_RR").RollbackTransaction(); this.GetDam("MCN_SZ").RollbackTransaction(); //this.GetDam("MCN_SS").RollbackTransaction(); this.GetDam("MCN_DF").RollbackTransaction(); #endregion } else if ((parameterValue.ActionType.Split('%'))[2] == "NC") { // コネクションなし // → まえもってロールバック、コネクションクローズしておく // // ※ トランザクションを開始して // コミットしないで閉じると、ロールバック扱い。 #region ロールバック this.GetDam("SQL_NT").RollbackTransaction(); this.GetDam("SQL_UC").RollbackTransaction(); this.GetDam("SQL_RC").RollbackTransaction(); this.GetDam("SQL_RR").RollbackTransaction(); this.GetDam("SQL_SZ").RollbackTransaction(); this.GetDam("SQL_SS").RollbackTransaction(); this.GetDam("SQL_DF").RollbackTransaction(); this.GetDam("ODP2_NT").RollbackTransaction(); //this.GetDam("ODP2_UC").RollbackTransaction(); this.GetDam("ODP2_RC").RollbackTransaction(); //this.GetDam("ODP2_RR").RollbackTransaction(); this.GetDam("ODP2_SZ").RollbackTransaction(); //this.GetDam("ODP2_SS").RollbackTransaction(); this.GetDam("ODP2_DF").RollbackTransaction(); this.GetDam("DB2_NT").RollbackTransaction(); this.GetDam("DB2_UC").RollbackTransaction(); this.GetDam("DB2_RC").RollbackTransaction(); this.GetDam("DB2_RR").RollbackTransaction(); this.GetDam("DB2_SZ").RollbackTransaction(); //this.GetDam("DB2_SS").RollbackTransaction(); this.GetDam("DB2_DF").RollbackTransaction(); this.GetDam("MCN_NT").RollbackTransaction(); this.GetDam("MCN_UC").RollbackTransaction(); this.GetDam("MCN_RC").RollbackTransaction(); this.GetDam("MCN_RR").RollbackTransaction(); this.GetDam("MCN_SZ").RollbackTransaction(); //this.GetDam("MCN_SS").RollbackTransaction(); this.GetDam("MCN_DF").RollbackTransaction(); #endregion #region コネクションクローズ this.GetDam("SQL_NT").ConnectionClose(); this.GetDam("SQL_UC").ConnectionClose(); this.GetDam("SQL_RC").ConnectionClose(); this.GetDam("SQL_RR").ConnectionClose(); this.GetDam("SQL_SZ").ConnectionClose(); this.GetDam("SQL_SS").ConnectionClose(); this.GetDam("SQL_DF").ConnectionClose(); this.GetDam("ODP2_NT").ConnectionClose(); //this.GetDam("ODP2_UC").ConnectionClose(); this.GetDam("ODP2_RC").ConnectionClose(); //this.GetDam("ODP2_RR").ConnectionClose(); this.GetDam("ODP2_SZ").ConnectionClose(); //this.GetDam("ODP2_SS").ConnectionClose(); this.GetDam("ODP2_DF").ConnectionClose(); this.GetDam("DB2_NT").ConnectionClose(); this.GetDam("DB2_UC").ConnectionClose(); this.GetDam("DB2_RC").ConnectionClose(); this.GetDam("DB2_RR").ConnectionClose(); this.GetDam("DB2_SZ").ConnectionClose(); //this.GetDam("DB2_SS").ConnectionClose(); this.GetDam("DB2_DF").ConnectionClose(); this.GetDam("MCN_NT").ConnectionClose(); this.GetDam("MCN_UC").ConnectionClose(); this.GetDam("MCN_RC").ConnectionClose(); this.GetDam("MCN_RR").ConnectionClose(); this.GetDam("MCN_SZ").ConnectionClose(); //this.GetDam("MCN_SS").ConnectionClose(); this.GetDam("MCN_DF").ConnectionClose(); #endregion } else if ((parameterValue.ActionType.Split('%'))[2] == "NULL") { // データアクセス制御クラス = Null // → まえもってロールバック、コネクションクローズ、Nullクリアしておく // // ※ トランザクションを開始して // コミットしないで閉じると、ロールバック扱い。 #region ロールバック this.GetDam("SQL_NT").RollbackTransaction(); this.GetDam("SQL_UC").RollbackTransaction(); this.GetDam("SQL_RC").RollbackTransaction(); this.GetDam("SQL_RR").RollbackTransaction(); this.GetDam("SQL_SZ").RollbackTransaction(); this.GetDam("SQL_SS").RollbackTransaction(); this.GetDam("SQL_DF").RollbackTransaction(); this.GetDam("ODP2_NT").RollbackTransaction(); //this.GetDam("ODP2_UC").RollbackTransaction(); this.GetDam("ODP2_RC").RollbackTransaction(); //this.GetDam("ODP2_RR").RollbackTransaction(); this.GetDam("ODP2_SZ").RollbackTransaction(); //this.GetDam("ODP2_SS").RollbackTransaction(); this.GetDam("ODP2_DF").RollbackTransaction(); this.GetDam("DB2_NT").RollbackTransaction(); this.GetDam("DB2_UC").RollbackTransaction(); this.GetDam("DB2_RC").RollbackTransaction(); this.GetDam("DB2_RR").RollbackTransaction(); this.GetDam("DB2_SZ").RollbackTransaction(); //this.GetDam("DB2_SS").RollbackTransaction(); this.GetDam("DB2_DF").RollbackTransaction(); this.GetDam("MCN_NT").RollbackTransaction(); this.GetDam("MCN_UC").RollbackTransaction(); this.GetDam("MCN_RC").RollbackTransaction(); this.GetDam("MCN_RR").RollbackTransaction(); this.GetDam("MCN_SZ").RollbackTransaction(); //this.GetDam("MCN_SS").RollbackTransaction(); this.GetDam("MCN_DF").RollbackTransaction(); #endregion #region コネクションクローズ this.GetDam("SQL_NT").ConnectionClose(); this.GetDam("SQL_UC").ConnectionClose(); this.GetDam("SQL_RC").ConnectionClose(); this.GetDam("SQL_RR").ConnectionClose(); this.GetDam("SQL_SZ").ConnectionClose(); this.GetDam("SQL_SS").ConnectionClose(); this.GetDam("SQL_DF").ConnectionClose(); this.GetDam("ODP2_NT").ConnectionClose(); //this.GetDam("ODP2_UC").ConnectionClose(); this.GetDam("ODP2_RC").ConnectionClose(); //this.GetDam("ODP2_RR").ConnectionClose(); this.GetDam("ODP2_SZ").ConnectionClose(); //this.GetDam("ODP2_SS").ConnectionClose(); this.GetDam("ODP2_DF").ConnectionClose(); this.GetDam("DB2_NT").ConnectionClose(); this.GetDam("DB2_UC").ConnectionClose(); this.GetDam("DB2_RC").ConnectionClose(); this.GetDam("DB2_RR").ConnectionClose(); this.GetDam("DB2_SZ").ConnectionClose(); //this.GetDam("DB2_SS").ConnectionClose(); this.GetDam("DB2_DF").ConnectionClose(); this.GetDam("MCN_NT").ConnectionClose(); this.GetDam("MCN_UC").ConnectionClose(); this.GetDam("MCN_RC").ConnectionClose(); this.GetDam("MCN_RR").ConnectionClose(); this.GetDam("MCN_SZ").ConnectionClose(); //this.GetDam("MCN_SS").ConnectionClose(); this.GetDam("MCN_DF").ConnectionClose(); #endregion #region Nullクリア this.SetDam("SQL_NT", null); this.SetDam("SQL_UC", null); this.SetDam("SQL_RC", null); this.SetDam("SQL_RR", null); this.SetDam("SQL_SZ", null); this.SetDam("SQL_SS", null); this.SetDam("SQL_DF", null); this.SetDam("ODP2_NT", null); //this.SetDam("ODP2_UC",null); this.SetDam("ODP2_RC", null); //this.SetDam("ODP2_RR",null); this.SetDam("ODP2_SZ", null); //this.SetDam("ODP2_SS",null); this.SetDam("ODP2_DF", null); this.SetDam("DB2_NT", null); this.SetDam("DB2_UC", null); this.SetDam("DB2_RC", null); this.SetDam("DB2_RR", null); this.SetDam("DB2_SZ", null); //this.SetDam("DB2_SS",null); this.SetDam("DB2_DF", null); this.SetDam("MCN_NT", null); this.SetDam("MCN_UC", null); this.SetDam("MCN_RC", null); this.SetDam("MCN_RR", null); this.SetDam("MCN_SZ", null); //this.SetDam("MCN_SS",null); this.SetDam("MCN_DF", null); #endregion } #endregion #region エラーのスロー if ((parameterValue.ActionType.Split('%'))[1] == "Business") { // 業務例外のスロー throw new BusinessApplicationException( "ロールバックのテスト", "ロールバックのテスト", "エラー情報"); } else if ((parameterValue.ActionType.Split('%'))[1] == "System") { // システム例外のスロー throw new BusinessSystemException( "ロールバックのテスト", "ロールバックのテスト"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other") { // その他、一般的な例外のスロー throw new Exception("ロールバックのテスト"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other-Business") { // その他、一般的な例外(業務例外へ振り替え)のスロー throw new Exception("Other-Business"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other-System") { // その他、一般的な例外(システム例外へ振り替え)のスロー throw new Exception("Other-System"); } #endregion #endregion }
/// <summary> /// 業務処理を実装 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> protected override void UOC_DoAction(BaseParameterValue parameterValue, ref BaseReturnValue returnValue) { // 引数クラスをアップキャスト TestParameterValue testParameter = (TestParameterValue)parameterValue; // 戻り値クラスを生成 TestReturnValue testReturn = new TestReturnValue(); // 戻り値クラスをダウンキャストして戻す returnValue = (BaseReturnValue)testReturn; // --- // トランザクション パターンIDの領域 string[] transactionPatternIDs; // トランザクション グループIDからトランザクション パターンIDを取得 BaseLogic.GetTransactionPatterns( (string)testParameter.Obj, out transactionPatternIDs); // トランザクション パターンIDを設定 testReturn.Obj = transactionPatternIDs; #region Damを初期化 // トランザクション グループIDから取得した、 // トランザクション パターンIDでDam初期化する。 foreach (string transactionPatternID in transactionPatternIDs) { BaseDam tempDam = null; if (transactionPatternID.IndexOf("SQL") != -1) { // DamSqlSvrを初期化してセット tempDam = new DamSqlSvr(); BaseLogic.InitDam(transactionPatternID, tempDam); this.SetDam(transactionPatternID, tempDam); } else if (transactionPatternID.IndexOf("ODP") != -1) { // DamManagedOdpを初期化してセット tempDam = new DamManagedOdp(); BaseLogic.InitDam(transactionPatternID, tempDam); this.SetDam(transactionPatternID, tempDam); } else if (transactionPatternID.IndexOf("MCN") != -1) { // DamMySQLを初期化してセット tempDam = new DamMySQL(); BaseLogic.InitDam(transactionPatternID, tempDam); this.SetDam(transactionPatternID, tempDam); } } #endregion #region 終了時の状態選択 #region Damの状態選択 if ((parameterValue.ActionType.Split('%'))[2] == "UT") { // トランザクションあり } else if ((parameterValue.ActionType.Split('%'))[2] == "NT") { // トランザクションなし // → まえもってロールバックしておく // ロールバック foreach (string transactionPatternID in transactionPatternIDs) { this.GetDam(transactionPatternID).RollbackTransaction(); } } else if ((parameterValue.ActionType.Split('%'))[2] == "NC") { // コネクションなし // → まえもってロールバック、コネクションクローズしておく // // ※ トランザクションを開始して // コミットしないで閉じると、ロールバック扱い。 // ロールバック foreach (string transactionPatternID in transactionPatternIDs) { this.GetDam(transactionPatternID).RollbackTransaction(); } // コネクションクローズ foreach (string transactionPatternID in transactionPatternIDs) { this.GetDam(transactionPatternID).ConnectionClose(); } } else if ((parameterValue.ActionType.Split('%'))[2] == "NULL") { // データアクセス制御クラス = Null // → まえもってロールバック、コネクションクローズ、Nullクリアしておく // // ※ トランザクションを開始して // コミットしないで閉じると、ロールバック扱い。 // ロールバック foreach (string transactionPatternID in transactionPatternIDs) { this.GetDam(transactionPatternID).RollbackTransaction(); } // コネクションクローズ foreach (string transactionPatternID in transactionPatternIDs) { this.GetDam(transactionPatternID).ConnectionClose(); } // Nullクリア foreach (string transactionPatternID in transactionPatternIDs) { this.SetDam(transactionPatternID, null); } } #endregion #region エラーのスロー if ((parameterValue.ActionType.Split('%'))[1] == "Business") { // 業務例外のスロー throw new BusinessApplicationException( "ロールバックのテスト", "ロールバックのテスト", "エラー情報"); } else if ((parameterValue.ActionType.Split('%'))[1] == "System") { // システム例外のスロー throw new BusinessSystemException( "ロールバックのテスト", "ロールバックのテスト"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other") { // その他、一般的な例外のスロー throw new Exception("ロールバックのテスト"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other-Business") { // その他、一般的な例外(業務例外へ振り替え)のスロー throw new Exception("Other-Business"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other-System") { // その他、一般的な例外(システム例外へ振り替え)のスロー throw new Exception("Other-System"); } #endregion #endregion }
/// <summary> /// 業務コード呼び出しメソッド(業務ロジックの入り口) /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="iso">分離レベル(DBMS毎の分離レベルの違いを理解して設定すること)</param> /// <returns>戻り値クラス</returns> /// <remarks> /// クライアント側(2層C/S)用 /// 画面コード クラスから利用する。 /// </remarks> public BaseReturnValue DoBusinessLogic( BaseParameterValue parameterValue, DbEnum.IsolationLevelEnum iso) { // 戻り値クラス BaseReturnValue returnValue = null; // オリジナルのスタックトレース値のクリア this.OriginalStackTrace = ""; // データアクセス制御クラス(DAM)がグローバルなので、全てロックする。 lock (BaseLogic2CS._lock) { if (BaseLogic2CS._dam == null) { // データアクセス制御クラス(DAM)が無い場合 // ★データアクセス制御クラス(DAM)の生成し、コネクションを確立、 // トランザクションを開始する処理(業務フレームワークに、UOCで実装する) this.UOC_ConnectionOpen(parameterValue, iso); } else { // データアクセス制御クラス(DAM)が有る場合 } try { // 自動振り分け対応 this.WasCalledFromDoBusinessLogic = true; // ★前処理(業務フレームワークに、UOCで実装する) this.UOC_PreAction(parameterValue); // ★業務ロジックの実行(業務処理の派生クラスに、UOCで実装する) this.UOC_DoAction(parameterValue, ref returnValue); // ★後処理(業務フレームワークに、UOCで実装する) this.UOC_AfterAction(parameterValue, returnValue); //// トランザクション終了 //BaseLogic2CS._dam.CommitTransaction(); //// ★トランザクション完了後の後処理(業務フレームワークに、UOCで実装する) //this.UOC_AfterTransaction(parameterValue, returnValue); } catch (BusinessApplicationException baEx)// 業務例外 { // ★★業務例外時のロールバックは自動にしない。 // 業務例外の場合、エラーフラグをセットする。 // 戻り値がnullの場合は、生成する。 if (returnValue == null) { returnValue = new BaseReturnValue(); } returnValue.ErrorFlag = true; // メッセージを戻す(戻り値クラスに設定)。 returnValue.ErrorMessageID = baEx.messageID; returnValue.ErrorMessage = baEx.Message; returnValue.ErrorInfo = baEx.Information; // ★異常系の後処理(業務フレームワークに、UOCで実装する) this.UOC_ABEND(parameterValue, returnValue, baEx); // 正常系の戻り値にして戻すため、リスローしない。 } catch (BusinessSystemException bsEx)// システム例外 { // ★システム例外時は、自動的にロールバック。 // 2009/03/13---B層内:トランザクション手動制御を可能に(ここから) // トランザクションをロールバック if (BaseLogic2CS._dam == null) { // nullの場合はロールバックしない(何もしない)。 } else { // 例外対策(例外は潰さない) try { // nullでない場合はロールバックする。 BaseLogic2CS._dam.RollbackTransaction(); // コネクション クローズ BaseLogic2CS._dam.ConnectionClose(); } finally { // nullクリア(次回、再接続される。) BaseLogic2CS._dam = null; } } // 2009/03/13---B層内:トランザクション手動制御を可能に(ここまで) // 戻り値がnullの場合は、生成する。 if (returnValue == null) { returnValue = new BaseReturnValue(); } // ★異常系の後処理(業務フレームワークに、UOCで実装する) this.UOC_ABEND(parameterValue, returnValue, bsEx); // リスロー throw; } catch (Exception Ex)// その他、一般的な例外 { // ★その他、一般的な例外は、自動的にロールバック。 // 2009/03/13---B層内:トランザクション手動制御を可能に(ここから) // トランザクションをロールバック if (BaseLogic2CS._dam == null) { // nullの場合はロールバックしない(何もしない)。 } else { // 例外対策(例外は潰さない) try { // nullでない場合はロールバックする。 BaseLogic2CS._dam.RollbackTransaction(); // コネクション クローズ BaseLogic2CS._dam.ConnectionClose(); } finally { // nullクリア(次回、再接続される。) BaseLogic2CS._dam = null; } } // 2009/03/13---B層内:トランザクション手動制御を可能に(ここまで) // 戻り値がnullの場合は、生成する。 if (returnValue == null) { returnValue = new BaseReturnValue(); } // ★異常系の後処理(業務フレームワークに、UOCで実装する) this.UOC_ABEND(parameterValue, ref returnValue, Ex); // リスローしない(上記のUOC_ABENDで必要に応じてリスロー) // throw; } finally { // 自動振り分け対応 this.WasCalledFromDoBusinessLogic = false; // クライアント側(2層C/S)用では、マニュアル操作だが、 // ノートランザクションの時は、都度コネクションを閉じる。 // Damオブジェクトの存在チェック if (BaseLogic2CS._dam == null) { // nullのためなにもしない。 } else { // ノートランザクションの時は、都度コネクションを閉じる。 if (iso == DbEnum.IsolationLevelEnum.NoTransaction) { // 例外対策(例外は潰さない) try { // コネクション クローズ BaseLogic2CS._dam.ConnectionClose(); } finally { // nullクリア(次回の「DoBusinessLogic_2CS」で再接続される。) BaseLogic2CS._dam = null; } } } } } // 戻り値を戻す。 return(returnValue); }
/// <summary> /// B層のシステム例外による異常終了の後処理を実装するUOCメソッド。 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <param name="bsEx">BusinessSystemException</param> /// <remarks>派生の業務コード親クラス2でオーバーライドする。</remarks> protected virtual void UOC_ABEND(BaseParameterValue parameterValue, BaseReturnValue returnValue, BusinessSystemException bsEx) { }
/// <summary> /// B層の業務例外による異常終了の後処理を実装するUOCメソッド。 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <param name="baEx">BusinessApplicationException</param> /// <remarks>派生の業務コード親クラス2でオーバーライドする。</remarks> protected virtual void UOC_ABEND(BaseParameterValue parameterValue, BaseReturnValue returnValue, BusinessApplicationException baEx) { }
/// <summary> /// B層のトランザクションのコミット後の終了処理を実装 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <remarks>派生の業務コード親クラス2でオーバーライドする。</remarks> protected virtual void UOC_AfterTransaction(BaseParameterValue parameterValue, BaseReturnValue returnValue) { }
/// <summary> /// 業務処理を実装 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <remarks>派生の業務コード クラスでオーバーライドする。</remarks> protected abstract void UOC_DoAction(BaseParameterValue parameterValue, ref BaseReturnValue returnValue);
/// <summary> /// 業務コード呼び出しメソッド(業務ロジックの入り口) /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="iso">分離レベル(DBMS毎の分離レベルの違いを理解して設定すること)</param> /// <returns>戻り値クラス</returns> /// <remarks>画面コード クラスから利用する。</remarks> public BaseReturnValue DoBusinessLogic( BaseParameterValue parameterValue, DbEnum.IsolationLevelEnum iso) { // 戻り値クラス BaseReturnValue returnValue = null; // オリジナルのスタックトレース値のクリア this.OriginalStackTrace = ""; // ★データアクセス制御クラス(DAM)の生成し、コネクションを確立、 // トランザクションを開始する処理(業務フレームワークに、UOCで実装する) // this._dam = this.UOC_ConnectionOpen(parameterValue, iso); this.UOC_ConnectionOpen(parameterValue, iso); try { // 自動振り分け対応 this.WasCalledFromDoBusinessLogic = true; // ★前処理(業務フレームワークに、UOCで実装する) this.UOC_PreAction(parameterValue); // ★業務ロジックの実行(業務処理の派生クラスに、UOCで実装する) this.UOC_DoAction(parameterValue, ref returnValue); // ★後処理(業務フレームワークに、UOCで実装する) this.UOC_AfterAction(parameterValue, returnValue); #region トランザクションをコミット // 2009/03/13---B層内:トランザクション手動制御を可能に(ここから) if (this._dam == null) { // nullの場合はコミットしない(何もしない)。 } else { // nullでない場合はコミットする。 this._dam.CommitTransaction(); } // 2009/03/13---B層内:トランザクション手動制御を可能に(ここまで) // 2009/03/28---データアクセス制御クラスを配列化(ここから) foreach (string key in this._dams.Keys) { // ここはforeachで取るので「キーなし」にならない if (this._dams[key] == null) { // nullの場合はコミットしない(何もしない)。 } else { // nullでない場合はコミットする。 ((BaseDam)this._dams[key]).CommitTransaction(); } } // 2009/03/28---データアクセス制御クラスを配列化(ここまで) #endregion // ★トランザクション完了後の後処理(業務フレームワークに、UOCで実装する) this.UOC_AfterTransaction(parameterValue, returnValue); } catch (BusinessApplicationException baEx)// 業務例外 { #region トランザクションをロールバック // 2009/03/13---B層内:トランザクション手動制御を可能に(ここから) if (this._dam == null) { // nullの場合はロールバックしない(何もしない)。 } else { // nullでない場合はロールバックする。 this._dam.RollbackTransaction(); } // 2009/03/13---B層内:トランザクション手動制御を可能に(ここまで) // 2009/03/28---データアクセス制御クラスを配列化(ここから) foreach (string key in this._dams.Keys) { // ここはforeachで取るので「キーなし」にならない if (this._dams[key] == null) { // nullの場合はロールバックしない(何もしない)。 } else { // nullでない場合はロールバックする。 ((BaseDam)this._dams[key]).RollbackTransaction(); } } // 2009/03/28---データアクセス制御クラスを配列化(ここまで) #endregion // 業務例外の場合、エラーフラグをセットする。 // 戻り値がnullの場合は、生成する。 if (returnValue == null) { returnValue = new BaseReturnValue(); } returnValue.ErrorFlag = true; // メッセージを戻す(戻り値クラスに設定)。 returnValue.ErrorMessageID = baEx.messageID; returnValue.ErrorMessage = baEx.Message; returnValue.ErrorInfo = baEx.Information; // ★異常系の後処理(業務フレームワークに、UOCで実装する) this.UOC_ABEND(parameterValue, returnValue, baEx); // 正常系の戻り値にして戻すため、リスローしない。 } catch (BusinessSystemException bsEx)// システム例外 { #region トランザクションをロールバック // 2009/03/13---B層内:トランザクション手動制御を可能に(ここから) if (this._dam == null) { // nullの場合はロールバックしない(何もしない)。 } else { // nullでない場合はロールバックする。 this._dam.RollbackTransaction(); } // 2009/03/13---B層内:トランザクション手動制御を可能に(ここまで) // 2009/03/28---データアクセス制御クラスを配列化(ここから) foreach (string key in this._dams.Keys) { // ここはforeachで取るので「キーなし」にならない if (this._dams[key] == null) { // nullの場合はロールバックしない(何もしない)。 } else { // nullでない場合はロールバックする。 ((BaseDam)this._dams[key]).RollbackTransaction(); } } // 2009/03/28---データアクセス制御クラスを配列化(ここまで) #endregion // 戻り値がnullの場合は、生成する。 if (returnValue == null) { returnValue = new BaseReturnValue(); } // ★異常系の後処理(業務フレームワークに、UOCで実装する) this.UOC_ABEND(parameterValue, returnValue, bsEx); // リスロー throw; } catch (Exception Ex)// その他、一般的な例外 { #region トランザクションをロールバック // 2009/03/13---B層内:トランザクション手動制御を可能に(ここから) if (this._dam == null) { // nullの場合はロールバックしない(何もしない)。 } else { // nullでない場合はロールバックする。 this._dam.RollbackTransaction(); } // 2009/03/13---B層内:トランザクション手動制御を可能に(ここまで) // 2009/03/28---データアクセス制御クラスを配列化(ここから) foreach (string key in this._dams.Keys) { // ここはforeachで取るので「キーなし」にならない if (this._dams[key] == null) { // nullの場合はロールバックしない(何もしない)。 } else { // nullでない場合はロールバックする。 ((BaseDam)this._dams[key]).RollbackTransaction(); } } // 2009/03/28---データアクセス制御クラスを配列化(ここまで) #endregion // 戻り値がnullの場合は、生成する。 if (returnValue == null) { returnValue = new BaseReturnValue(); } // ★異常系の後処理(業務フレームワークに、UOCで実装する) this.UOC_ABEND(parameterValue, ref returnValue, Ex); // リスローしない(上記のUOC_ABENDで必要に応じてリスロー) // throw; } finally { // 自動振り分け対応 this.WasCalledFromDoBusinessLogic = false; #region コネクションを閉じる // 2009/03/13---B層内:トランザクション手動制御を可能に(ここから) if (this._dam == null) { // nullのためなにもしない。 } else { // コネクションを閉じる。 this._dam.ConnectionClose(); } // 2009/03/13---B層内:トランザクション手動制御を可能に(ここまで) // 2009/03/28---データアクセス制御クラスを配列化(ここから) foreach (string key in this._dams.Keys) { // ここはforeachで取るので「キーなし」にならない if (this._dams[key] == null) { // nullのためなにもしない。 } else { // コネクションを閉じる。 ((BaseDam)this._dams[key]).ConnectionClose(); } } // 2009/03/28---データアクセス制御クラスを配列化(ここまで) #endregion } // 戻り値を戻す。 return(returnValue); }
/// <summary>業務処理を実装</summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> protected override void UOC_DoAction(BaseParameterValue parameterValue, ref BaseReturnValue returnValue) { // 戻り値を生成しておく。 returnValue = new MyReturnValue(); // 自動トランザクションで開始したトランザクションを閉じる。 this.GetDam().CommitTransaction(); // コネクションを閉じる。 this.GetDam().ConnectionClose(); // データアクセス制御クラスをクリア。 this.SetDam(null); // Dam用ワーク BaseDam damWork; // 共通Dao CmnDao cmnDao; // カバレージ上げ用 IDbConnection idcnn = null; IDbTransaction idtx = null; IDbCommand idcmd = null; IDataAdapter idapt = null; DataSet ds = null; // SQLの戻り値を受ける object obj; #region SQL Server damWork = new DamSqlSvr(); #region 接続しない BaseLogic.InitDam("XXXX", damWork); this.SetDam(damWork); // なにもしない。 // プロパティにアクセス(デバッガで確認) idcnn = ((DamSqlSvr)this.GetDam()).DamSqlConnection; idtx = ((DamSqlSvr)this.GetDam()).DamSqlTransaction; // nullの時に呼んだ場合。 this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region SQL_NT BaseLogic.InitDam("SQL_NT", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region SQL_UC BaseLogic.InitDam("SQL_UC", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region SQL_RC BaseLogic.InitDam("SQL_RC", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); // プロパティにアクセス(デバッガで確認) idcnn = ((DamSqlSvr)this.GetDam()).DamSqlConnection; idtx = ((DamSqlSvr)this.GetDam()).DamSqlTransaction; idcmd = ((DamSqlSvr)this.GetDam()).DamSqlCommand; idapt = ((DamSqlSvr)this.GetDam()).DamSqlDataAdapter; ds = new DataSet(); idapt.Fill(ds); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); // 2連続で呼んだ場合。 this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region SQL_RR BaseLogic.InitDam("SQL_RR", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region SQL_SZ BaseLogic.InitDam("SQL_SZ", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region SQL_SS BaseLogic.InitDam("SQL_SS", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region SQL_DF BaseLogic.InitDam("SQL_DF", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #endregion #region Oracle damWork = new DamManagedOdp(); #region 接続しない BaseLogic.InitDam("XXXX", damWork); this.SetDam(damWork); // なにもしない。 // プロパティにアクセス(デバッガで確認) idcnn = ((DamManagedOdp)this.GetDam()).DamOracleConnection; idtx = ((DamManagedOdp)this.GetDam()).DamOracleTransaction; // nullの時に呼んだ場合。 this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region ODP_NT BaseLogic.InitDam("ODP_NT", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region ODP_UC // ★ サポートされない分離レベル #endregion #region ODP_RC BaseLogic.InitDam("ODP_RC", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); // プロパティにアクセス(デバッガで確認) idcnn = ((DamManagedOdp)this.GetDam()).DamOracleConnection; idtx = ((DamManagedOdp)this.GetDam()).DamOracleTransaction; idcmd = ((DamManagedOdp)this.GetDam()).DamOracleCommand; idapt = ((DamManagedOdp)this.GetDam()).DamOracleDataAdapter; ds = new DataSet(); idapt.Fill(ds); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); // 2連続で呼んだ場合。 this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region ODP_RR // ★ サポートされない分離レベル #endregion #region ODP_SZ BaseLogic.InitDam("ODP_SZ", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region ODP_SS // ★ サポートされない分離レベル #endregion #region ODP_DF BaseLogic.InitDam("ODP_DF", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #endregion #region MySQL damWork = new DamMySQL(); #region 接続しない BaseLogic.InitDam("XXXX", damWork); this.SetDam(damWork); // なにもしない。 // プロパティにアクセス(デバッガで確認) idcnn = ((DamMySQL)this.GetDam()).DamMySqlConnection; idtx = ((DamMySQL)this.GetDam()).DamMySqlTransaction; // nullの時に呼んだ場合。 this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region MCN_NT BaseLogic.InitDam("MCN_NT", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); //this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region MCN_UC BaseLogic.InitDam("MCN_UC", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region MCN_RC BaseLogic.InitDam("MCN_RC", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); // プロパティにアクセス(デバッガで確認) idcnn = ((DamMySQL)this.GetDam()).DamMySqlConnection; idtx = ((DamMySQL)this.GetDam()).DamMySqlTransaction; idcmd = ((DamMySQL)this.GetDam()).DamMySqlCommand; idapt = ((DamMySQL)this.GetDam()).DamMySqlDataAdapter; ds = new DataSet(); idapt.Fill(ds); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); // 2連続で呼んだ場合。 this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region MCN_RR BaseLogic.InitDam("MCN_RR", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region MCN_SZ BaseLogic.InitDam("MCN_SZ", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #region MCN_SS // ★ サポートされない分離レベル #endregion #region MCN_DF BaseLogic.InitDam("MCN_DF", damWork); this.SetDam(damWork); // 行数 // Damを直接使用することもできるが、 // 通常は、データアクセスにはDaoを使用する。 cmnDao = new CmnDao(this.GetDam()); cmnDao.SQLText = "SELECT COUNT(*) FROM SHIPPERS"; obj = (object)cmnDao.ExecSelectScalar(); this.GetDam().CommitTransaction(); this.GetDam().ConnectionClose(); #endregion #endregion #region エラー処理(ロールバックのテスト) if ((parameterValue.ActionType.Split('%'))[1] != "-") { #region エラー時のDamの状態選択 if ((parameterValue.ActionType.Split('%'))[2] == "UT") { // トランザクションあり damWork = new DamSqlSvr(); damWork.ConnectionOpen(GetConfigParameter.GetConnectionString("ConnectionString_SQL")); damWork.BeginTransaction(DbEnum.IsolationLevelEnum.ReadCommitted); this.SetDam(damWork); } else if ((parameterValue.ActionType.Split('%'))[2] == "NT") { // トランザクションなし damWork = new DamSqlSvr(); damWork.ConnectionOpen(GetConfigParameter.GetConnectionString("ConnectionString_SQL")); this.SetDam(damWork); } else if ((parameterValue.ActionType.Split('%'))[2] == "NC") { // コネクションなし damWork = new DamSqlSvr(); this.SetDam(damWork); } else if ((parameterValue.ActionType.Split('%'))[2] == "NULL") { // データアクセス制御クラス = Null this.SetDam(null); } #endregion #region エラーのスロー if ((parameterValue.ActionType.Split('%'))[1] == "Business") { // 業務例外のスロー throw new BusinessApplicationException( "ロールバックのテスト", "ロールバックのテスト", "エラー情報"); } else if ((parameterValue.ActionType.Split('%'))[1] == "System") { // システム例外のスロー throw new BusinessSystemException( "ロールバックのテスト", "ロールバックのテスト"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other") { // その他、一般的な例外のスロー throw new Exception("ロールバックのテスト"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other-Business") { // その他、一般的な例外(業務例外へ振り替え)のスロー throw new Exception("Other-Business"); } else if ((parameterValue.ActionType.Split('%'))[1] == "Other-System") { // その他、一般的な例外(システム例外へ振り替え)のスロー throw new Exception("Other-System"); } #endregion } #endregion }
/// <summary> /// WCF TCP/IPサービスを使用した /// サービス インターフェイス基盤(.NETオンライン) /// </summary> /// <param name="serviceName">サービス名</param> /// <param name="contextObject">コンテキスト</param> /// <param name="parameterValueObject">引数</param> /// <param name="returnValueObject">戻り値</param> /// <returns>返すべきエラーの情報</returns> /// <remarks>値は全て.NETオブジェクトをバイナリシリアライズしたバイト配列データ</remarks> public byte[] DotNETOnlineTCP( string serviceName, ref byte[] contextObject, byte[] parameterValueObject, out byte[] returnValueObject) { // ステータス string status = "-"; // 初期化のため returnValueObject = null; #region 呼出し制御関係の変数 // アセンブリ名 string assemblyName = ""; // クラス名 string className = ""; #endregion #region 引数・戻り値関係の変数 // コンテキスト情報 object context; // 2009/09/29-この行 // 引数・戻り値の.NETオブジェクト BaseParameterValue parameterValue = null; BaseReturnValue returnValue = null; // エラー情報(クライアント側で復元するため) WSErrorInfo wsErrorInfo = new WSErrorInfo(); // エラー情報(ログ出力用) string errorType = ""; // 2009/09/15-この行 string errorMessageID = ""; string errorMessage = ""; string errorToString = ""; #endregion try { // 開始ログの出力 LogIF.InfoLog("SERVICE-IF", FxLiteral.SIF_STATUS_START); #region 前解決 // ★ status = FxLiteral.SIF_STATUS_NAME_SERVICE; // 名前解決(インプロセス) WCFTCPSvcForFx.IPR_NS.NameResolution(serviceName, out assemblyName, out className); #endregion #region 引数のデシリアライズ // ★ status = FxLiteral.SIF_STATUS_DESERIALIZE; // コンテキストクラスの.NETオブジェクト化 context = BinarySerialize.BytesToObject(contextObject); // 2009/09/29-この行 // ※ コンテキストの利用方法は任意だが、サービスインターフェイス上での利用に止める。 // 引数クラスの.NETオブジェクト化 parameterValue = (BaseParameterValue)BinarySerialize.BytesToObject(parameterValueObject); // 引数クラスをパラメタ セットに格納 object[] paramSet = new object[] { parameterValue, DbEnum.IsolationLevelEnum.User }; #endregion #region 認証処理のUOC // ★ status = FxLiteral.SIF_STATUS_AUTHENTICATION; // ★★ コンテキストの情報を使用するなどして // 認証処理をUOCする(必要に応じて)。 //// 認証チケットの復号化 //string[] authTicket = (string[])BinarySerialize.BytesToObject( // CustomEncode.FromBase64String( // SymmetricCryptography.DecryptString( // (string)context, GetConfigParameter.GetConfigValue("private-key"), // EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider))); //// 認証チケットの整合性を確認 //// B層・D層呼出し //// スライディング・タイムアウトの実装、 //// タイムスタンプのチェックと、更新 //returnValue = (BaseReturnValue)Latebind.InvokeMethod( // "xxxx", "yyyy", // FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, // new object[] { new AuthParameterValue("-", "-", "zzzz", "", // ((MyParameterValue)parameterValue).User, authTicket[1]), // DbEnum.IsolationLevelEnum.User }); //if (returnValue.ErrorFlag) //{ // // 認証エラー // throw new BusinessSystemException("xxxx", "認証チケットが不正か、タイムアウトです。"); //} // 持ち回るならCookieにするか、 // contextをrefにするなどとする。 contextObject = BinarySerialize.ObjectToBytes(DateTime.Now); // 更新されたかのテストコード #endregion #region B層・D層呼出し // ★ status = FxLiteral.SIF_STATUS_INVOKE; // #17-start try { // B層・D層呼出し //returnValue = (BaseReturnValue)Latebind.InvokeMethod( // AppDomain.CurrentDomain.BaseDirectory + "\\bin\\" + assemblyName + ".dll", // className, FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, paramSet); returnValue = (BaseReturnValue)Latebind.InvokeMethod( assemblyName, className, FxLiteral.TRANSMISSION_INPROCESS_METHOD_NAME, paramSet); } catch (System.Reflection.TargetInvocationException rtEx) { //// InnerExceptionを投げなおす。 //throw rtEx.InnerException; // スタックトレースを保って InnerException を throw ExceptionDispatchInfo.Capture(rtEx.InnerException).Throw(); } // #17-end #endregion #region 戻り値のシリアライズ // ★ status = FxLiteral.SIF_STATUS_SERIALIZE; returnValueObject = BinarySerialize.ObjectToBytes(returnValue); #endregion // ★ status = ""; // 戻り値を返す。 return(null); } catch (BusinessSystemException bsEx) { // システム例外 // エラー情報を設定する。 wsErrorInfo.ErrorType = FxEnum.ErrorType.BusinessSystemException; wsErrorInfo.ErrorMessageID = bsEx.messageID; wsErrorInfo.ErrorMessage = bsEx.Message; // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.BusinessSystemException.ToString(); // 2009/09/15-この行 errorMessageID = bsEx.messageID; errorMessage = bsEx.Message; errorToString = bsEx.ToString(); // エラー情報を戻す。 return(BinarySerialize.ObjectToBytes(wsErrorInfo)); } catch (FrameworkException fxEx) { // フレームワーク例外 // ★ インナーエクセプション情報は消失 // エラー情報を設定する。 wsErrorInfo.ErrorType = FxEnum.ErrorType.FrameworkException; wsErrorInfo.ErrorMessageID = fxEx.messageID; wsErrorInfo.ErrorMessage = fxEx.Message; // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.FrameworkException.ToString(); // 2009/09/15-この行 errorMessageID = fxEx.messageID; errorMessage = fxEx.Message; errorToString = fxEx.ToString(); // エラー情報を戻す。 return(BinarySerialize.ObjectToBytes(wsErrorInfo)); } catch (Exception ex) { // ログ出力用の情報を保存 errorType = FxEnum.ErrorType.ElseException.ToString(); // 2009/09/15-この行 errorMessageID = "-"; errorMessage = ex.Message; errorToString = ex.ToString(); throw; // SoapExceptionになって伝播 } finally { // Sessionステートレス //HttpContext.Current.Session.Clear(); //HttpContext.Current.Session.Abandon(); // 終了ロクの出力 if (status == "") { // 終了ログ出力 LogIF.InfoLog("SERVICE-IF", "正常終了"); } else { // 終了ログ出力 LogIF.ErrorLog("SERVICE-IF", "異常終了" + ":" + status + "\r\n" + "エラー タイプ:" + errorType + "\r\n" // 2009/09/15-この行 + "エラー メッセージID:" + errorMessageID + "\r\n" + "エラー メッセージ:" + errorMessage + "\r\n" + errorToString + "\r\n"); } } }
/// <summary> /// B層のトランザクションのコミット後の終了処理を実装 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <remarks>業務コード親クラス1から利用される派生の末端</remarks> protected override void UOC_AfterTransaction(BaseParameterValue parameterValue, BaseReturnValue returnValue) { // TODO: }
/// <summary> /// B層の一般的な例外による異常終了の後処理を実装するUOCメソッド。 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <param name="ex">Exception</param> /// <remarks>業務コード親クラス1から利用される派生の末端</remarks> protected override void UOC_ABEND(BaseParameterValue parameterValue, ref BaseReturnValue returnValue, Exception ex) { // 一般的な例外発生時の処理を実装 // TODO: // nullチェック if (this.perfRec == null) { // なにもしない // リスロー throw ex; } else { // 性能測定終了 this.perfRec.EndsPerformanceRecord(); // キャスト MyParameterValue myPV = (MyParameterValue)parameterValue; // システム例外に振り替える用のワーク bool sysErrorFlag = false; string sysErrorMessageID = ""; string sysErrorMessage = ""; #region 例外の振替処理のIF文 if (ex.Message == "Other-Business") { // 業務例外へ変換 returnValue.ErrorFlag = true; returnValue.ErrorMessageID = "振替後"; returnValue.ErrorMessage = "振替後"; returnValue.ErrorInfo = "振り替える場合は、基本的にここを利用。"; } else if (ex.Message == "Other-System") { // システム例外へ振替 sysErrorFlag = true; sysErrorMessageID = "振替後"; sysErrorMessage = "振替後"; } #endregion #region ACCESSログ出力、リスローする・しない if (returnValue.ErrorFlag) { // 業務例外へ変換 // ------------ // メッセージ部 // ------------ // ユーザ名, IPアドレス, レイヤ, // 画面名, コントロール名, メソッド名, 処理名 // 処理時間(実行時間), 処理時間(CPU時間) // エラーメッセージID, エラーメッセージ等 // ------------ string strLogMessage = "," + myPV.User.UserName + "," + myPV.User.IPAddress + "," + "<<-----" + "," + myPV.ScreenId + "," + myPV.ControlId + "," + myPV.MethodName + "," + myPV.ActionType + "," + this.perfRec.ExecTime + "," + this.perfRec.CpuTime + "," + returnValue.ErrorMessageID + "," + returnValue.ErrorMessage; // Log4Netへログ出力 LogIF.WarnLog("ACCESS", strLogMessage); } else if (sysErrorFlag) { // システム例外へ振替 // ------------ // メッセージ部 // ------------ // ユーザ名, IPアドレス, レイヤ, // 画面名, コントロール名, メソッド名, 処理名 // 処理時間(実行時間), 処理時間(CPU時間) // エラーメッセージID, エラーメッセージ等 // ------------ string strLogMessage = "," + myPV.User.UserName + "," + myPV.User.IPAddress + "," + "<<-----" + "," + myPV.ScreenId + "," + myPV.ControlId + "," + myPV.MethodName + "," + myPV.ActionType + "," + this.perfRec.ExecTime + "," + this.perfRec.CpuTime + "," + sysErrorMessageID + "," + sysErrorMessage + "\r\n" + ex.StackTrace; // Log4Netへログ出力 LogIF.ErrorLog("ACCESS", strLogMessage); // 振替てスロー throw new BusinessSystemException(sysErrorMessageID, sysErrorMessage); } else { // そのまま // ------------ // メッセージ部 // ------------ // ユーザ名, IPアドレス, レイヤ, // 画面名, コントロール名, メソッド名, 処理名 // 処理時間(実行時間), 処理時間(CPU時間) // エラーメッセージID, エラーメッセージ等 // ------------ string strLogMessage = "," + myPV.User.UserName + "," + myPV.User.IPAddress + "," + "<<-----" + "," + myPV.ScreenId + "," + myPV.ControlId + "," + myPV.MethodName + "," + myPV.ActionType + "," + this.perfRec.ExecTime + "," + this.perfRec.CpuTime + "," + "other Exception" + "," + ex.Message + "\r\n" + ex.StackTrace; // Log4Netへログ出力 LogIF.ErrorLog("ACCESS", strLogMessage); // リスロー throw ex; } #endregion } }
/// <summary> /// B層の一般的な例外による異常終了の後処理を実装するUOCメソッド。 /// </summary> /// <param name="parameterValue">引数クラス</param> /// <param name="returnValue">戻り値クラス</param> /// <param name="ex">Exception</param> /// <remarks>派生の業務コード親クラス2でオーバーライドする。</remarks> protected virtual void UOC_ABEND(BaseParameterValue parameterValue, ref BaseReturnValue returnValue, Exception ex) { }