com.landawn.abacus.util.LockMode Maven / Gradle / Ivy
/*
* Copyright (C) 2015 HaiYang Li
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.landawn.abacus.util;
/**
* {@code R} --- Read; {@code A} --- Add; {@code U} --- Update; {@code D} --- Delete.
*
*/
public enum LockMode {
/**
* Others can't read by bean id (but can query by condition) if lock on this level.
*/
R(1),
/**
* Others can't add(insert) if lock on this level.
*
* @deprecated not supported at present.
*/
@Deprecated
A(2),
/**
* Others can't modify(update) if lock on this level.
*/
U(4),
/**
* Others can't delete if lock on this level.
*/
D(8),
/**
* Others can't read by bean id (but can query by condition) and add(insert) if lock on this level.
*
* @deprecated not supported at present.
*/
@Deprecated
RA(R.intValue + A.intValue),
/**
* Others can't read by bean id (but can query by condition) and modify(update) if lock on this level.
*/
RU(R.intValue + U.intValue),
/**
* Others can't read by bean id (but can query by condition) and delete if lock on this level.
*/
RD(R.intValue + D.intValue),
/**
* Others can't add(insert) and modify(update) if lock on this level.
*
* @deprecated not supported at present.
*/
@Deprecated
AU(A.intValue + U.intValue),
/**
* Others can't add(insert) and delete if lock on this level.
*
* @deprecated not supported at present.
*/
@Deprecated
AD(A.intValue + D.intValue),
/**
* Others can't modify(update) and delete if lock on this level.
*/
UD(U.intValue + D.intValue),
/**
* Others can't read by bean id (but can query by condition), add(insert) and modify(update) if lock on this
* level.
*
* @deprecated not supported at present.
*/
@Deprecated
RAU(R.intValue + A.intValue + U.intValue),
/**
* Others can't read by bean id (but can query by condition), add(insert) and delete if lock on this level.
*
* @deprecated not supported at present.
*/
@Deprecated
RAD(R.intValue + A.intValue + D.intValue),
/**
* Others can't read by bean id (but can query by condition), modify(update) and delete if lock on this level.
*/
RUD(R.intValue + U.intValue + D.intValue),
/**
* Others can't add(insert), modify(update) and delete if lock on this level.
*
* @deprecated not supported at present.
*/
@Deprecated
AUD(A.intValue + U.intValue + D.intValue),
/**
* Others read by bean id (but can query by condition), add(insert), modify(update) and delete if lock on this
* level.
*
* @deprecated not supported at present.
*/
@Deprecated
RAUD(R.intValue + A.intValue + U.intValue + D.intValue);
private final int intValue;
/**
*
* @param value
*/
LockMode(final int value) {
intValue = value;
}
/**
*
* @return int
*/
public int intValue() {
return intValue;
}
/**
*
* @param intValue
* @return LockMode
*/
public static LockMode valueOf(final int intValue) {
switch (intValue) {
case 1:
return R;
case 2:
return A;
case 4:
return U;
case 8:
return D;
case 3:
return RA;
case 5:
return RU;
case 9:
return RD;
case 6:
return AU;
case 10:
return AD;
case 12:
return UD;
case 7:
return RAU;
case 11:
return RAD;
case 13:
return RUD;
case 14:
return AUD;
case 15:
return RAUD;
default:
throw new IllegalArgumentException("Invalid lock mode value[" + intValue + "]. ");
}
}
/**
* Check if this {@code LockMode} is locked by the specified {@code byLockMode}.
*
* @param lockMode
* @return boolean
*/
public boolean isXLockOf(final LockMode lockMode) {
return (intValue & lockMode.intValue) > 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy