• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revisiona3ce170d1e898fecf17babb0d2be480b6753bebe (tree)
Zeit2022-11-16 00:36:14
Autoryoshy <yoshy.org.bitbucket@gz.j...>
Commiteryoshy

Log Message

[MOD] DBコネクションラッパーを抽象化し、単純実装したクラスとそのファクトリを追加(各RDMBS固有の機能が必要な場合はアプリ側で実装する)

Ändern Zusammenfassung

Diff

--- a/CleanAuLait48.Db.csproj
+++ b/CleanAuLait48.Db.csproj
@@ -49,7 +49,8 @@
4949 <Compile Include="OuterEdge\Repository\Db\Tx\AbstractConnectionFactory.cs" />
5050 <Compile Include="OuterEdge\Repository\Db\Tx\ConnectoinFactoryMap.cs" />
5151 <Compile Include="OuterEdge\Repository\Db\Tx\DataSource.cs" />
52- <Compile Include="OuterEdge\Repository\Db\Tx\DbConnectionWrapper.cs" />
52+ <Compile Include="OuterEdge\Repository\Db\Tx\AbstractDbConnectionWrapper.cs" />
53+ <Compile Include="OuterEdge\Repository\Db\Tx\DbConnectionHelper.cs" />
5354 <Compile Include="OuterEdge\Repository\Db\Tx\DbTransactionWrapper.cs" />
5455 <Compile Include="OuterEdge\Repository\Db\Tx\IConnectionFactory.cs" />
5556 <Compile Include="OuterEdge\Repository\Db\Tx\IConnectionFactoryMap.cs" />
@@ -58,6 +59,7 @@
5859 <Compile Include="OuterEdge\Repository\Db\Tx\IDbTransactionWrapper.cs" />
5960 <Compile Include="OuterEdge\Repository\Db\Tx\ITransactionManager.cs" />
6061 <Compile Include="OuterEdge\Repository\Db\Tx\SimpleConnectionFactory.cs" />
62+ <Compile Include="OuterEdge\Repository\Db\Tx\SimpleDbConnectionWrapper.cs" />
6163 <Compile Include="OuterEdge\Repository\Db\Tx\TransactionManager.cs" />
6264 <Compile Include="Properties\AssemblyInfo.cs" />
6365 </ItemGroup>
--- a/OuterEdge/Repository/Db/Tx/DbConnectionWrapper.cs
+++ b/OuterEdge/Repository/Db/Tx/AbstractDbConnectionWrapper.cs
@@ -5,12 +5,12 @@ using System.Text;
55
66 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
77 {
8- public class DbConnectionWrapper : IDbConnectionWrapper
8+ public abstract class AbstractDbConnectionWrapper : IDbConnectionWrapper
99 {
1010 private const string MANAGED_ERROR = "The transaction is managed by the transaction manager. So, we can't ";
1111
12- private readonly IDbConnection conn;
13- private readonly string name;
12+ protected readonly IDbConnection conn;
13+ protected readonly string name;
1414
1515 public string Database => this.conn.Database;
1616
@@ -22,7 +22,7 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
2222
2323 public IDbConnection GetRawConnection() => this.conn;
2424
25- public DbConnectionWrapper(IDbConnection conn, string name)
25+ public AbstractDbConnectionWrapper(IDbConnection conn, string name)
2626 {
2727 this.conn = conn;
2828 this.name = name;
@@ -81,21 +81,17 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
8181 return buf.ToString();
8282 }
8383
84- public static IDbConnection GetRawConnection(IDbConnection conn)
84+ public abstract void TestConnection();
85+
86+ protected void ExecuteTestQuery(string query)
8587 {
86- if (conn is IDbConnectionWrapper connWrapper)
88+ using (IDbCommand cmd = this.GetRawConnection().CreateCommand())
8789 {
88- conn = connWrapper.GetRawConnection();
90+ cmd.CommandText = query;
91+ _ = cmd.ExecuteNonQuery();
8992 }
90-
91- return conn;
9293 }
93-#if false
94- public static IDatabase CreateDatabaseFromRawConnection(IDbConnection conn)
95- {
96- return new Database((DbConnection)GetRawConnection(conn));
97- }
98-#endif
94+
9995 }
10096 }
10197
\ No newline at end of file
--- /dev/null
+++ b/OuterEdge/Repository/Db/Tx/DbConnectionHelper.cs
@@ -0,0 +1,24 @@
1+using System.Data;
2+
3+namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
4+{
5+ public static class DbConnectionHelper
6+ {
7+ public static IDbConnection GetRawConnection(IDbConnection conn)
8+ {
9+ if (conn is IDbConnectionWrapper connWrapper)
10+ {
11+ conn = connWrapper.GetRawConnection();
12+ }
13+
14+ return conn;
15+ }
16+
17+#if false
18+ public static IDatabase CreateDatabaseFromRawConnection(IDbConnection conn)
19+ {
20+ return new Database((DbConnection)GetRawConnection(conn));
21+ }
22+#endif
23+ }
24+}
--- a/OuterEdge/Repository/Db/Tx/IDbConnectionWrapper.cs
+++ b/OuterEdge/Repository/Db/Tx/IDbConnectionWrapper.cs
@@ -5,5 +5,7 @@ namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
55 public interface IDbConnectionWrapper : IDbConnection
66 {
77 IDbConnection GetRawConnection();
8+
9+ void TestConnection();
810 }
911 }
\ No newline at end of file
--- a/OuterEdge/Repository/Db/Tx/SimpleConnectionFactory.cs
+++ b/OuterEdge/Repository/Db/Tx/SimpleConnectionFactory.cs
@@ -1,11 +1,23 @@
1-using System.Data.Common;
1+using System.Data;
2+using System.Data.Common;
23
34 namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
45 {
56 public class SimpleConnectionFactory : AbstractConnectionFactory
67 {
7- public SimpleConnectionFactory(DbProviderFactory factory, string connStr) : base(factory, connStr)
8+ public SimpleConnectionFactory(DbProviderFactory factory, string connStr) :
9+ base(factory, connStr)
810 {
911 }
12+
13+ public SimpleConnectionFactory(DbProviderFactory factory, string connStr, string name) :
14+ base(factory, connStr, name)
15+ {
16+ }
17+
18+ public override IDbConnectionWrapper CreateWrapper(IDbConnection conn, string name)
19+ {
20+ return new SimpleDbConnectionWrapper(conn, this.name);
21+ }
1022 }
1123 }
--- /dev/null
+++ b/OuterEdge/Repository/Db/Tx/SimpleDbConnectionWrapper.cs
@@ -0,0 +1,17 @@
1+using System;
2+using System.Data;
3+
4+namespace CleanAuLait48.OuterEdge.Repository.Db.Tx
5+{
6+ internal class SimpleDbConnectionWrapper : AbstractDbConnectionWrapper
7+ {
8+ public SimpleDbConnectionWrapper(IDbConnection conn, string name) : base(conn, name)
9+ {
10+ }
11+
12+ public override void TestConnection()
13+ {
14+ throw new NotSupportedException();
15+ }
16+ }
17+}