• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂a9ac1a666fffd549e3ab015bdeebb01070e4d03e (tree)
時間2022-11-16 00:35:49
作者yoshy <yoshy.org.bitbucket@gz.j...>
Commiteryoshy

Log Message

[MOD] コネクションファクトリ、コネクションファクトリマップ、データソース、トランザクションマネージャをコネクションラッパーに対応

Change Summary

差異

--- a/OuterEdge/Repository/Db/Tx/AbstractConnectionFactory.cs
+++ b/OuterEdge/Repository/Db/Tx/AbstractConnectionFactory.cs
@@ -11,32 +11,48 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
1111 {
1212 private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
1313
14+ protected readonly string name;
15+
1416 private readonly DbProviderFactory factory;
1517 private readonly string connStr;
18+
1619 private readonly ISet<IDbConnection> connSet;
20+
1721 private bool disposedValue;
1822
1923 public AbstractConnectionFactory(DbProviderFactory factory, string connStr)
24+ : this(factory, connStr, "default")
25+ {
26+ }
27+
28+ public AbstractConnectionFactory(DbProviderFactory factory, string connStr, string name)
2029 {
2130 this.factory = factory;
31+
2232 this.connStr = connStr;
33+ this.name = name;
34+
2335 this.connSet = new HashSet<IDbConnection>();
2436 }
2537
26- public virtual IDbConnection GetConnection()
38+ public virtual IDbConnectionWrapper GetConnection()
2739 {
28- IDbConnection conn = CreateConnection();
40+ IDbConnection conn = CreateRawConnection();
2941
30- _ = connSet.Add(conn);
31-
32- return conn;
42+ return CreateWrapper(conn, this.name);
3343 }
3444
35- protected IDbConnection CreateConnection()
45+ public abstract IDbConnectionWrapper CreateWrapper(IDbConnection conn, string name);
46+
47+ protected IDbConnection CreateRawConnection()
3648 {
3749 IDbConnection conn = factory.CreateConnection();
50+
3851 conn.ConnectionString = connStr;
3952 conn.Open();
53+
54+ _ = connSet.Add(conn);
55+
4056 return conn;
4157 }
4258
--- a/OuterEdge/Repository/Db/Tx/ConnectoinFactoryMap.cs
+++ b/OuterEdge/Repository/Db/Tx/ConnectoinFactoryMap.cs
@@ -1,6 +1,5 @@
11 using System;
22 using System.Collections.Generic;
3-using System.Data;
43
54 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
65 {
@@ -30,12 +29,12 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
3029 factoryMap.Add(key, factory);
3130 }
3231
33- public IDbConnection GetConnection()
32+ public IDbConnectionWrapper GetConnection()
3433 {
3534 return GetConnection("");
3635 }
3736
38- public IDbConnection GetConnection(string name)
37+ public IDbConnectionWrapper GetConnection(string name)
3938 {
4039 if (name == null)
4140 {
--- a/OuterEdge/Repository/Db/Tx/DataSource.cs
+++ b/OuterEdge/Repository/Db/Tx/DataSource.cs
@@ -1,5 +1,4 @@
11 using System;
2-using System.Data;
32
43 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
54 {
@@ -14,12 +13,12 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
1413 this.factoryMap = factoryMap;
1514 }
1615
17- public IDbConnection GetConnection()
16+ public IDbConnectionWrapper GetConnection()
1817 {
1918 return factoryMap.GetConnection();
2019 }
2120
22- public IDbConnection GetConnection(string name)
21+ public IDbConnectionWrapper GetConnection(string name)
2322 {
2423 return factoryMap.GetConnection(name);
2524 }
--- a/OuterEdge/Repository/Db/Tx/IConnectionFactory.cs
+++ b/OuterEdge/Repository/Db/Tx/IConnectionFactory.cs
@@ -1,10 +1,9 @@
11 using System;
2-using System.Data;
32
43 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
54 {
65 public interface IConnectionFactory : IDisposable
76 {
8- IDbConnection GetConnection();
7+ IDbConnectionWrapper GetConnection();
98 }
109 }
--- a/OuterEdge/Repository/Db/Tx/IConnectionFactoryMap.cs
+++ b/OuterEdge/Repository/Db/Tx/IConnectionFactoryMap.cs
@@ -1,12 +1,11 @@
11 using System;
2-using System.Data;
32
43 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
54 {
65 public interface IConnectionFactoryMap : IDisposable
76 {
8- IDbConnection GetConnection();
9- IDbConnection GetConnection(string name);
7+ IDbConnectionWrapper GetConnection();
8+ IDbConnectionWrapper GetConnection(string name);
109
1110 void Clear();
1211
--- a/OuterEdge/Repository/Db/Tx/IDataSource.cs
+++ b/OuterEdge/Repository/Db/Tx/IDataSource.cs
@@ -1,11 +1,10 @@
11 using System;
2-using System.Data;
32
43 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
54 {
65 public interface IDataSource : IDisposable
76 {
8- IDbConnection GetConnection();
9- IDbConnection GetConnection(string name);
7+ IDbConnectionWrapper GetConnection();
8+ IDbConnectionWrapper GetConnection(string name);
109 }
1110 }
\ No newline at end of file
--- a/OuterEdge/Repository/Db/Tx/TransactionManager.cs
+++ b/OuterEdge/Repository/Db/Tx/TransactionManager.cs
@@ -1,15 +1,11 @@
11 using CleanAuLait48.Core.Log;
22 using NLog;
3+using System;
34 using System.Collections.Generic;
45 using System.Data;
56
67 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
78 {
8- /*
9- * TOOD: FactoryMapにアプリケーション設定を反映させるタイミングの検討
10- * TODO: Dialectの注入方法の検討(現状は型引数だが... DIから生成しなければ現状のままで良い?)
11- */
12-
139 public class TransactionManager : ITransactionManager
1410 {
1511 private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
@@ -35,7 +31,7 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
3531 IDbConnectionWrapper conn = GetConnection(name);
3632 IDbTransaction tx = conn.GetRawConnection().BeginTransaction();
3733
38- IDbTransactionWrapper txWrapper = new DbTransactionWrapper(this, conn,tx, name);
34+ IDbTransactionWrapper txWrapper = new DbTransactionWrapper(this, conn, tx, name);
3935
4036 txMap.Add(name, txWrapper);
4137
@@ -83,6 +79,16 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
8379 {
8480 if (connMap.TryGetValue(name, out IDbConnectionWrapper conn))
8581 {
82+ try
83+ {
84+ conn.TestConnection();
85+ }
86+ catch (Exception e)
87+ {
88+ logger.Warn(e);
89+ logger.Warn("既存DB接続 [{0}] {1} は疎通テストに失敗しました。", name, ToConnectionID(conn));
90+ }
91+
8692 logger.Trace("既存DB接続 [{0}] {1} の状態は [{2}] です.", name, ToConnectionID(conn), conn.State);
8793
8894 if (conn.State == ConnectionState.Open)
@@ -97,15 +103,13 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
97103 connMap.Remove(name);
98104 }
99105
100- IDbConnection rawConn = dataSource.GetConnection(name);
101-
102- conn = new DbConnectionWrapper(rawConn, name);
106+ IDbConnectionWrapper wrapper = dataSource.GetConnection(name);
103107
104- connMap.Add(name, conn);
108+ connMap.Add(name, wrapper);
105109
106- logger.Trace("新規DB接続 [{0}] {1} を取得しました.", name, ToConnectionID(conn));
110+ logger.Trace("新規DB接続 [{0}] {1} を取得しました.", name, ToConnectionID(wrapper));
107111
108- return conn;
112+ return wrapper;
109113 }
110114
111115 public void ClearConnectionCacheMap()