Changeset 1496
- Timestamp:
- 04/03/09 11:54:10 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.DataAccess.ADOHelper
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAccess.ADOHelper/Session.cs
r1488 r1496 27 27 using HeuristicLab.PluginInfrastructure; 28 28 using System.Data.Common; 29 using System.Threading; 29 30 30 31 namespace HeuristicLab.DataAccess.ADOHelper { … … 39 40 private DbConnection connection; 40 41 42 private Thread ownerThread; 43 41 44 private IDictionary<Guid, object> adapters = 42 45 new Dictionary<Guid, object>(); … … 44 47 public Session(SessionFactory factory) { 45 48 this.factory = factory; 49 this.ownerThread = Thread.CurrentThread; 50 } 51 52 public void CheckThread() { 53 if (!Thread.CurrentThread.Equals(ownerThread)) { 54 throw new Exception("Session is owned by another thread"); 55 } 46 56 } 47 57 … … 62 72 #region ISession Members 63 73 public ITransaction BeginTransaction() { 74 CheckThread(); 75 64 76 if (transaction == null) { 65 77 transaction = new Transaction(this); … … 71 83 72 84 public ITransaction GetCurrentTransaction() { 85 CheckThread(); 86 73 87 return transaction; 74 88 } … … 76 90 public IDataAdapter<ObjT> GetDataAdapter<ObjT>() 77 91 where ObjT : IPersistableObject { 92 CheckThread(); 93 78 94 Guid adapterId = typeof(IDataAdapter<ObjT>).GUID; 79 95 … … 94 110 where T : class, IDataAdapter<ObjT> 95 111 { 96 Guid adapterId = typeof(T).GUID;112 CheckThread(); 97 113 98 if (!adapters.ContainsKey(adapterId)) { 99 T adapter = 100 discoveryService.GetInstances<T>()[0]; 114 Guid adapterId = typeof(T).GUID; 101 115 102 adapter.Session = this; 116 if (!adapters.ContainsKey(adapterId)) { 117 T adapter = 118 discoveryService.GetInstances<T>()[0]; 103 119 104 adapters.Add(adapterId, adapter); 105 } 120 adapter.Session = this; 106 121 107 return adapters[adapterId] as T; 122 adapters.Add(adapterId, adapter); 123 } 124 125 return adapters[adapterId] as T; 108 126 } 109 127 110 128 public void EndSession() { 129 CheckThread(); 130 111 131 if (transaction != null) { 112 132 transaction.Rollback(); -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/Transaction.cs
r1488 r1496 38 38 } 39 39 40 #region ITransaction Members41 40 public DbConnection Connection { 42 41 set { 43 42 if (value != null && 44 43 (transaction == null || 45 !(transaction.Connection != null && 44 !(transaction.Connection != null && 46 45 transaction.Connection.Equals(value)))) { 47 48 46 if (value.State != System.Data.ConnectionState.Open) 47 value.Open(); 49 48 50 49 transaction = value.BeginTransaction(IsolationLevel.RepeatableRead); 51 50 } 52 51 } 53 52 } 54 53 54 #region ITransaction Members 55 55 public void Commit() { 56 this.session.CheckThread(); 57 56 58 if (transaction != null) { 57 59 DbConnection conn = … … 70 72 71 73 public void Rollback() { 74 this.session.CheckThread(); 75 72 76 if (transaction != null) { 73 77 DbConnection conn = … … 87 91 public object InnerTransaction { 88 92 get { 93 this.session.CheckThread(); 94 89 95 return transaction; 90 96 }
Note: See TracChangeset
for help on using the changeset viewer.