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.Identity;
020    
021    /**
022     * This interface declares the functionality of the OJB internal Locking mechanism.
023     * A default implementaion LockManagerDefaultImpl is provided. This implementaion
024     * keeps distributed locks in the database. The locking mechanisms thus involves a
025     * lot of database lookups and writes. For some environments this solution may not
026     * be adequate. OJB allows to provide user defined implementations of this interface.
027     * To activate a user defined LockManagerDefaultImpl it must be configured in the OJB.properties file.
028     *
029     *
030     * @author thma
031     */
032    public interface LockManager
033    {
034        /**
035         * aquires a readlock for transaction tx on object obj.
036         * Returns true if successful, else false.
037         */
038        public abstract boolean readLock(TransactionImpl tx, Object obj);
039    
040        /**
041         * aquires a readlock for transaction tx on object obj.
042         * Returns true if successful, else false.
043         */
044        public abstract boolean readLock(TransactionImpl tx, Identity oid, Object obj);
045    
046    
047        /**
048         * aquires a writelock for transaction tx on object obj.
049         * Returns true if successful, else false.
050         */
051        public abstract boolean writeLock(TransactionImpl tx, Object obj);
052    
053        /**
054         * aquires a writelock for transaction tx on object obj.
055         * Returns true if successful, else false.
056         */
057        public abstract boolean writeLock(TransactionImpl tx, Identity oid, Object obj);
058    
059    
060        /**
061         * upgrades readlock for transaction tx on object obj to a writelock.
062         * If no readlock existed a writelock is acquired anyway.
063         * Returns true if successful, else false.
064         */
065        public abstract boolean upgradeLock(TransactionImpl tx, Object obj);
066    
067        /**
068         * upgrades readlock for transaction tx on object obj to a writelock.
069         * If no readlock existed a writelock is acquired anyway.
070         * Returns true if successful, else false.
071         */
072        public abstract boolean upgradeLock(TransactionImpl tx, Identity oid, Object obj);
073    
074    
075        /**
076         * releases a lock for transaction tx on object obj.
077         * Returns true if successful, else false.
078         */
079        public abstract boolean releaseLock(TransactionImpl tx, Object obj);
080    
081        /**
082         * releases a lock for transaction tx on object obj.
083         * Returns true if successful, else false.
084         */
085        public abstract boolean releaseLock(TransactionImpl tx, Identity oid, Object obj);
086    
087    
088        /**
089         * checks if there is a readlock for transaction tx on object obj.
090         * Returns true if so, else false.
091         */
092        public abstract boolean checkRead(TransactionImpl tx, Object obj);
093    
094        /**
095         * checks if there is a readlock for transaction tx on object obj.
096         * Returns true if so, else false.
097         */
098        public abstract boolean checkRead(TransactionImpl tx, Identity oid, Object obj);
099    
100    
101        /**
102         * checks if there is a writelock for transaction tx on object obj.
103         * Returns true if so, else false.
104         */
105        public abstract boolean checkWrite(TransactionImpl tx, Object obj);
106    
107        /**
108         * checks if there is a writelock for transaction tx on object obj.
109         * Returns true if so, else false.
110         */
111        public abstract boolean checkWrite(TransactionImpl tx, Identity oid, Object obj);
112    }