- Timestamp:
- 04/03/09 11:54:10 (15 years ago)
- File:
-
- 1 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();
Note: See TracChangeset
for help on using the changeset viewer.