1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
19 using Castle
.Core
.Interceptor
;
22 /// Summary description for TransactionInterceptor.
24 public class TransactionInterceptor
: IMethodInterceptor
26 private ITransactionManager _transactionManager
;
27 private TransactionConfigHolder _transactionConfHolder
;
29 public TransactionInterceptor(ITransactionManager transactionManager
,
30 TransactionConfigHolder transactionConfHolder
)
32 _transactionManager
= transactionManager
;
33 _transactionConfHolder
= transactionConfHolder
;
36 public object Intercept(IMethodInvocation invocation
, params object[] args
)
38 if (_transactionManager
.CurrentTransaction
!= null)
40 // No support for nested transactions
42 return invocation
.Proceed(args
);
45 TransactionConfig config
=
46 _transactionConfHolder
.GetConfig(
47 invocation
.Method
.DeclaringType
);
49 if (config
!= null && config
.IsMethodTransactional( invocation
.Method
))
51 ITransaction transaction
=
52 _transactionManager
.CreateTransaction();
58 value = invocation
.Proceed(args
);
64 transaction
.Rollback();
70 _transactionManager
.Release(transaction
);
77 return invocation
.Proceed(args
);