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.
15 namespace Castle
.ActiveRecord
.Framework
.Scopes
17 internal class ScopeUtil
19 internal static ISessionScope
FindPreviousScope(ISessionScope thisScope
,
20 bool preferenceForTransactional
)
22 return FindPreviousScope(thisScope
, preferenceForTransactional
, false);
25 internal static ISessionScope
FindPreviousScope(ISessionScope thisScope
,
26 bool preferenceForTransactional
, bool doNotReturnSessionScope
)
28 object[] items
= ThreadScopeAccessor
.Instance
.CurrentStack
.ToArray();
30 ISessionScope first
= null;
32 for (int i
= 0; i
< items
.Length
; i
++)
34 ISessionScope scope
= items
[i
] as ISessionScope
;
36 if (scope
== thisScope
) continue;
38 if (first
== null) first
= scope
;
40 if (!preferenceForTransactional
) break;
42 if (scope
.ScopeType
== SessionScopeType
.Transactional
)
48 return doNotReturnSessionScope
? null : first
;