Changeset 1488
- Timestamp:
- 04/02/09 15:00:35 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataAccess.ADOHelper/DataAdapterBase.cs
r1468 r1488 144 144 protected ObjT FindSingle(Selector selector) { 145 145 ITransaction trans = 146 session.Get TransactionForCurrentThread();146 session.GetCurrentTransaction(); 147 147 bool transactionExists = trans != null; 148 148 if (!transactionExists) { … … 174 174 protected ICollection<ObjT> FindMultiple(Selector selector) { 175 175 ITransaction trans = 176 session.Get TransactionForCurrentThread();176 session.GetCurrentTransaction(); 177 177 bool transactionExists = trans != null; 178 178 if (!transactionExists) { … … 242 242 public void Update(ObjT obj) { 243 243 ITransaction trans = 244 session.Get TransactionForCurrentThread();244 session.GetCurrentTransaction(); 245 245 bool transactionExists = trans != null; 246 246 if (!transactionExists) { … … 294 294 public bool Delete(ObjT obj) { 295 295 ITransaction trans = 296 session.Get TransactionForCurrentThread();296 session.GetCurrentTransaction(); 297 297 bool transactionExists = trans != null; 298 298 if (!transactionExists) { -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/DataAdapterWrapperBase.cs
r1468 r1488 43 43 get { 44 44 ITransaction trans = 45 session.Get TransactionForCurrentThread();45 session.GetCurrentTransaction(); 46 46 if (trans != null) 47 47 SetTransaction(trans.InnerTransaction as DbTransaction); -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/HeuristicLab.DataAccess.ADOHelper.csproj
r1486 r1488 88 88 <Compile Include="SessionFactory.cs" /> 89 89 <Compile Include="Transaction.cs" /> 90 <Compile Include="TransactionManager.cs" />91 90 </ItemGroup> 92 91 <ItemGroup> -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/Session.cs
r1468 r1488 35 35 private SessionFactory factory; 36 36 37 private ITransactionManager transManager;37 private Transaction transaction; 38 38 39 39 private DbConnection connection; … … 42 42 new Dictionary<Guid, object>(); 43 43 44 public Session(SessionFactory factory, 45 ITransactionManager transManager) { 44 public Session(SessionFactory factory) { 46 45 this.factory = factory; 47 this.transManager = transManager;48 46 } 49 47 … … 58 56 } 59 57 58 public void DetachTrasaction() { 59 this.transaction = null; 60 } 61 60 62 #region ISession Members 61 63 public ITransaction BeginTransaction() { 62 ITransaction trans = transManager.BeginTransaction(); 63 if(trans is Transaction) 64 ((Transaction)trans).Connection = Connection; 64 if (transaction == null) { 65 transaction = new Transaction(this); 66 transaction.Connection = Connection; 67 } 65 68 66 return trans ;69 return transaction; 67 70 } 68 71 69 public ITransaction GetTransactionForCurrentThread() { 70 ITransaction trans = transManager.GetTransactionForCurrentThread(); 71 if (trans != null && trans is Transaction) 72 ((Transaction)trans).Connection = Connection; 73 74 return trans; 72 public ITransaction GetCurrentTransaction() { 73 return transaction; 75 74 } 76 75 77 76 public IDataAdapter<ObjT> GetDataAdapter<ObjT>() 78 77 where ObjT : IPersistableObject { 79 lock(this) { 80 Guid adapterId = typeof(IDataAdapter<ObjT>).GUID; 78 Guid adapterId = typeof(IDataAdapter<ObjT>).GUID; 81 79 82 83 84 80 if (!adapters.ContainsKey(adapterId)) { 81 IDataAdapter<ObjT> adapter = 82 discoveryService.GetInstances<IDataAdapter<ObjT>>()[0]; 85 83 86 84 adapter.Session = this; 87 85 88 89 86 adapters.Add(adapterId, adapter); 87 } 90 88 91 return adapters[adapterId] as IDataAdapter<ObjT>; 92 } 89 return adapters[adapterId] as IDataAdapter<ObjT>; 93 90 } 94 91 … … 97 94 where T : class, IDataAdapter<ObjT> 98 95 { 99 lock (this) {100 96 Guid adapterId = typeof(T).GUID; 101 97 … … 110 106 111 107 return adapters[adapterId] as T; 112 }113 108 } 114 109 115 110 public void EndSession() { 116 if(connection.State == System.Data.ConnectionState.Open) 111 if (transaction != null) { 112 transaction.Rollback(); 113 transaction = null; 114 } 115 if (connection.State == System.Data.ConnectionState.Open) { 117 116 connection.Close(); 117 connection = null; 118 } 118 119 factory.EndSession(this); 119 120 } -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/SessionFactory.cs
r1468 r1488 33 33 private IDictionary<Thread, ISession> sessions = 34 34 new Dictionary<Thread, ISession>(); 35 36 private ITransactionManager transManager =37 new TransactionManager();38 35 39 36 public Type DbConnectionType { get; set; } … … 86 83 if (!sessions.ContainsKey(current)) { 87 84 sessions[current] = 88 new Session(this , transManager);85 new Session(this); 89 86 } 90 87 -
trunk/sources/HeuristicLab.DataAccess.ADOHelper/Transaction.cs
r1468 r1488 31 31 class Transaction: ITransaction { 32 32 private DbTransaction transaction; 33 private TransactionManager manager; 33 34 private Session session; 35 36 public Transaction(Session session) { 37 this.session = session; 38 } 34 39 35 40 #region ITransaction Members 36 37 public Transaction(TransactionManager manager) {38 this.manager = manager;39 }40 41 41 public DbConnection Connection { 42 42 set { … … 54 54 55 55 public void Commit() { 56 manager.RemoveTransaction(this);57 56 if (transaction != null) { 58 57 DbConnection conn = … … 60 59 61 60 transaction.Commit(); 61 62 transaction = null; 63 session.DetachTrasaction(); 62 64 63 65 if (conn != null && … … 68 70 69 71 public void Rollback() { 70 manager.RemoveTransaction(this);71 DbConnection conn =72 transaction.Connection;72 if (transaction != null) { 73 DbConnection conn = 74 transaction.Connection; 73 75 74 transaction.Rollback();76 transaction.Rollback(); 75 77 76 if (conn != null && 77 conn.State == System.Data.ConnectionState.Open) 78 conn.Close(); 78 transaction = null; 79 session.DetachTrasaction(); 80 81 if (conn != null && 82 conn.State == System.Data.ConnectionState.Open) 83 conn.Close(); 84 } 79 85 } 80 86 -
trunk/sources/HeuristicLab.DataAccess/Interfaces/ISession.cs
r1468 r1488 29 29 ITransaction BeginTransaction(); 30 30 31 ITransaction Get TransactionForCurrentThread();31 ITransaction GetCurrentTransaction(); 32 32 33 33 IDataAdapter<ObjT> GetDataAdapter<ObjT>() -
trunk/sources/HeuristicLab.Security.DataAccess/Properties/AssemblyInfo.frame
r1378 r1488 28 28 // set of attributes. Change these attribute values to modify the information 29 29 // associated with an assembly. 30 [assembly: AssemblyTitle("HeuristicLab.Security.DataAccess )]30 [assembly: AssemblyTitle("HeuristicLab.Security.DataAccess")] 31 31 [assembly: AssemblyDescription("")] 32 32 [assembly: AssemblyConfiguration("")]
Note: See TracChangeset
for help on using the changeset viewer.