001: package org.apache.ojb.odmg.locking;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import org.apache.ojb.broker.Identity;
019: import org.apache.ojb.broker.locking.IsolationLevels;
020: import org.apache.ojb.broker.core.proxy.ProxyHelper;
021: import org.apache.ojb.broker.metadata.ClassDescriptor;
022: import org.apache.ojb.odmg.TransactionImpl;
023:
024: /**
025: * The odmg lock manager implementation of the {@link LockManager} interface. This class
026: * using the OJB kernel locking api {@link org.apache.ojb.broker.locking.LockManager}
027: * to manage object locking.
028: *
029: * @author <a href="mailto:arminw@apache.org">Armin Waibel</a>
030: * @version $Id: LockManagerOdmgImpl.java,v 1.1.2.4 2005/12/21 22:29:51 tomdz Exp $
031: */
032: public class LockManagerOdmgImpl implements LockManager {
033: private org.apache.ojb.broker.locking.LockManager lm;
034:
035: public LockManagerOdmgImpl(
036: org.apache.ojb.broker.locking.LockManager lm) {
037: this .lm = lm;
038: }
039:
040: private boolean ignore(int isolationLevel) {
041: return isolationLevel == IsolationLevels.IL_OPTIMISTIC
042: || isolationLevel == IsolationLevels.IL_NONE;
043: }
044:
045: public boolean readLock(TransactionImpl tx, Object obj) {
046: Identity oid = tx.getBroker().serviceIdentity().buildIdentity(
047: obj);
048: return readLock(tx, oid, obj);
049: }
050:
051: public boolean readLock(TransactionImpl tx, Identity oid, Object obj) {
052: ClassDescriptor cld = tx.getBroker().getClassDescriptor(
053: ProxyHelper.getRealClass(obj));
054: int isolationLevel = cld.getIsolationLevel();
055: return ignore(isolationLevel) ? true : lm.readLock(
056: tx.getGUID(), oid, isolationLevel);
057: }
058:
059: public boolean writeLock(TransactionImpl tx, Object obj) {
060: Identity oid = tx.getBroker().serviceIdentity().buildIdentity(
061: obj);
062: return writeLock(tx, oid, obj);
063: }
064:
065: public boolean writeLock(TransactionImpl tx, Identity oid,
066: Object obj) {
067: ClassDescriptor cld = tx.getBroker().getClassDescriptor(
068: ProxyHelper.getRealClass(obj));
069: int isolationLevel = cld.getIsolationLevel();
070: return ignore(isolationLevel) ? true : lm.writeLock(tx
071: .getGUID(), oid, isolationLevel);
072: }
073:
074: public boolean upgradeLock(TransactionImpl tx, Object obj) {
075: Identity oid = tx.getBroker().serviceIdentity().buildIdentity(
076: obj);
077: return upgradeLock(tx, oid, obj);
078: }
079:
080: public boolean upgradeLock(TransactionImpl tx, Identity oid,
081: Object obj) {
082: ClassDescriptor cld = tx.getBroker().getClassDescriptor(
083: ProxyHelper.getRealClass(obj));
084: int isolationLevel = cld.getIsolationLevel();
085: return ignore(isolationLevel) ? true : lm.upgradeLock(tx
086: .getGUID(), oid, isolationLevel);
087: }
088:
089: public boolean releaseLock(TransactionImpl tx, Object obj) {
090: Identity oid = tx.getBroker().serviceIdentity().buildIdentity(
091: obj);
092: return releaseLock(tx, oid, obj);
093: }
094:
095: public boolean releaseLock(TransactionImpl tx, Identity oid,
096: Object obj) {
097: return lm.releaseLock(tx.getGUID(), oid);
098: }
099:
100: public boolean checkRead(TransactionImpl tx, Object obj) {
101: Identity oid = tx.getBroker().serviceIdentity().buildIdentity(
102: obj);
103: return checkRead(tx, oid, obj);
104: }
105:
106: public boolean checkRead(TransactionImpl tx, Identity oid,
107: Object obj) {
108: return lm.hasRead(tx.getGUID(), oid);
109: }
110:
111: public boolean checkWrite(TransactionImpl tx, Object obj) {
112: Identity oid = tx.getBroker().serviceIdentity().buildIdentity(
113: obj);
114: return checkWrite(tx, oid, obj);
115: }
116:
117: public boolean checkWrite(TransactionImpl tx, Identity oid,
118: Object obj) {
119: return lm.hasWrite(tx.getGUID(), oid);
120: }
121: }
|