Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Facilities / ActiveRecordIntegration / Castle.Facilities.ActiveRecordIntegration / TransactionScopeResourceAdapter.cs
blobd17851921e6a9db2c50b1ad020783d2f00b15565
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
15 namespace Castle.Facilities.ActiveRecordIntegration
17 using Castle.ActiveRecord;
18 using Castle.Services.Transaction;
19 using TransactionMode = Castle.Services.Transaction.TransactionMode;
21 /// <summary>
22 ///
23 /// </summary>
24 public class TransactionScopeResourceAdapter : IResource
26 private readonly TransactionMode transactionMode;
27 private TransactionScope scope;
29 /// <summary>
30 /// Initializes a new instance of the <see cref="TransactionScopeResourceAdapter"/> class.
31 /// </summary>
32 /// <param name="transactionMode">The transaction mode.</param>
33 public TransactionScopeResourceAdapter(TransactionMode transactionMode)
35 this.transactionMode = transactionMode;
38 /// <summary>
39 /// Implementors should start the
40 /// transaction on the underlying resource
41 /// </summary>
42 public void Start()
44 Castle.ActiveRecord.TransactionMode mode = (transactionMode == TransactionMode.Requires)
45 ? Castle.ActiveRecord.TransactionMode.Inherits
46 : Castle.ActiveRecord.TransactionMode.New;
48 scope = new TransactionScope(mode);
51 /// <summary>
52 /// Implementors should commit the
53 /// transaction on the underlying resource
54 /// </summary>
55 public void Commit()
57 scope.VoteCommit();
59 Dispose();
62 /// <summary>
63 /// Implementors should rollback the
64 /// transaction on the underlying resource
65 /// </summary>
66 public void Rollback()
68 scope.VoteRollBack();
70 Dispose();
73 /// <summary>
74 /// Releases unmanaged and - optionally - managed resources
75 /// </summary>
76 protected void Dispose()
78 scope.Dispose();