KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > store > raw > ContainerLock


1 /*
2
3    Derby - Class org.apache.derby.iapi.store.raw.ContainerLock
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.iapi.store.raw;
23
24 /**
25     A ContainerLock represents a qualifier that is to be used when
26     locking a container through a ContainerHandle.
27
28     <BR>
29     MT - Immutable
30
31     @see ContainerHandle
32     @see LockingPolicy
33 */

34
35 public final class ContainerLock {
36
37     private final int type;
38
39     private ContainerLock(int type) {
40         this.type = type;
41     }
42
43     // Names of locks for virtual lock table print out
44
private static String JavaDoc[] shortnames = {"IS", "IX", "S", "U", "X" };
45
46     /** Container Intent Shared lock */
47     public static final ContainerLock CIS = new ContainerLock(0);
48     /** Container Intent Exclusive lock */
49     public static final ContainerLock CIX = new ContainerLock(1);
50     /** Container Shared lock */
51     public static final ContainerLock CS = new ContainerLock(2);
52     /** Container Update lock */
53     public static final ContainerLock CU = new ContainerLock(3);
54     /** Container Exclusive lock */
55     public static final ContainerLock CX = new ContainerLock(4);
56
57     /** number of types of container locks */
58     public static final int C_NUMBER = 5;
59
60     /** Container lock compatability table */
61     private static final boolean[][] C_COMPAT = {
62
63     // Granted
64
// Request \ CIS CIX CS CU CX
65
//
66
/* CIS */ { true, true, true, false, false },
67     /* CIX */ { true, true, false, false, false },
68     /* CS */ { true, false, true, false, false },
69     /* CU */ { false, false, true, false, false },
70     /* CX */ { false, false, false, false, false }
71
72     };
73
74     /**
75         Get an integer representation of the type of the lock. This method is guaranteed
76         to return an integer >= 0 and < C_NUMBER. No correlation between the value
77         and one of the static variables (CIS etc.) is guaranteed, except that
78         the values returned do not change.
79     */

80     public int getType() {
81         return type;
82     }
83
84     public boolean isCompatible(ContainerLock granted) {
85
86         return isCompatible(granted.getType());
87     }
88
89     public boolean isCompatible(int granted) {
90
91         return C_COMPAT[getType()][granted];
92     }
93
94     public String JavaDoc toString() {
95
96         return shortnames[getType()];
97     }
98 }
99
Popular Tags