1 // Copyright 2004-2007 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.
15 namespace Castle
.Services
.Transaction
20 /// The supported transaction mode for the components.
22 public enum TransactionMode
29 /// transaction context will be created
30 /// managing internally a connection, no
31 /// transaction is opened though
35 /// transaction context will be created if not present
39 /// a new transaction context will be created
43 /// an existing appropriate transaction context
44 /// will be joined if present
50 /// The supported isolation modes.
52 public enum IsolationMode
63 /// Indicates that the target class wants to use
64 /// the transactional services.
66 [AttributeUsage(AttributeTargets
.Class
, AllowMultiple
=false)]
67 public class TransactionalAttribute
: System
.Attribute
72 /// Indicates the transaction support for a method.
74 [AttributeUsage(AttributeTargets
.Method
, AllowMultiple
=false)]
75 public class TransactionAttribute
: System
.Attribute
77 private TransactionMode _transactionMode
;
78 private IsolationMode _isolationMode
;
79 private bool distributedTransaction
;
82 /// Declares unspecified values for transaction and isolation, which
83 /// means that the transaction manager will use the default values
86 public TransactionAttribute() : this(TransactionMode
.Unspecified
, IsolationMode
.Unspecified
)
91 /// Declares the transaction mode, but omits the isolation,
92 /// which means that the transaction manager should use the
93 /// default value for it.
95 /// <param name="transactionMode"></param>
96 public TransactionAttribute(TransactionMode transactionMode
) : this(transactionMode
, IsolationMode
.Unspecified
)
101 /// Declares both the transaction mode and isolation
102 /// desired for this method. The transaction manager should
103 /// obey the declaration.
105 /// <param name="transactionMode"></param>
106 /// <param name="isolationMode"></param>
107 public TransactionAttribute(TransactionMode transactionMode
, IsolationMode isolationMode
)
109 _transactionMode
= transactionMode
;
110 _isolationMode
= isolationMode
;
114 /// Returns the <see cref="TransactionMode"/>
116 public TransactionMode TransactionMode
118 get { return _transactionMode; }
122 /// Returns the <see cref="IsolationMode"/>
124 public IsolationMode IsolationMode
126 get { return _isolationMode; }
130 /// Gets or sets a value indicating whether the transaction should be distributed.
133 /// <c>true</c> if a distributed transaction should be created; otherwise, <c>false</c>.
135 public bool Distributed
137 get { return distributedTransaction; }
138 set { distributedTransaction = value; }