001: /*
002:
003: Derby - Class org.apache.derby.iapi.store.raw.RowLock
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.store.raw;
023:
024: /**
025: A RowLock represents a qualifier that is to be used when
026: locking a Row through a RecordHandle.
027:
028: <BR>
029: MT - Immutable
030:
031: @see RecordHandle
032: @see LockingPolicy
033: */
034:
035: public final class RowLock {
036:
037: private final int type;
038:
039: // Names of locks for virtual lock table print out
040: private static String[] shortnames = { "S", "S", "U", "U", "X",
041: "X", "X", "X" };
042:
043: /* Row Shared lock for repeatable read and below isolation level */
044: public static final RowLock RS2 = new RowLock(0);
045: /* Row Shared lock for serialized read isolation level */
046: public static final RowLock RS3 = new RowLock(1);
047: /* Row Update lock for reapeatable read and below isolation level*/
048: public static final RowLock RU2 = new RowLock(2);
049: /* Row Update lock for serializable isolation level*/
050: public static final RowLock RU3 = new RowLock(3);
051: /* Row Insert previous key lock */
052: public static final RowLock RIP = new RowLock(4);
053: /* Row Insert lock */
054: public static final RowLock RI = new RowLock(5);
055: /* Row exclusive write lock for repeatable read and below isolation level */
056: public static final RowLock RX2 = new RowLock(6);
057: /* Row exclusive write lock for serializable isolation level */
058: public static final RowLock RX3 = new RowLock(7);
059:
060: /** Number of row locks */
061: public static final int R_NUMBER = 8;
062:
063: /** Row lock compatability table */
064: public static final boolean[][] R_COMPAT = {
065: // Granted
066: // Request RS2 RS3 RU2 RU3 RIP RI RX2 RX3
067: //
068: /* RS2 */{ true, true, true, true, true, false, false,
069: false },
070: /* RS3 */{ true, true, true, true, false, false, false,
071: false },
072: /* RU2 */{ true, true, false, false, true, false, false,
073: false },
074: /* RU3 */{ true, true, false, false, false, false, false,
075: false },
076: /* RIP */{ true, false, true, false, true, true, true,
077: false },
078: /* RI */{ false, false, false, false, true, false, false,
079: false },
080: /* RX2 */{ false, false, false, false, true, false, false,
081: false },
082: /* RX3 */{ false, false, false, false, false, false,
083: false, false } };
084:
085: /* lock debugging stuff */
086: public static final String DIAG_INDEX = "index";
087: public static final String DIAG_XACTID = "xactid";
088: public static final String DIAG_LOCKTYPE = "locktype";
089: public static final String DIAG_LOCKMODE = "lockmode";
090: public static final String DIAG_CONGLOMID = "conglomId";
091: public static final String DIAG_CONTAINERID = "containerId";
092: public static final String DIAG_SEGMENTID = "segmentId";
093: public static final String DIAG_PAGENUM = "pageNum";
094: public static final String DIAG_RECID = "RecId";
095: public static final String DIAG_COUNT = "count";
096: public static final String DIAG_GROUP = "group";
097: public static final String DIAG_STATE = "state";
098:
099: private RowLock(int type) {
100: this .type = type;
101: }
102:
103: /**
104: Get an integer representation of the type of the lock. This method is
105: guaranteed to return an integer >= 0 and < R_NUMBER. No correlation
106: between the value and one of the static variables (CIS etc.) is
107: guaranteed, except that the values returned do not change.
108: */
109: public int getType() {
110: return type;
111: }
112:
113: public boolean isCompatible(RowLock granted) {
114:
115: return isCompatible(granted.getType());
116: }
117:
118: public boolean isCompatible(int granted) {
119:
120: return R_COMPAT[getType()][granted];
121: }
122:
123: public String toString() {
124: return shortnames[getType()];
125: }
126: }
|