| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractLockStrategy |
|
| 1.1111111111111112;1.111 |
| 1 | package org.apache.ojb.odmg.locking; | |
| 2 | ||
| 3 | /* Copyright 2002-2005 The Apache Software Foundation | |
| 4 | * | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | ||
| 18 | import org.apache.ojb.odmg.TransactionImpl; | |
| 19 | import org.apache.ojb.broker.util.configuration.Configuration; | |
| 20 | import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator; | |
| 21 | ||
| 22 | import java.util.Collection; | |
| 23 | ||
| 24 | /** | |
| 25 | * The base class of all LockingStrategies. It provides the basic | |
| 26 | * infrastructure to read and write locks to the persistent storage. | |
| 27 | * @deprecated | |
| 28 | * @author Thomas Mahler | |
| 29 | */ | |
| 30 | public abstract class AbstractLockStrategy implements LockStrategy | |
| 31 | { | |
| 32 | /** | |
| 33 | * the timeout for lock entries | |
| 34 | */ | |
| 35 | public static long DEFAULT_LOCK_TIMEOUT = 30000; | |
| 36 | ||
| 37 | /** | |
| 38 | * the map holding all locks | |
| 39 | */ | |
| 40 | private static LockMap lockMap = null; | |
| 41 | ||
| 42 | ||
| 43 | public AbstractLockStrategy() | |
| 44 | { | |
| 45 | synchronized (AbstractLockStrategy.class) | |
| 46 | { | |
| 47 | if (lockMap == null) | |
| 48 | { | |
| 49 | lockMap = LockMapFactory.getLockMap(); | |
| 50 | Configuration conf = OjbConfigurator.getInstance().getConfigurationFor(null); | |
| 51 | DEFAULT_LOCK_TIMEOUT = conf.getInteger("LockTimeout", 60000); | |
| 52 | } | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 56 | ||
| 57 | /** | |
| 58 | * returns the LockEntry for the Writer of object obj. | |
| 59 | * If now writer exists, null is returned. | |
| 60 | */ | |
| 61 | protected LockEntry getWriter(Object obj) | |
| 62 | { | |
| 63 | return lockMap.getWriter(obj); | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * returns a collection of Reader LockEntries for object obj. | |
| 68 | * If now LockEntries could be found an empty Vector is returned. | |
| 69 | */ | |
| 70 | protected Collection getReaders(Object obj) | |
| 71 | { | |
| 72 | return lockMap.getReaders(obj); | |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Add a reader lock entry for transaction tx on object obj | |
| 77 | * to the persistent storage. | |
| 78 | */ | |
| 79 | protected boolean addReader(TransactionImpl tx, Object obj) | |
| 80 | { | |
| 81 | return lockMap.addReader(tx, obj); | |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * remove a reader lock entry for transaction tx on object obj | |
| 86 | * from the persistent storage. | |
| 87 | */ | |
| 88 | protected void removeReader(TransactionImpl tx, Object obj) | |
| 89 | { | |
| 90 | lockMap.removeReader(tx, obj); | |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * remove a writer lock entry for transaction tx on object obj | |
| 95 | * from the persistent storage. | |
| 96 | */ | |
| 97 | protected void removeWriter(LockEntry writer) | |
| 98 | { | |
| 99 | lockMap.removeWriter(writer); | |
| 100 | } | |
| 101 | ||
| 102 | ||
| 103 | /** | |
| 104 | * upgrade a reader lock entry for transaction tx on object obj | |
| 105 | * and write it to the persistent storage. | |
| 106 | */ | |
| 107 | protected boolean upgradeLock(LockEntry reader) | |
| 108 | { | |
| 109 | return lockMap.upgradeLock(reader); | |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * generate a writer lock entry for transaction tx on object obj | |
| 114 | * and write it to the persistent storage. | |
| 115 | */ | |
| 116 | protected boolean setWriter(TransactionImpl tx, Object obj) | |
| 117 | { | |
| 118 | return lockMap.setWriter(tx, obj); | |
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * check if there is a reader lock entry for transaction tx on object obj | |
| 123 | * in the persistent storage. | |
| 124 | */ | |
| 125 | protected boolean hasReadLock(TransactionImpl tx, Object obj) | |
| 126 | { | |
| 127 | return lockMap.hasReadLock(tx, obj); | |
| 128 | } | |
| 129 | ||
| 130 | } |