KickJava   Java API By Example, From Geeks To Geeks.

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


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

34
35 public final class RowLock {
36
37     private final int type;
38
39     // Names of locks for virtual lock table print out
40
private static String JavaDoc[] shortnames = { "S", "S", "U", "U", "X", "X", "X", "X" };
41
42     /* Row Shared lock for repeatable read and below isolation level */
43     public static final RowLock RS2 = new RowLock(0);
44     /* Row Shared lock for serialized read isolation level */
45     public static final RowLock RS3 = new RowLock(1);
46     /* Row Update lock for reapeatable read and below isolation level*/
47     public static final RowLock RU2 = new RowLock(2);
48     /* Row Update lock for serializable isolation level*/
49     public static final RowLock RU3 = new RowLock(3);
50     /* Row Insert previous key lock */
51     public static final RowLock RIP = new RowLock(4);
52     /* Row Insert lock */
53     public static final RowLock RI = new RowLock(5);
54     /* Row exclusive write lock for repeatable read and below isolation level */
55     public static final RowLock RX2 = new RowLock(6);
56     /* Row exclusive write lock for serializable isolation level */
57     public static final RowLock RX3 = new RowLock(7);
58
59     /** Number of row locks */
60     public static final int R_NUMBER = 8;
61
62     /** Row lock compatability table */
63     public static final boolean[][] R_COMPAT = {
64         // Granted
65
// Request RS2 RS3 RU2 RU3 RIP RI RX2 RX3
66
//
67
/* RS2 */ {true, true, true, true, true, false, false, false },
68         /* RS3 */ {true, true, true, true, false, false, false, false },
69         /* RU2 */ {true, true, false, false, true, false, false, false },
70         /* RU3 */ {true, true, false, false, false, false, false, false },
71         /* RIP */ {true, false, true, false, true, true , true, false },
72         /* RI */ {false, false, false, false, true, false, false, false },
73         /* RX2 */ {false, false, false, false, true, false, false, false },
74         /* RX3 */ {false, false, false, false, false, false, false, false }
75     };
76
77     /* lock debugging stuff */
78     public static final String JavaDoc DIAG_INDEX = "index";
79     public static final String JavaDoc DIAG_XACTID = "xactid";
80     public static final String JavaDoc DIAG_LOCKTYPE = "locktype";
81     public static final String JavaDoc DIAG_LOCKMODE = "lockmode";
82     public static final String JavaDoc DIAG_CONGLOMID = "conglomId";
83     public static final String JavaDoc DIAG_CONTAINERID = "containerId";
84     public static final String JavaDoc DIAG_SEGMENTID = "segmentId";
85     public static final String JavaDoc DIAG_PAGENUM = "pageNum";
86     public static final String JavaDoc DIAG_RECID = "RecId";
87     public static final String JavaDoc DIAG_COUNT = "count";
88     public static final String JavaDoc DIAG_GROUP = "group";
89     public static final String JavaDoc DIAG_STATE = "state";
90
91     private RowLock(int type) {
92         this.type = type;
93     }
94
95     /**
96         Get an integer representation of the type of the lock. This method is
97         guaranteed to return an integer >= 0 and < R_NUMBER. No correlation
98         between the value and one of the static variables (CIS etc.) is
99         guaranteed, except that the values returned do not change.
100     */

101     public int getType() {
102         return type;
103     }
104
105     public boolean isCompatible(RowLock granted) {
106
107         return isCompatible(granted.getType());
108     }
109
110     public boolean isCompatible(int granted) {
111
112         return R_COMPAT[getType()][granted];
113     }
114
115     public String JavaDoc toString()
116     {
117         return shortnames[getType()];
118     }
119 }
120
Popular Tags