1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.raw.xact.ContainerLocking3 |
4 | |
5 | Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.store.raw.xact; |
22 | |
23 | import org.apache.derby.iapi.services.locks.LockFactory; |
24 | import org.apache.derby.iapi.services.locks.C_LockFactory; |
25 | |
26 | import org.apache.derby.iapi.store.raw.ContainerHandle; |
27 | import org.apache.derby.iapi.store.raw.ContainerLock; |
28 | import org.apache.derby.iapi.store.raw.Transaction; |
29 | |
30 | import org.apache.derby.iapi.error.StandardException; |
31 | |
32 | |
33 | /** |
34 | A locking policy that implements container level locking with |
35 | isolation degree 3. |
36 | |
37 | @see org.apache.derby.iapi.store.raw.LockingPolicy |
38 | */ |
39 | public class ContainerLocking3 extends NoLocking { |
40 | |
41 | protected final LockFactory lf; |
42 | |
43 | protected ContainerLocking3(LockFactory lf) |
44 | { |
45 | this.lf = lf; |
46 | } |
47 | |
48 | /** |
49 | Obtain a Container shared or exclusive lock until |
50 | the end of the nested transaction. |
51 | |
52 | @exception StandardException Standard Cloudscape error policy |
53 | */ |
54 | public boolean lockContainer( |
55 | Transaction t, |
56 | ContainerHandle container, |
57 | boolean waitForLock, |
58 | boolean forUpdate) |
59 | throws StandardException |
60 | { |
61 | Object qualifier = forUpdate ? ContainerLock.CX : ContainerLock.CS; |
62 | |
63 | return( |
64 | lf.lockObject( |
65 | t.getCompatibilitySpace(), t, container.getId(), qualifier, |
66 | waitForLock ? |
67 | C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT)); |
68 | } |
69 | |
70 | public int getMode() { |
71 | return MODE_CONTAINER; |
72 | } |
73 | |
74 | |
75 | /* |
76 | ** We can inherit all the others methods of NoLocking since we hold the |
77 | ** container lock until the end of transaction, and we don't obtain row |
78 | ** locks. |
79 | */ |
80 | } |