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.odmg.TransactionImpl;
019: import org.apache.ojb.broker.util.configuration.Configuration;
020: import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
021:
022: import java.util.Collection;
023:
024: /**
025: * The base class of all LockingStrategies. It provides the basic
026: * infrastructure to read and write locks to the persistent storage.
027: * @deprecated
028: * @author Thomas Mahler
029: */
030: public abstract class AbstractLockStrategy implements LockStrategy {
031: /**
032: * the timeout for lock entries
033: */
034: public static long DEFAULT_LOCK_TIMEOUT = 30000;
035:
036: /**
037: * the map holding all locks
038: */
039: private static LockMap lockMap = null;
040:
041: public AbstractLockStrategy() {
042: synchronized (AbstractLockStrategy.class) {
043: if (lockMap == null) {
044: lockMap = LockMapFactory.getLockMap();
045: Configuration conf = OjbConfigurator.getInstance()
046: .getConfigurationFor(null);
047: DEFAULT_LOCK_TIMEOUT = conf.getInteger("LockTimeout",
048: 60000);
049: }
050: }
051: }
052:
053: /**
054: * returns the LockEntry for the Writer of object obj.
055: * If now writer exists, null is returned.
056: */
057: protected LockEntry getWriter(Object obj) {
058: return lockMap.getWriter(obj);
059: }
060:
061: /**
062: * returns a collection of Reader LockEntries for object obj.
063: * If now LockEntries could be found an empty Vector is returned.
064: */
065: protected Collection getReaders(Object obj) {
066: return lockMap.getReaders(obj);
067: }
068:
069: /**
070: * Add a reader lock entry for transaction tx on object obj
071: * to the persistent storage.
072: */
073: protected boolean addReader(TransactionImpl tx, Object obj) {
074: return lockMap.addReader(tx, obj);
075: }
076:
077: /**
078: * remove a reader lock entry for transaction tx on object obj
079: * from the persistent storage.
080: */
081: protected void removeReader(TransactionImpl tx, Object obj) {
082: lockMap.removeReader(tx, obj);
083: }
084:
085: /**
086: * remove a writer lock entry for transaction tx on object obj
087: * from the persistent storage.
088: */
089: protected void removeWriter(LockEntry writer) {
090: lockMap.removeWriter(writer);
091: }
092:
093: /**
094: * upgrade a reader lock entry for transaction tx on object obj
095: * and write it to the persistent storage.
096: */
097: protected boolean upgradeLock(LockEntry reader) {
098: return lockMap.upgradeLock(reader);
099: }
100:
101: /**
102: * generate a writer lock entry for transaction tx on object obj
103: * and write it to the persistent storage.
104: */
105: protected boolean setWriter(TransactionImpl tx, Object obj) {
106: return lockMap.setWriter(tx, obj);
107: }
108:
109: /**
110: * check if there is a reader lock entry for transaction tx on object obj
111: * in the persistent storage.
112: */
113: protected boolean hasReadLock(TransactionImpl tx, Object obj) {
114: return lockMap.hasReadLock(tx, obj);
115: }
116:
117: }
|