Clover.NET coverage report - Coverage for s2container.net

Coverage timestamp: 2006年5月30日 11:21:29

File Stats: LOC: 179   Methods: 19
NCLOC: 129 Classes: 1
 
Source File Conditionals Statements Methods TOTAL
Seasar.Extension.Tx\Impl\TransactionContext.cs 50.0% 94.1% 89.5% 90.9%
coverage coverage
1   #region Copyright
2   /*
3   * Copyright 2005 the Seasar Foundation and the Others.
4   *
5   * Licensed under the Apache License, Version 2.0 (the "License");
6   * you may not use this file except in compliance with the License.
7   * You may obtain a copy of the License at
8   *
9   * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14   * either express or implied. See the License for the specific language
15   * governing permissions and limitations under the License.
16   */
17   #endregion
18  
19   using System;
20   using System.Data;
21   using System.Threading;
22   using Seasar.Extension.ADO;
23   using Seasar.Framework.Log;
24   using Seasar.Framework.Util;
25  
26   namespace Seasar.Extension.Tx.Impl
27   {
28   /// <summary>
29   /// TransactionContext の概要の説明です。
30   /// </summary>
31   public class TransactionContext : ITransactionContext, ITransactionStateHandler
32   {
33   private static Logger logger = Logger.GetLogger(typeof(TransactionContext));
34   private LocalDataStoreSlot slot;
35  
36   private IDataSource dataSource;
37   private IsolationLevel level = IsolationLevel.ReadCommitted;
38  
39   private ITransactionContext parent;
40   private IDbConnection connection;
41   private IDbTransaction transaction;
42  
43 45 public TransactionContext()
44   {
45 45 slot = Thread.AllocateDataSlot();
46   }
47  
48 17 private TransactionContext(LocalDataStoreSlot slot)
49   {
50 17 this.slot = slot;
51   }
52  
53 45 public void OpenConnection()
54   {
55 45 connection = DataSourceUtil.GetConnection(this.DataSouce);
56   }
57  
58 41 public void Begin()
59   {
60 41 OpenConnection();
61 41 this.transaction = this.Connection.BeginTransaction(this.Level);
62 41 logger.Log("DSSR0003", null);
63   }
64  
65 6 public void Commit()
66   {
67 6 this.transaction.Commit();
68 6 this.transaction.Dispose();
69 6 this.transaction = null;
70 6 logger.Log("DSSR0004", null);
71   }
72  
73 35 public void Rollback()
74   {
75 35 this.transaction.Rollback();
76 35 this.transaction.Dispose();
77 35 this.transaction = null;
78 35 logger.Log("DSSR0005", null);
79   }
80  
81 17 public ITransactionContext Create()
82   {
83 17 TransactionContext ctx = new TransactionContext(this.slot);
84 17 ctx.dataSource = this.dataSource;
85 17 return ctx;
86   }
87  
88   public ITransactionContext Current
89   {
90 274 get
91   {
92 274 return (Thread.GetData(slot) as TransactionContext);
93   }
94 82 set
95   {
96 82 Thread.SetData(slot, value);
97   }
98   }
99  
100   public ITransactionContext Parent
101   {
102 0 get
103   {
104   return this.parent;
105   }
106  
107 67 set
108   {
109 67 this.parent = value;
110   }
111   }
112  
113   public IDbConnection Connection
114   {
115 207 get
116   {
117 207 return this.connection;
118   }
119   }
120  
121   public bool IsInTransaction
122   {
123 106 get
124   {
125 106 TransactionContext cur = this.Current as TransactionContext;
126 106 return cur == null ? false : cur.transaction != null;
127   }
128   }
129   public IDataSource DataSouce
130   {
131 45 get
132   {
133 45 return this.dataSource;
134   }
135 45 set
136   {
137 45 this.dataSource = value;
138   }
139   }
140  
141   public IsolationLevel Level
142   {
143 41 get
144   {
145 41 return this.level;
146   }
147 0 set
148   {
149   this.level = value;
150   }
151   }
152  
153   public IDbTransaction Transaction
154   {
155 38 get { return this.transaction; }
156   }
157  
158   #region IDisposable メンバ
159  
160 17 public void Dispose()
161   {
162 17 this.transaction = null;
163 17 try
164   {
165 17 ConnectionUtil.Close(this.Connection);
166   }
167   finally
168   {
169 17 if(this.connection != null)
170   {
171 17 this.Connection.Dispose();
172   }
173   }
174   }
175  
176   #endregion
177   }
178   }
179