KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > xact > ContainerLocking3


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.xact.ContainerLocking3
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.store.raw.xact;
23
24 import org.apache.derby.iapi.services.locks.LockFactory;
25 import org.apache.derby.iapi.services.locks.C_LockFactory;
26
27 import org.apache.derby.iapi.store.raw.ContainerHandle;
28 import org.apache.derby.iapi.store.raw.ContainerLock;
29 import org.apache.derby.iapi.store.raw.Transaction;
30
31 import org.apache.derby.iapi.error.StandardException;
32
33
34 /**
35     A locking policy that implements container level locking with
36     isolation degree 3.
37
38     @see org.apache.derby.iapi.store.raw.LockingPolicy
39 */

40 public class ContainerLocking3 extends NoLocking {
41
42     protected final LockFactory lf;
43
44     protected ContainerLocking3(LockFactory lf)
45     {
46         this.lf = lf;
47     }
48
49     /**
50         Obtain a Container shared or exclusive lock until
51         the end of the nested transaction.
52
53         @exception StandardException Standard Cloudscape error policy
54     */

55     public boolean lockContainer(
56     Transaction t,
57     ContainerHandle container,
58     boolean waitForLock,
59     boolean forUpdate)
60         throws StandardException
61     {
62         Object JavaDoc qualifier = forUpdate ? ContainerLock.CX : ContainerLock.CS;
63
64         return(
65             lf.lockObject(
66                 t.getCompatibilitySpace(), t, container.getId(), qualifier,
67                 waitForLock ?
68                     C_LockFactory.TIMED_WAIT : C_LockFactory.NO_WAIT));
69     }
70
71     public int getMode() {
72         return MODE_CONTAINER;
73     }
74
75
76     /*
77     ** We can inherit all the others methods of NoLocking since we hold the
78     ** container lock until the end of transaction, and we don't obtain row
79     ** locks.
80     */

81 }
82
Popular Tags