You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Robert Sfeir <ro...@codepuccino.com> on 2004/06/10 15:27:40 UTC

[patch] a couple more quick fixes

No biggie here.  I am working on fixing recursions.  These will take a 
bit longer since i need to understand what the code is doing better.  
There are 14 instances of Tail Recursions.


Re: [patch] a couple more quick fixes

Posted by Armin Waibel <ar...@apache.org>.
Hi,

I tried to apply Roberts patches in Eclipse3.0M9 without success.
Could someone else check in these patches?

regards,
Armin

Robert Sfeir wrote:
> No biggie here.  I am working on fixing recursions.  These will take a 
> bit longer since i need to understand what the code is doing better.  
> There are 14 instances of Tail Recursions.
> 
> 
> ------------------------------------------------------------------------
> 
> Index: AbstractTransactionManagerFactory.java
> ===================================================================
> RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/transaction/tm/AbstractTransactionManagerFactory.java,v
> retrieving revision 1.1
> diff -r1.1 AbstractTransactionManagerFactory.java
> 103c103
> <                 throw new TransactionManagerFactoryException("Can't lookup transaction manager:" + EOL + msg.toString());
> ---
> 
>>                throw new TransactionManagerFactoryException("Can't lookup transaction manager:" + EOL + msg);
>>
>>
>>------------------------------------------------------------------------
>>
>>Index: PBKey.java
>>===================================================================
>>RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/PBKey.java,v
>>retrieving revision 1.10
>>diff -r1.10 PBKey.java
>>77c77
>><             hashCode = new String(this.jcdAlias + this.user + this.password).hashCode();
>>---
>>
>>>            hashCode = ( this.jcdAlias + this.user + this.password ).hashCode();
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>Index: ReadCommittedStrategy.java
>>>===================================================================
>>>RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/odmg/locking/ReadCommittedStrategy.java,v
>>>retrieving revision 1.4
>>>diff -r1.4 ReadCommittedStrategy.java
>>>1c1
>>>< package org.apache.ojb.odmg.locking;
>>>
>>>---
>>>
>>>>package org.apache.ojb.odmg.locking;
>>>
>>>17,186c17,176
>>>< 
>>>
>>>< import org.apache.ojb.odmg.TransactionImpl;
>>>
>>>< 
>>>
>>>< /**
>>>
>>><  * The implementation of the Commited Reads Locking stra
>>>
>>><  * ReadCommitted - Reads and Writes require locks.
>>>
>>><  *
>>>
>>><  * Locks are acquired for reading and modifying the database.
>>>
>>><  * Locks are released after reading but locks on modified objects
>>>
>>><  * are held until EOT.
>>>
>>><  *
>>>
>>><  * Allows:
>>>
>>><  * Non-Repeatable Reads
>>>
>>><  * Phantom Readstegy.
>>>
>>><  *
>>>
>>><  * @author Thomas Mahler & David Dixon-Peugh
>>>
>>><  */
>>>
>>>< public class ReadCommittedStrategy extends AbstractLockStrategy
>>>
>>>< {
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * acquire a read lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction requesting the lock
>>>
>>><      * @param obj the Object to be locked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean readLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>>< 
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer == null)
>>>
>>><         {
>>>
>>><             addReader(tx, obj);
>>>
>>><             // if there has been a successful write locking, try again
>>>
>>><             if (getWriter(obj) == null)
>>>
>>><                 return true;
>>>
>>><             else
>>>
>>><             {
>>>
>>><                 removeReader(tx, obj);
>>>
>>><                 return readLock(tx, obj);
>>>
>>><             }
>>>
>>><         }
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;    // If I'm the writer, I can read.
>>>
>>><         }
>>>
>>><         else
>>>
>>><         {
>>>
>>><             return false;
>>>
>>><         }
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * acquire a write lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction requesting the lock
>>>
>>><      * @param obj the Object to be locked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean writeLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         // if there is no writer yet we can try to get the global write lock
>>>
>>><         if (writer == null)
>>>
>>><         {
>>>
>>><             // if lock could be acquired return true
>>>
>>><             if (setWriter(tx, obj))
>>>
>>><                 return true;
>>>
>>><             // else try again
>>>
>>><             else
>>>
>>><                 return writeLock(tx, obj);
>>>
>>><         }
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;    // If I'm the writer, then I can write.
>>>
>>><         }
>>>
>>>< 
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * acquire a lock upgrade (from read to write) lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction requesting the lock
>>>
>>><      * @param obj the Object to be locked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean upgradeLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer == null)
>>>
>>><         {
>>>
>>><             // if lock could be acquired return true
>>>
>>><             if (setWriter(tx, obj))
>>>
>>><                 return true;
>>>
>>><             // else try again
>>>
>>><             else
>>>
>>><                 return upgradeLock(tx, obj);
>>>
>>><         }
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;    // If I already have Write, then I've upgraded.
>>>
>>><         }
>>>
>>>< 
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * release a lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction releasing the lock
>>>
>>><      * @param obj the Object to be unlocked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean releaseLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>>< 
>>>
>>><         if (writer != null && writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             removeWriter(writer);
>>>
>>><             return true;
>>>
>>><         }
>>>
>>>< 
>>>
>>><         if (hasReadLock(tx, obj))
>>>
>>><         {
>>>
>>><             removeReader(tx, obj);
>>>
>>><             return true;
>>>
>>><         }
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * checks whether the specified Object obj is read-locked by Transaction tx.
>>>
>>><      * @param tx the transaction
>>>
>>><      * @param obj the Object to be checked
>>>
>>><      * @return true if lock exists, else false
>>>
>>><      */
>>>
>>><     public boolean checkRead(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         if (hasReadLock(tx, obj))
>>>
>>><         {
>>>
>>><             return true;
>>>
>>><         }
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;
>>>
>>><         }
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * checks whether the specified Object obj is write-locked by Transaction tx.
>>>
>>><      * @param tx the transaction
>>>
>>><      * @param obj the Object to be checked
>>>
>>><      * @return true if lock exists, else false
>>>
>>><      */
>>>
>>><     public boolean checkWrite(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer == null)
>>>
>>><             return false;
>>>
>>><         else if (writer.isOwnedBy(tx))
>>>
>>><             return true;
>>>
>>><         else
>>>
>>><             return false;
>>>
>>><     }
>>>
>>>< }
>>>
>>>---
>>>
>>>>import org.apache.ojb.odmg.TransactionImpl;
>>>>
>>>>/**
>>>> * The implementation of the Commited Reads Locking stra
>>>> * ReadCommitted - Reads and Writes require locks.
>>>> *
>>>> * Locks are acquired for reading and modifying the database.
>>>> * Locks are released after reading but locks on modified objects
>>>> * are held until EOT.
>>>> *
>>>> * Allows:
>>>> * Non-Repeatable Reads
>>>> * Phantom Readstegy.
>>>> *
>>>> * @author Thomas Mahler & David Dixon-Peugh
>>>> */
>>>>public class ReadCommittedStrategy extends AbstractLockStrategy
>>>>{
>>>>
>>>>    /**
>>>>     * acquire a read lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction requesting the lock
>>>>     * @param obj the Object to be locked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean readLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer == null)
>>>>        {
>>>>            addReader(tx, obj);
>>>>            // if there has been a successful write locking, try again
>>>>            if (getWriter(obj) == null)
>>>>                return true;
>>>>            else
>>>>            {
>>>>                removeReader(tx, obj);
>>>>                return readLock(tx, obj);
>>>>            }
>>>>        }
>>>>      return writer.isOwnedBy( tx );
>>>>    }
>>>>
>>>>    /**
>>>>     * acquire a write lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction requesting the lock
>>>>     * @param obj the Object to be locked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean writeLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>        // if there is no writer yet we can try to get the global write lock
>>>>        if (writer == null)
>>>>        {
>>>>            // if lock could be acquired return true
>>>>            if (setWriter(tx, obj))
>>>>                return true;
>>>>            // else try again
>>>>            else
>>>>                return writeLock(tx, obj);
>>>>        }
>>>>        if (writer.isOwnedBy(tx))
>>>>        {
>>>>            return true;    // If I'm the writer, then I can write.
>>>>        }
>>>>
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * acquire a lock upgrade (from read to write) lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction requesting the lock
>>>>     * @param obj the Object to be locked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean upgradeLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer == null)
>>>>        {
>>>>            // if lock could be acquired return true
>>>>            if (setWriter(tx, obj))
>>>>                return true;
>>>>            // else try again
>>>>            else
>>>>                return upgradeLock(tx, obj);
>>>>        }
>>>>        if (writer.isOwnedBy(tx))
>>>>        {
>>>>            return true;    // If I already have Write, then I've upgraded.
>>>>        }
>>>>
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * release a lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction releasing the lock
>>>>     * @param obj the Object to be unlocked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean releaseLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>
>>>>        if (writer != null && writer.isOwnedBy(tx))
>>>>        {
>>>>            removeWriter(writer);
>>>>            return true;
>>>>        }
>>>>
>>>>        if (hasReadLock(tx, obj))
>>>>        {
>>>>            removeReader(tx, obj);
>>>>            return true;
>>>>        }
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * checks whether the specified Object obj is read-locked by Transaction tx.
>>>>     * @param tx the transaction
>>>>     * @param obj the Object to be checked
>>>>     * @return true if lock exists, else false
>>>>     */
>>>>    public boolean checkRead(TransactionImpl tx, Object obj)
>>>>    {
>>>>        if (hasReadLock(tx, obj))
>>>>        {
>>>>            return true;
>>>>        }
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer.isOwnedBy(tx))
>>>>        {
>>>>            return true;
>>>>        }
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * checks whether the specified Object obj is write-locked by Transaction tx.
>>>>     * @param tx the transaction
>>>>     * @param obj the Object to be checked
>>>>     * @return true if lock exists, else false
>>>>     */
>>>>    public boolean checkWrite(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer == null)
>>>>            return false;
>>>>        else return writer.isOwnedBy( tx );
>>>>    }
>>>>}
>>>
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-dev-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [patch] a couple more quick fixes

Posted by Robert Sfeir <ro...@codepuccino.com>.
Excellent thanks.  I'll re check out the src dir and send on some more.

R

On Jun 11, 2004, at 3:02 PM, Jakob Braeuchi wrote:

> hi robert,
>
> i applied the small patches manually.
>
> jakob
>
> Robert Sfeir wrote:
>
>> No biggie here.  I am working on fixing recursions.  These will take  
>> a bit longer since i need to understand what the code is doing  
>> better.  There are 14 instances of Tail Recursions.
>> ---------------------------------------------------------------------- 
>> --
>> Index: AbstractTransactionManagerFactory.java
>> ===================================================================
>> RCS file:  
>> /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/transaction/tm/ 
>> AbstractTransactionManagerFactory.java,v
>> retrieving revision 1.1
>> diff -r1.1 AbstractTransactionManagerFactory.java
>> 103c103
>> <                 throw new TransactionManagerFactoryException("Can't  
>> lookup transaction manager:" + EOL + msg.toString());
>> ---
>>>                throw new TransactionManagerFactoryException("Can't  
>>> lookup transaction manager:" + EOL + msg);
>>>
>>>
>>> --------------------------------------------------------------------- 
>>> ---
>>>
>>> Index: PBKey.java
>>> ===================================================================
>>> RCS file:  
>>> /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/PBKey.java,v
>>> retrieving revision 1.10
>>> diff -r1.10 PBKey.java
>>> 77c77
>>> <             hashCode = new String(this.jcdAlias + this.user +  
>>> this.password).hashCode();
>>> ---
>>>
>>>>            hashCode = ( this.jcdAlias + this.user + this.password  
>>>> ).hashCode();
>>>>
>>>>
>>>> -------------------------------------------------------------------- 
>>>> ----
>>>>
>>>> Index: ReadCommittedStrategy.java
>>>> ===================================================================
>>>> RCS file:  
>>>> /home/cvspublic/db-ojb/src/java/org/apache/ojb/odmg/locking/ 
>>>> ReadCommittedStrategy.java,v
>>>> retrieving revision 1.4
>>>> diff -r1.4 ReadCommittedStrategy.java
>>>> 1c1
>>>> < package org.apache.ojb.odmg.locking;
>>>>
>>>> ---
>>>>
>>>>> package org.apache.ojb.odmg.locking;
>>>>
>>>> 17,186c17,176
>>>> <
>>>> < import org.apache.ojb.odmg.TransactionImpl;
>>>>
>>>> <
>>>> < /**
>>>>
>>>> <  * The implementation of the Commited Reads Locking stra
>>>>
>>>> <  * ReadCommitted - Reads and Writes require locks.
>>>>
>>>> <  *
>>>>
>>>> <  * Locks are acquired for reading and modifying the database.
>>>>
>>>> <  * Locks are released after reading but locks on modified objects
>>>>
>>>> <  * are held until EOT.
>>>>
>>>> <  *
>>>>
>>>> <  * Allows:
>>>>
>>>> <  * Non-Repeatable Reads
>>>>
>>>> <  * Phantom Readstegy.
>>>>
>>>> <  *
>>>>
>>>> <  * @author Thomas Mahler & David Dixon-Peugh
>>>>
>>>> <  */
>>>>
>>>> < public class ReadCommittedStrategy extends AbstractLockStrategy
>>>>
>>>> < {
>>>>
>>>> <
>>>> <     /**
>>>>
>>>> <      * acquire a read lock on Object obj for Transaction tx.
>>>>
>>>> <      * @param tx the transaction requesting the lock
>>>>
>>>> <      * @param obj the Object to be locked
>>>>
>>>> <      * @return true if successful, else false
>>>>
>>>> <      *
>>>>
>>>> <      */
>>>>
>>>> <     public boolean readLock(TransactionImpl tx, Object obj)
>>>>
>>>> <     {
>>>>
>>>> <
>>>> <         LockEntry writer = getWriter(obj);
>>>>
>>>> <         if (writer == null)
>>>>
>>>> <         {
>>>>
>>>> <             addReader(tx, obj);
>>>>
>>>> <             // if there has been a successful write locking, try  
>>>> again
>>>>
>>>> <             if (getWriter(obj) == null)
>>>>
>>>> <                 return true;
>>>>
>>>> <             else
>>>>
>>>> <             {
>>>>
>>>> <                 removeReader(tx, obj);
>>>>
>>>> <                 return readLock(tx, obj);
>>>>
>>>> <             }
>>>>
>>>> <         }
>>>>
>>>> <         if (writer.isOwnedBy(tx))
>>>>
>>>> <         {
>>>>
>>>> <             return true;    // If I'm the writer, I can read.
>>>>
>>>> <         }
>>>>
>>>> <         else
>>>>
>>>> <         {
>>>>
>>>> <             return false;
>>>>
>>>> <         }
>>>>
>>>> <     }
>>>>
>>>> <
>>>> <     /**
>>>>
>>>> <      * acquire a write lock on Object obj for Transaction tx.
>>>>
>>>> <      * @param tx the transaction requesting the lock
>>>>
>>>> <      * @param obj the Object to be locked
>>>>
>>>> <      * @return true if successful, else false
>>>>
>>>> <      *
>>>>
>>>> <      */
>>>>
>>>> <     public boolean writeLock(TransactionImpl tx, Object obj)
>>>>
>>>> <     {
>>>>
>>>> <         LockEntry writer = getWriter(obj);
>>>>
>>>> <         // if there is no writer yet we can try to get the global  
>>>> write lock
>>>>
>>>> <         if (writer == null)
>>>>
>>>> <         {
>>>>
>>>> <             // if lock could be acquired return true
>>>>
>>>> <             if (setWriter(tx, obj))
>>>>
>>>> <                 return true;
>>>>
>>>> <             // else try again
>>>>
>>>> <             else
>>>>
>>>> <                 return writeLock(tx, obj);
>>>>
>>>> <         }
>>>>
>>>> <         if (writer.isOwnedBy(tx))
>>>>
>>>> <         {
>>>>
>>>> <             return true;    // If I'm the writer, then I can  
>>>> write.
>>>>
>>>> <         }
>>>>
>>>> <
>>>> <         return false;
>>>>
>>>> <     }
>>>>
>>>> <
>>>> <     /**
>>>>
>>>> <      * acquire a lock upgrade (from read to write) lock on Object  
>>>> obj for Transaction tx.
>>>>
>>>> <      * @param tx the transaction requesting the lock
>>>>
>>>> <      * @param obj the Object to be locked
>>>>
>>>> <      * @return true if successful, else false
>>>>
>>>> <      *
>>>>
>>>> <      */
>>>>
>>>> <     public boolean upgradeLock(TransactionImpl tx, Object obj)
>>>>
>>>> <     {
>>>>
>>>> <         LockEntry writer = getWriter(obj);
>>>>
>>>> <         if (writer == null)
>>>>
>>>> <         {
>>>>
>>>> <             // if lock could be acquired return true
>>>>
>>>> <             if (setWriter(tx, obj))
>>>>
>>>> <                 return true;
>>>>
>>>> <             // else try again
>>>>
>>>> <             else
>>>>
>>>> <                 return upgradeLock(tx, obj);
>>>>
>>>> <         }
>>>>
>>>> <         if (writer.isOwnedBy(tx))
>>>>
>>>> <         {
>>>>
>>>> <             return true;    // If I already have Write, then I've  
>>>> upgraded.
>>>>
>>>> <         }
>>>>
>>>> <
>>>> <         return false;
>>>>
>>>> <     }
>>>>
>>>> <
>>>> <     /**
>>>>
>>>> <      * release a lock on Object obj for Transaction tx.
>>>>
>>>> <      * @param tx the transaction releasing the lock
>>>>
>>>> <      * @param obj the Object to be unlocked
>>>>
>>>> <      * @return true if successful, else false
>>>>
>>>> <      *
>>>>
>>>> <      */
>>>>
>>>> <     public boolean releaseLock(TransactionImpl tx, Object obj)
>>>>
>>>> <     {
>>>>
>>>> <         LockEntry writer = getWriter(obj);
>>>>
>>>> <
>>>> <         if (writer != null && writer.isOwnedBy(tx))
>>>>
>>>> <         {
>>>>
>>>> <             removeWriter(writer);
>>>>
>>>> <             return true;
>>>>
>>>> <         }
>>>>
>>>> <
>>>> <         if (hasReadLock(tx, obj))
>>>>
>>>> <         {
>>>>
>>>> <             removeReader(tx, obj);
>>>>
>>>> <             return true;
>>>>
>>>> <         }
>>>>
>>>> <         return false;
>>>>
>>>> <     }
>>>>
>>>> <
>>>> <     /**
>>>>
>>>> <      * checks whether the specified Object obj is read-locked by  
>>>> Transaction tx.
>>>>
>>>> <      * @param tx the transaction
>>>>
>>>> <      * @param obj the Object to be checked
>>>>
>>>> <      * @return true if lock exists, else false
>>>>
>>>> <      */
>>>>
>>>> <     public boolean checkRead(TransactionImpl tx, Object obj)
>>>>
>>>> <     {
>>>>
>>>> <         if (hasReadLock(tx, obj))
>>>>
>>>> <         {
>>>>
>>>> <             return true;
>>>>
>>>> <         }
>>>>
>>>> <         LockEntry writer = getWriter(obj);
>>>>
>>>> <         if (writer.isOwnedBy(tx))
>>>>
>>>> <         {
>>>>
>>>> <             return true;
>>>>
>>>> <         }
>>>>
>>>> <         return false;
>>>>
>>>> <     }
>>>>
>>>> <
>>>> <     /**
>>>>
>>>> <      * checks whether the specified Object obj is write-locked by  
>>>> Transaction tx.
>>>>
>>>> <      * @param tx the transaction
>>>>
>>>> <      * @param obj the Object to be checked
>>>>
>>>> <      * @return true if lock exists, else false
>>>>
>>>> <      */
>>>>
>>>> <     public boolean checkWrite(TransactionImpl tx, Object obj)
>>>>
>>>> <     {
>>>>
>>>> <         LockEntry writer = getWriter(obj);
>>>>
>>>> <         if (writer == null)
>>>>
>>>> <             return false;
>>>>
>>>> <         else if (writer.isOwnedBy(tx))
>>>>
>>>> <             return true;
>>>>
>>>> <         else
>>>>
>>>> <             return false;
>>>>
>>>> <     }
>>>>
>>>> < }
>>>>
>>>> ---
>>>>
>>>>> import org.apache.ojb.odmg.TransactionImpl;
>>>>>
>>>>> /**
>>>>> * The implementation of the Commited Reads Locking stra
>>>>> * ReadCommitted - Reads and Writes require locks.
>>>>> *
>>>>> * Locks are acquired for reading and modifying the database.
>>>>> * Locks are released after reading but locks on modified objects
>>>>> * are held until EOT.
>>>>> *
>>>>> * Allows:
>>>>> * Non-Repeatable Reads
>>>>> * Phantom Readstegy.
>>>>> *
>>>>> * @author Thomas Mahler & David Dixon-Peugh
>>>>> */
>>>>> public class ReadCommittedStrategy extends AbstractLockStrategy
>>>>> {
>>>>>
>>>>>    /**
>>>>>     * acquire a read lock on Object obj for Transaction tx.
>>>>>     * @param tx the transaction requesting the lock
>>>>>     * @param obj the Object to be locked
>>>>>     * @return true if successful, else false
>>>>>     *
>>>>>     */
>>>>>    public boolean readLock(TransactionImpl tx, Object obj)
>>>>>    {
>>>>>
>>>>>        LockEntry writer = getWriter(obj);
>>>>>        if (writer == null)
>>>>>        {
>>>>>            addReader(tx, obj);
>>>>>            // if there has been a successful write locking, try  
>>>>> again
>>>>>            if (getWriter(obj) == null)
>>>>>                return true;
>>>>>            else
>>>>>            {
>>>>>                removeReader(tx, obj);
>>>>>                return readLock(tx, obj);
>>>>>            }
>>>>>        }
>>>>>      return writer.isOwnedBy( tx );
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     * acquire a write lock on Object obj for Transaction tx.
>>>>>     * @param tx the transaction requesting the lock
>>>>>     * @param obj the Object to be locked
>>>>>     * @return true if successful, else false
>>>>>     *
>>>>>     */
>>>>>    public boolean writeLock(TransactionImpl tx, Object obj)
>>>>>    {
>>>>>        LockEntry writer = getWriter(obj);
>>>>>        // if there is no writer yet we can try to get the global  
>>>>> write lock
>>>>>        if (writer == null)
>>>>>        {
>>>>>            // if lock could be acquired return true
>>>>>            if (setWriter(tx, obj))
>>>>>                return true;
>>>>>            // else try again
>>>>>            else
>>>>>                return writeLock(tx, obj);
>>>>>        }
>>>>>        if (writer.isOwnedBy(tx))
>>>>>        {
>>>>>            return true;    // If I'm the writer, then I can write.
>>>>>        }
>>>>>
>>>>>        return false;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     * acquire a lock upgrade (from read to write) lock on Object  
>>>>> obj for Transaction tx.
>>>>>     * @param tx the transaction requesting the lock
>>>>>     * @param obj the Object to be locked
>>>>>     * @return true if successful, else false
>>>>>     *
>>>>>     */
>>>>>    public boolean upgradeLock(TransactionImpl tx, Object obj)
>>>>>    {
>>>>>        LockEntry writer = getWriter(obj);
>>>>>        if (writer == null)
>>>>>        {
>>>>>            // if lock could be acquired return true
>>>>>            if (setWriter(tx, obj))
>>>>>                return true;
>>>>>            // else try again
>>>>>            else
>>>>>                return upgradeLock(tx, obj);
>>>>>        }
>>>>>        if (writer.isOwnedBy(tx))
>>>>>        {
>>>>>            return true;    // If I already have Write, then I've  
>>>>> upgraded.
>>>>>        }
>>>>>
>>>>>        return false;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     * release a lock on Object obj for Transaction tx.
>>>>>     * @param tx the transaction releasing the lock
>>>>>     * @param obj the Object to be unlocked
>>>>>     * @return true if successful, else false
>>>>>     *
>>>>>     */
>>>>>    public boolean releaseLock(TransactionImpl tx, Object obj)
>>>>>    {
>>>>>        LockEntry writer = getWriter(obj);
>>>>>
>>>>>        if (writer != null && writer.isOwnedBy(tx))
>>>>>        {
>>>>>            removeWriter(writer);
>>>>>            return true;
>>>>>        }
>>>>>
>>>>>        if (hasReadLock(tx, obj))
>>>>>        {
>>>>>            removeReader(tx, obj);
>>>>>            return true;
>>>>>        }
>>>>>        return false;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     * checks whether the specified Object obj is read-locked by  
>>>>> Transaction tx.
>>>>>     * @param tx the transaction
>>>>>     * @param obj the Object to be checked
>>>>>     * @return true if lock exists, else false
>>>>>     */
>>>>>    public boolean checkRead(TransactionImpl tx, Object obj)
>>>>>    {
>>>>>        if (hasReadLock(tx, obj))
>>>>>        {
>>>>>            return true;
>>>>>        }
>>>>>        LockEntry writer = getWriter(obj);
>>>>>        if (writer.isOwnedBy(tx))
>>>>>        {
>>>>>            return true;
>>>>>        }
>>>>>        return false;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     * checks whether the specified Object obj is write-locked by  
>>>>> Transaction tx.
>>>>>     * @param tx the transaction
>>>>>     * @param obj the Object to be checked
>>>>>     * @return true if lock exists, else false
>>>>>     */
>>>>>    public boolean checkWrite(TransactionImpl tx, Object obj)
>>>>>    {
>>>>>        LockEntry writer = getWriter(obj);
>>>>>        if (writer == null)
>>>>>            return false;
>>>>>        else return writer.isOwnedBy( tx );
>>>>>    }
>>>>> }
>>>>
>>>>
>>>>
>>>> -------------------------------------------------------------------- 
>>>> ----
>>>>
>>>> -------------------------------------------------------------------- 
>>>> -
>>>> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Re: [patch] a couple more quick fixes

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi robert,

i applied the small patches manually.

jakob

Robert Sfeir wrote:

> No biggie here.  I am working on fixing recursions.  These will take a 
> bit longer since i need to understand what the code is doing better.  
> There are 14 instances of Tail Recursions.
> 
> 
> ------------------------------------------------------------------------
> 
> Index: AbstractTransactionManagerFactory.java
> ===================================================================
> RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/transaction/tm/AbstractTransactionManagerFactory.java,v
> retrieving revision 1.1
> diff -r1.1 AbstractTransactionManagerFactory.java
> 103c103
> <                 throw new TransactionManagerFactoryException("Can't lookup transaction manager:" + EOL + msg.toString());
> ---
> 
>>                throw new TransactionManagerFactoryException("Can't lookup transaction manager:" + EOL + msg);
>>
>>
>>------------------------------------------------------------------------
>>
>>Index: PBKey.java
>>===================================================================
>>RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/PBKey.java,v
>>retrieving revision 1.10
>>diff -r1.10 PBKey.java
>>77c77
>><             hashCode = new String(this.jcdAlias + this.user + this.password).hashCode();
>>---
>>
>>>            hashCode = ( this.jcdAlias + this.user + this.password ).hashCode();
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>Index: ReadCommittedStrategy.java
>>>===================================================================
>>>RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/odmg/locking/ReadCommittedStrategy.java,v
>>>retrieving revision 1.4
>>>diff -r1.4 ReadCommittedStrategy.java
>>>1c1
>>>< package org.apache.ojb.odmg.locking;
>>>
>>>---
>>>
>>>>package org.apache.ojb.odmg.locking;
>>>
>>>17,186c17,176
>>>< 
>>>
>>>< import org.apache.ojb.odmg.TransactionImpl;
>>>
>>>< 
>>>
>>>< /**
>>>
>>><  * The implementation of the Commited Reads Locking stra
>>>
>>><  * ReadCommitted - Reads and Writes require locks.
>>>
>>><  *
>>>
>>><  * Locks are acquired for reading and modifying the database.
>>>
>>><  * Locks are released after reading but locks on modified objects
>>>
>>><  * are held until EOT.
>>>
>>><  *
>>>
>>><  * Allows:
>>>
>>><  * Non-Repeatable Reads
>>>
>>><  * Phantom Readstegy.
>>>
>>><  *
>>>
>>><  * @author Thomas Mahler & David Dixon-Peugh
>>>
>>><  */
>>>
>>>< public class ReadCommittedStrategy extends AbstractLockStrategy
>>>
>>>< {
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * acquire a read lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction requesting the lock
>>>
>>><      * @param obj the Object to be locked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean readLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>>< 
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer == null)
>>>
>>><         {
>>>
>>><             addReader(tx, obj);
>>>
>>><             // if there has been a successful write locking, try again
>>>
>>><             if (getWriter(obj) == null)
>>>
>>><                 return true;
>>>
>>><             else
>>>
>>><             {
>>>
>>><                 removeReader(tx, obj);
>>>
>>><                 return readLock(tx, obj);
>>>
>>><             }
>>>
>>><         }
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;    // If I'm the writer, I can read.
>>>
>>><         }
>>>
>>><         else
>>>
>>><         {
>>>
>>><             return false;
>>>
>>><         }
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * acquire a write lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction requesting the lock
>>>
>>><      * @param obj the Object to be locked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean writeLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         // if there is no writer yet we can try to get the global write lock
>>>
>>><         if (writer == null)
>>>
>>><         {
>>>
>>><             // if lock could be acquired return true
>>>
>>><             if (setWriter(tx, obj))
>>>
>>><                 return true;
>>>
>>><             // else try again
>>>
>>><             else
>>>
>>><                 return writeLock(tx, obj);
>>>
>>><         }
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;    // If I'm the writer, then I can write.
>>>
>>><         }
>>>
>>>< 
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * acquire a lock upgrade (from read to write) lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction requesting the lock
>>>
>>><      * @param obj the Object to be locked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean upgradeLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer == null)
>>>
>>><         {
>>>
>>><             // if lock could be acquired return true
>>>
>>><             if (setWriter(tx, obj))
>>>
>>><                 return true;
>>>
>>><             // else try again
>>>
>>><             else
>>>
>>><                 return upgradeLock(tx, obj);
>>>
>>><         }
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;    // If I already have Write, then I've upgraded.
>>>
>>><         }
>>>
>>>< 
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * release a lock on Object obj for Transaction tx.
>>>
>>><      * @param tx the transaction releasing the lock
>>>
>>><      * @param obj the Object to be unlocked
>>>
>>><      * @return true if successful, else false
>>>
>>><      *
>>>
>>><      */
>>>
>>><     public boolean releaseLock(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>>< 
>>>
>>><         if (writer != null && writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             removeWriter(writer);
>>>
>>><             return true;
>>>
>>><         }
>>>
>>>< 
>>>
>>><         if (hasReadLock(tx, obj))
>>>
>>><         {
>>>
>>><             removeReader(tx, obj);
>>>
>>><             return true;
>>>
>>><         }
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * checks whether the specified Object obj is read-locked by Transaction tx.
>>>
>>><      * @param tx the transaction
>>>
>>><      * @param obj the Object to be checked
>>>
>>><      * @return true if lock exists, else false
>>>
>>><      */
>>>
>>><     public boolean checkRead(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         if (hasReadLock(tx, obj))
>>>
>>><         {
>>>
>>><             return true;
>>>
>>><         }
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer.isOwnedBy(tx))
>>>
>>><         {
>>>
>>><             return true;
>>>
>>><         }
>>>
>>><         return false;
>>>
>>><     }
>>>
>>>< 
>>>
>>><     /**
>>>
>>><      * checks whether the specified Object obj is write-locked by Transaction tx.
>>>
>>><      * @param tx the transaction
>>>
>>><      * @param obj the Object to be checked
>>>
>>><      * @return true if lock exists, else false
>>>
>>><      */
>>>
>>><     public boolean checkWrite(TransactionImpl tx, Object obj)
>>>
>>><     {
>>>
>>><         LockEntry writer = getWriter(obj);
>>>
>>><         if (writer == null)
>>>
>>><             return false;
>>>
>>><         else if (writer.isOwnedBy(tx))
>>>
>>><             return true;
>>>
>>><         else
>>>
>>><             return false;
>>>
>>><     }
>>>
>>>< }
>>>
>>>---
>>>
>>>>import org.apache.ojb.odmg.TransactionImpl;
>>>>
>>>>/**
>>>> * The implementation of the Commited Reads Locking stra
>>>> * ReadCommitted - Reads and Writes require locks.
>>>> *
>>>> * Locks are acquired for reading and modifying the database.
>>>> * Locks are released after reading but locks on modified objects
>>>> * are held until EOT.
>>>> *
>>>> * Allows:
>>>> * Non-Repeatable Reads
>>>> * Phantom Readstegy.
>>>> *
>>>> * @author Thomas Mahler & David Dixon-Peugh
>>>> */
>>>>public class ReadCommittedStrategy extends AbstractLockStrategy
>>>>{
>>>>
>>>>    /**
>>>>     * acquire a read lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction requesting the lock
>>>>     * @param obj the Object to be locked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean readLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer == null)
>>>>        {
>>>>            addReader(tx, obj);
>>>>            // if there has been a successful write locking, try again
>>>>            if (getWriter(obj) == null)
>>>>                return true;
>>>>            else
>>>>            {
>>>>                removeReader(tx, obj);
>>>>                return readLock(tx, obj);
>>>>            }
>>>>        }
>>>>      return writer.isOwnedBy( tx );
>>>>    }
>>>>
>>>>    /**
>>>>     * acquire a write lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction requesting the lock
>>>>     * @param obj the Object to be locked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean writeLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>        // if there is no writer yet we can try to get the global write lock
>>>>        if (writer == null)
>>>>        {
>>>>            // if lock could be acquired return true
>>>>            if (setWriter(tx, obj))
>>>>                return true;
>>>>            // else try again
>>>>            else
>>>>                return writeLock(tx, obj);
>>>>        }
>>>>        if (writer.isOwnedBy(tx))
>>>>        {
>>>>            return true;    // If I'm the writer, then I can write.
>>>>        }
>>>>
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * acquire a lock upgrade (from read to write) lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction requesting the lock
>>>>     * @param obj the Object to be locked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean upgradeLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer == null)
>>>>        {
>>>>            // if lock could be acquired return true
>>>>            if (setWriter(tx, obj))
>>>>                return true;
>>>>            // else try again
>>>>            else
>>>>                return upgradeLock(tx, obj);
>>>>        }
>>>>        if (writer.isOwnedBy(tx))
>>>>        {
>>>>            return true;    // If I already have Write, then I've upgraded.
>>>>        }
>>>>
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * release a lock on Object obj for Transaction tx.
>>>>     * @param tx the transaction releasing the lock
>>>>     * @param obj the Object to be unlocked
>>>>     * @return true if successful, else false
>>>>     *
>>>>     */
>>>>    public boolean releaseLock(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>
>>>>        if (writer != null && writer.isOwnedBy(tx))
>>>>        {
>>>>            removeWriter(writer);
>>>>            return true;
>>>>        }
>>>>
>>>>        if (hasReadLock(tx, obj))
>>>>        {
>>>>            removeReader(tx, obj);
>>>>            return true;
>>>>        }
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * checks whether the specified Object obj is read-locked by Transaction tx.
>>>>     * @param tx the transaction
>>>>     * @param obj the Object to be checked
>>>>     * @return true if lock exists, else false
>>>>     */
>>>>    public boolean checkRead(TransactionImpl tx, Object obj)
>>>>    {
>>>>        if (hasReadLock(tx, obj))
>>>>        {
>>>>            return true;
>>>>        }
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer.isOwnedBy(tx))
>>>>        {
>>>>            return true;
>>>>        }
>>>>        return false;
>>>>    }
>>>>
>>>>    /**
>>>>     * checks whether the specified Object obj is write-locked by Transaction tx.
>>>>     * @param tx the transaction
>>>>     * @param obj the Object to be checked
>>>>     * @return true if lock exists, else false
>>>>     */
>>>>    public boolean checkWrite(TransactionImpl tx, Object obj)
>>>>    {
>>>>        LockEntry writer = getWriter(obj);
>>>>        if (writer == null)
>>>>            return false;
>>>>        else return writer.isOwnedBy( tx );
>>>>    }
>>>>}
>>>
>>>
>>>
>>>------------------------------------------------------------------------
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-dev-help@db.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org