/// <summary>Connectionオブジェクト生成メソッド</summary> /// <returns>IDbConnection</returns> public static IDbConnection CreateConnection() { switch (ASPNETIdentityConfig.UserStoreType) { case EnumUserStoreType.SqlServer: //return new SqlConnection(GetConfigParameter.GetConnectionString("ConnectionString_SQL")); return(new ProfiledDbConnection( new SqlConnection(GetConfigParameter.GetConnectionString("ConnectionString_SQL")), new TraceDbProfiler())); case EnumUserStoreType.ODPManagedDriver: //return new OracleConnection(GetConfigParameter.GetConnectionString("ConnectionString_ODP")); return(new ProfiledDbConnection( new OracleConnection(GetConfigParameter.GetConnectionString("ConnectionString_ODP")), new TraceDbProfiler())); case EnumUserStoreType.PostgreSQL: //return new NpgsqlConnection(GetConfigParameter.GetConnectionString("ConnectionString_NPS")); return(new ProfiledDbConnection( new NpgsqlConnection(GetConfigParameter.GetConnectionString("ConnectionString_NPS")), new TraceDbProfiler())); default: return(null); } }
/// <summary>Damの初期化</summary> private void InitDam() { // Initializes dam this._dam = new DamSqlSvr(); this._dam.Obj = new MyUserInfo("WorkflowTest", "127.0.0.1"); // Gets the connection string from config and open the db connection this._dam.ConnectionOpen(GetConfigParameter.GetConnectionString("ConnectionString_SQL")); this._dam.BeginTransaction(DbEnum.IsolationLevelEnum.ReadCommitted); }
/// <summary>開始処理</summary> private void Form1_Load(object sender, EventArgs e) { // イベントハンドラ this.dataGridView1.DataError += new DataGridViewDataErrorEventHandler(DataGridView_DataError); // ステータス this.cmbTSColType.SelectedIndex = 0; this.cmbTableType.SelectedIndex = 0; dam = new DamSqlSvr(); dam.Obj = new MyUserInfo("userName", Environment.MachineName); this.dam.ConnectionOpen(GetConfigParameter.GetConnectionString("ConnectionString_SQL")); }
/// <summary>ロード</summary> private void Form1_Load(object sender, EventArgs e) { // 現状SQLServerのみ対応 this.txtCnnstr.Text = GetConfigParameter.GetConnectionString("ConnectionString_SQL"); this.txtSubSystemId.Text = GetConfigParameter.GetConfigValue("SubSystemId"); this.txtWorkflowName.Text = GetConfigParameter.GetConfigValue("WorkflowName"); // SQLは埋め込まれたリソースを使用する。 Touryo.Infrastructure.Business.Dao.MyBaseDao.UseEmbeddedResource = true; // タブ this.tabControl1.SelectedTab = this.tabControl1.TabPages[1]; this.tabControl1.SelectedTab = this.tabControl1.TabPages[0]; // GetUserInfoDelegateの設定 if (Workflow.GetUserInfo == null) { Workflow.GetUserInfo = new GetUserInfoDelegate(this.MyGetUserInfo); } }
/// <summary>データアクセス制御クラス(DAM)の生成し、コネクションを確立、トランザクションを開始する処理を実装</summary> /// <param name="parameterValue">引数クラス</param> /// <param name="iso">分離レベル(DBMS毎の分離レベルの違いを理解して設定すること)</param> /// <remarks>業務コード親クラス1から利用される派生の末端</remarks> protected override void UOC_ConnectionOpen( BaseParameterValue parameterValue, DbEnum.IsolationLevelEnum iso) { #region トランザクション属性取得例 //// クラスの属性、メソッドの属性から調査 //MyAttribute[] aryMCA; //MyAttribute[] aryMMA; //// クラスの属性を取得 //MyAttribute.GetAttr(this, out aryMCA); //foreach (MyAttribute mca in aryMCA) //{ // Debug.WriteLine(this.GetType().ToString() + ".MyAttributeA = " + mca.MyAttributeA); // Debug.WriteLine(this.GetType().ToString() + ".MyAttributeB = " + mca.MyAttributeB); // Debug.WriteLine(this.GetType().ToString() + ".MyAttributeC = " + mca.MyAttributeC); // Debug.WriteLine("+------------------+"); //} //// メソッドの属性を取得 //MethodInfo[] aryMtdInfo = this.GetType().GetMethods(); //foreach (MethodInfo mtdInfo in aryMtdInfo) //{ // MyAttribute.GetAttr(mtdInfo, out aryMMA); // foreach (MyAttribute mma in aryMMA) // { // Debug.WriteLine(mtdInfo.Name + ".MyAttributeA = " + mma.MyAttributeA); // Debug.WriteLine(mtdInfo.Name + ".MyAttributeB = " + mma.MyAttributeB); // Debug.WriteLine(mtdInfo.Name + ".MyAttributeC = " + mma.MyAttributeC); // Debug.WriteLine("+------------------+"); // } //} #endregion // データアクセス制御クラス(DAM) BaseDam dam = null; #region 接続 if (iso == DbEnum.IsolationLevelEnum.NotConnect) { // 接続しない } else { // 接続する string connstring = ""; #region データ プロバイダ選択 if (parameterValue.ActionType.Split('%')[0] == "SQL") { // SQL Server / SQL Client用のDamを生成 dam = new DamSqlSvr(); // 接続文字列をロード connstring = GetConfigParameter.GetConnectionString("ConnectionString_SQL"); } else if (parameterValue.ActionType.Split('%')[0] == "OLE") { // OLEDB.NET用のDamを生成 dam = new DamOLEDB(); // 接続文字列をロード connstring = GetConfigParameter.GetConnectionString("ConnectionString_OLE"); } else if (parameterValue.ActionType.Split('%')[0] == "ODB") { // ODBC.NET用のDamを生成 dam = new DamODBC(); // 接続文字列をロード connstring = GetConfigParameter.GetConnectionString("ConnectionString_ODBC"); } else if (parameterValue.ActionType.Split('%')[0] == "ORA") { // Oracle / Oracle Client用のDamを生成 dam = new DamOraClient(); // 接続文字列をロード connstring = GetConfigParameter.GetConnectionString("ConnectionString_ORA"); } else if (parameterValue.ActionType.Split('%')[0] == "ODP") { // Oracle / ODP.NET用のDamを生成 dam = new DamOraOdp(); // 接続文字列をロード(ODP2:Instant Client) connstring = GetConfigParameter.GetConnectionString("ConnectionString_ODP2"); } else if (parameterValue.ActionType.Split('%')[0] == "DB2") { // DB2.NET用のDamを生成 dam = new DamDB2(); // 接続文字列をロード connstring = GetConfigParameter.GetConnectionString("ConnectionString_DB2"); } //else if (parameterValue.ActionType.Split('%')[0] == "HIR") //{ // // HiRDBデータプロバイダ用のDamを生成 // dam = new DamHiRDB(); // // 接続文字列をロード // connstring = GetConfigParameter.GetConnectionString("ConnectionString_HIR"); //} else if (parameterValue.ActionType.Split('%')[0] == "MCN") { // MySQL Cnn/NET用のDamを生成 dam = new DamMySQL(); // 接続文字列をロード connstring = GetConfigParameter.GetConnectionString("ConnectionString_MCN"); } else if (parameterValue.ActionType.Split('%')[0] == "NPS") { // PostgreSQL / Npgsql用のDamを生成 dam = new DamPstGrS(); // 接続文字列をロード connstring = GetConfigParameter.GetConnectionString("ConnectionString_NPS"); } else { // ここは通らない } #endregion if (dam != null) { // コネクションをオープンする。 dam.ConnectionOpen(connstring); #region トランザクションを開始する。 if (iso == DbEnum.IsolationLevelEnum.User) { // 自動トランザクション(規定の分離レベル) dam.BeginTransaction(DbEnum.IsolationLevelEnum.ReadCommitted); } else { // 自動トランザクション(指定の分離レベル) dam.BeginTransaction(iso); } #endregion // ユーザ情報を格納する(ログ出力で利用)。 dam.Obj = ((MyParameterValue)parameterValue).User; // damを設定する。 this.SetDam(dam); } } #endregion }
/// <summary>トランザクション制御情報を取得する。</summary> /// <param name="TransactionPatternID">トランザクション パターンID</param> /// <param name="connectionString">接続文字列(out)</param> /// <param name="isolevel">分離レベル(out)</param> private void GetTCInfo(string TransactionPatternID, out string connectionString, out DbEnum.IsolationLevelEnum isolevel) { connectionString = ""; isolevel = DbEnum.IsolationLevelEnum.NotConnect; // 属性チェック用 XmlNode xmlNode = null; // TransactionPatternタグを取得する。 XmlElement xmlElement = this.XMLTCD.GetElementById(TransactionPatternID); if (xmlElement == null) { // TransactionPatternタグがない場合 // 例外を発生させる。 throw new FrameworkException( FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR[0], String.Format(FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR[1], String.Format(FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR_tp, TransactionPatternID))); } else { // TransactionPatternタグがある場合 // connkey属性 xmlNode = xmlElement.Attributes[FxLiteral.XML_TX_ATTR_CONNKEY]; if (xmlNode == null) { // connkey属性なしの場合 } else { // connkey属性ありの場合 connectionString = GetConfigParameter.GetConnectionString(xmlNode.Value); } // isolevel属性 xmlNode = xmlElement.Attributes[FxLiteral.XML_TX_ATTR_ISOLEVEL]; if (xmlNode == null) { // isolevel属性なしの場合 // 例外を発生させる。 throw new FrameworkException( FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR[0], String.Format(FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR[1], String.Format(FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR_iso1, TransactionPatternID))); } else { // isolevel属性ありの場合 // 分離level string isolevelString = xmlNode.Value; switch (isolevelString.ToUpper()) { case FxLiteral.ISO_LEVEL_NOT_CONNECT: isolevel = DbEnum.IsolationLevelEnum.NotConnect; break; case FxLiteral.ISO_LEVEL_NO_TRANSACTION: isolevel = DbEnum.IsolationLevelEnum.NoTransaction; break; case FxLiteral.ISO_LEVEL_READ_UNCOMMITTED: isolevel = DbEnum.IsolationLevelEnum.ReadUncommitted; break; case FxLiteral.ISO_LEVEL_READ_COMMIT: isolevel = DbEnum.IsolationLevelEnum.ReadCommitted; break; case FxLiteral.ISO_LEVEL_REPEATABLE_READ: isolevel = DbEnum.IsolationLevelEnum.RepeatableRead; break; case FxLiteral.ISO_LEVEL_SERIALIZABLE: isolevel = DbEnum.IsolationLevelEnum.Serializable; break; case FxLiteral.ISO_LEVEL_SNAPSHOT: isolevel = DbEnum.IsolationLevelEnum.Snapshot; break; case FxLiteral.ISO_LEVEL_DEFAULT: isolevel = DbEnum.IsolationLevelEnum.DefaultTransaction; break; default: // 定義(分離level)が間違っている。 // 例外を発生させる。 throw new FrameworkException( FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR[0], String.Format(FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR[1], String.Format(FrameworkExceptionMessage.TRANSACTION_CONTROL_XML_FORMAT_ERROR_iso2, isolevelString, TransactionPatternID))); } } } }
static void Main(string[] args) { // configの初期化 GetConfigParameter.InitConfiguration("appsettings.json"); // コマンドラインをバラす関数がある。 List <string> valsLst = null; Dictionary <string, string> argsDic = null; StringVariableOperator.GetCommandArgs('/', out argsDic, out valsLst); if (argsDic.ContainsKey("/SQL")) { SqlConnection cn = new SqlConnection(GetConfigParameter.GetConnectionString("ConnectionString_SQL")); cn.Open(); SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM SHIPPERS", cn); Console.WriteLine("SQL:" + cmd.ExecuteScalar().ToString() + "件"); } if (argsDic.ContainsKey("/ODP")) { OracleConnection cn = new OracleConnection(GetConfigParameter.GetConnectionString("ConnectionString_ODP")); cn.Open(); OracleCommand cmd = new OracleCommand("SELECT COUNT(*) FROM SHIPPERS", cn); Console.WriteLine("ODP:" + cmd.ExecuteScalar().ToString() + "件"); } if (argsDic.ContainsKey("/MCN")) { MySqlConnection cn = new MySqlConnection(GetConfigParameter.GetConnectionString("ConnectionString_MCN")); cn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM Shippers", cn); Console.WriteLine("MCN:" + cmd.ExecuteScalar().ToString() + "件"); } if (argsDic.ContainsKey("/NPS")) { NpgsqlConnection cn = new NpgsqlConnection(GetConfigParameter.GetConnectionString("ConnectionString_NPS")); cn.Open(); NpgsqlCommand cmd = new NpgsqlCommand("SELECT COUNT(*) FROM SHIPPERS", cn); Console.WriteLine("NPS:" + cmd.ExecuteScalar().ToString() + "件"); } if (argsDic.ContainsKey("/REDIS")) { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); IDatabase cache = redis.GetDatabase(); cache.StringSet("key:jp:hello", "こんにちは"); cache.StringSet("key:jp:goodbye", "さようなら"); Console.WriteLine(cache.StringGet("key:jp:hello")); Console.WriteLine(cache.StringGet("key:jp:goodbye")); } if (argsDic.ContainsKey("/MONGO")) { string connectionString = "mongodb://*****:*****@localhost:27017"; MongoClient client = new MongoClient(connectionString); IMongoDatabase db = client.GetDatabase("testdb"); IMongoCollection <Person> collection = db.GetCollection <Person>("testtbl"); // 全ドキュメントの削除 collection.DeleteMany(FilterDefinition <Person> .Empty); // ドキュメントの挿入 Person person = null; person = new Person { Name = "Dan", Age = 18, }; collection.InsertOne(person); person = new Person { Name = "Bob", Age = 22, }; collection.InsertOne(person); person = new Person { Name = "John", Age = 30, }; collection.InsertOne(person); // ドキュメントの参照 var persons = collection.Find(FilterDefinition <Person> .Empty).ToList(); foreach (Person _person in persons) { Console.WriteLine(JsonConvert.SerializeObject(_person)); } } }
/// <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 }