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
|
|
|
21
|
|
using Seasar.Framework.Aop;
|
22
|
|
|
23
|
|
namespace Seasar.Extension.Tx.Impl
|
24
|
|
{
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
|
public class LocalRequiredTxHandler : AbstractLocalTxHandler
|
29
|
|
{
|
30
|
6
|
public override object Handle(IMethodInvocation invocation, bool alreadyInTransaction)
|
31
|
|
{
|
32
|
6
|
if(! alreadyInTransaction)
|
33
|
|
{
|
34
|
2
|
return HandleTransaction(invocation);
|
35
|
|
}
|
36
|
|
else
|
37
|
|
{
|
38
|
4
|
return invocation.Proceed();
|
39
|
|
}
|
40
|
|
}
|
41
|
|
|
42
|
2
|
private object HandleTransaction(IMethodInvocation invocation)
|
43
|
|
{
|
44
|
2
|
using(ITransactionContext current = this.Context.Create())
|
45
|
|
{
|
46
|
2
|
ITransactionContext parent = this.Context.Current;
|
47
|
2
|
current.Parent = parent;
|
48
|
2
|
current.Begin();
|
49
|
2
|
this.Context.Current = current;
|
50
|
2
|
try
|
51
|
|
{
|
52
|
2
|
object obj = invocation.Proceed();
|
53
|
1
|
current.Commit();
|
54
|
1
|
return obj;
|
55
|
|
}
|
56
|
|
catch
|
57
|
|
{
|
58
|
1
|
current.Rollback();
|
59
|
1
|
throw;
|
60
|
|
}
|
61
|
|
finally
|
62
|
|
{
|
63
|
2
|
this.Context.Current = parent;
|
64
|
2
|
if(parent != null) this.Context.Current.Parent = null;
|
65
|
|
}
|
66
|
|
}
|
67
|
|
}
|
68
|
|
|
69
|
|
}
|
70
|
|
}
|
71
|
|
|