1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Transactions;
|
21
|
|
|
22
|
|
namespace Seasar.Tests.Extension.Tx.Impl
|
23
|
|
{
|
24
|
|
public interface ITxTest
|
25
|
|
{
|
26
|
|
bool IsInTransaction();
|
27
|
|
string TxId
|
28
|
|
{
|
29
|
|
get;
|
30
|
|
}
|
31
|
|
void throwException();
|
32
|
|
}
|
33
|
|
|
34
|
|
|
35
|
|
[global::System.Serializable]
|
36
|
|
public class TxException : Exception
|
37
|
|
{
|
38
|
|
private bool wasInTx;
|
39
|
|
|
40
|
|
public bool WasInTx
|
41
|
|
{
|
42
|
4
|
get { return wasInTx; }
|
43
|
4
|
set { wasInTx = value; }
|
44
|
|
}
|
45
|
|
|
46
|
|
private string txId;
|
47
|
|
public string TxId
|
48
|
|
{
|
49
|
2
|
get { return txId; }
|
50
|
4
|
set { txId = value; }
|
51
|
|
}
|
52
|
|
|
53
|
4
|
public TxException() { }
|
54
|
0
|
public TxException(string message) : base(message) { }
|
55
|
0
|
public TxException(string message, Exception inner) : base(message, inner) { }
|
56
|
0
|
protected TxException(
|
57
|
|
System.Runtime.Serialization.SerializationInfo info,
|
58
|
|
System.Runtime.Serialization.StreamingContext context)
|
59
|
|
: base(info, context) { }
|
60
|
|
}
|
61
|
|
|
62
|
|
public class TxTest : ITxTest
|
63
|
|
{
|
64
|
|
|
65
|
|
#region ITxTest メンバ
|
66
|
|
|
67
|
7
|
public bool IsInTransaction()
|
68
|
|
{
|
69
|
7
|
Transaction tx = Transaction.Current;
|
70
|
7
|
if (tx != null)
|
71
|
|
{
|
72
|
6
|
return tx.TransactionInformation.Status == TransactionStatus.Active;
|
73
|
|
}
|
74
|
1
|
return false;
|
75
|
|
}
|
76
|
|
|
77
|
|
public string TxId
|
78
|
|
{
|
79
|
7
|
get {
|
80
|
7
|
Transaction tx = Transaction.Current;
|
81
|
7
|
if (tx != null)
|
82
|
|
{
|
83
|
6
|
return tx.TransactionInformation.LocalIdentifier;
|
84
|
|
}
|
85
|
1
|
return null;
|
86
|
|
}
|
87
|
|
}
|
88
|
|
|
89
|
4
|
public void throwException()
|
90
|
|
{
|
91
|
4
|
TxException ex = new TxException();
|
92
|
4
|
ex.WasInTx = this.IsInTransaction();
|
93
|
4
|
ex.TxId = this.TxId;
|
94
|
4
|
throw ex;
|
95
|
|
}
|
96
|
|
|
97
|
|
#endregion
|
98
|
|
}
|
99
|
|
}
|
100
|
|
|