db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/otm/lock LockManager.java ObjectLock.java
Date Sun, 18 May 2003 09:49:11 GMT
olegnitz    2003/05/18 02:49:11

  Modified:    src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
                        RequestContext.java
               src/java/org/apache/ojb/otm/kit SimpleKit.java
               src/java/org/apache/ojb/otm/lock LockManager.java
                        ObjectLock.java
  Log:
  Made locking stuff work
  
  Revision  Changes    Path
  1.6       +16 -10    db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java
  
  Index: ConcreteEditingContext.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/ConcreteEditingContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConcreteEditingContext.java	15 May 2003 21:42:20 -0000	1.5
  +++ ConcreteEditingContext.java	18 May 2003 09:49:10 -0000	1.6
  @@ -120,8 +120,7 @@
           if (entry == null)
           {
               LockManager lockManager = LockManager.getInstance();
  -            lockManager.ensureLock(kit, oid, _transaction, lock);
  -            int lockHeld = lockManager.getLockHeld(kit, oid, _transaction);
  +            lockManager.ensureLock(oid, _transaction, lock);
               Swizzling swizzlingStrategy = kit.getSwizzlingStrategy();
               Object swizzledObject = swizzlingStrategy.swizzle(insertedObject, null);
               entry = new ContextEntry(swizzledObject);
  @@ -138,14 +137,12 @@
               {
                       // The object in context is the same object attempted an insert on
                       // Ensure we have the correct lock level
  -                lockManager.ensureLock(kit, oid, _transaction, lock);
  +                lockManager.ensureLock(oid, _transaction, lock);
               }
               else
               {
                       // It is a similar but different object
  -                int lockHeld = lockManager.getLockHeld(kit, oid, _transaction);
  -
  -                lockManager.ensureLock(kit, oid, _transaction, lock);
  +                lockManager.ensureLock(oid, _transaction, lock);
   
                   Object swizzledObject = swizzlingStrategy.swizzle(insertedObject, contextObject);
                   entry.object = swizzledObject;
  @@ -245,13 +242,10 @@
                   entry.state = state.commit();
               }
               connMan.executeBatch();
  +            releaseLocks();
               _objects.clear();
               _order.clear();
           }
  -        catch (Throwable t)
  -        {
  -            connMan.clearBatch();
  -        }
           finally
           {
               connMan.setBatchMode(saveBatchMode);
  @@ -271,8 +265,20 @@
               ContextEntry entry = (ContextEntry) _objects.get(iterator.next());
               entry.state = entry.state.rollback();
           }
  +        releaseLocks();
           _objects.clear();
           _order.clear();
  +    }
  +
  +    private void releaseLocks()
  +    {
  +        LockManager lockManager = LockManager.getInstance();
  +
  +        for (Iterator it = _objects.keySet().iterator(); it.hasNext(); )
  +        {
  +            Identity oid = (Identity) it.next();
  +            lockManager.releaseLock(oid, _transaction);
  +        }
       }
   
   
  
  
  
  1.7       +1 -2      db-ojb/src/java/org/apache/ojb/otm/core/RequestContext.java
  
  Index: RequestContext.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/core/RequestContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RequestContext.java	14 May 2003 22:15:37 -0000	1.6
  +++ RequestContext.java	18 May 2003 09:49:10 -0000	1.7
  @@ -55,7 +55,6 @@
    */
   
   import org.apache.ojb.broker.Identity;
  -import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.cache.ObjectCache;
   import org.apache.ojb.otm.OTMKit;
   import org.apache.ojb.otm.lock.LockType;
  @@ -173,7 +172,7 @@
           }
           catch (LockingException ex)
           {
  -            throw new PersistenceBrokerException(ex);
  +            throw new LockingPassthruException(ex);
           }
       }
   
  
  
  
  1.5       +4 -1      db-ojb/src/java/org/apache/ojb/otm/kit/SimpleKit.java
  
  Index: SimpleKit.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/kit/SimpleKit.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SimpleKit.java	19 Mar 2003 06:48:59 -0000	1.4
  +++ SimpleKit.java	18 May 2003 09:49:10 -0000	1.5
  @@ -64,6 +64,7 @@
   import org.apache.ojb.otm.lock.map.InMemoryLockMap;
   import org.apache.ojb.otm.lock.map.LockMap;
   import org.apache.ojb.otm.lock.wait.LockWaitStrategy;
  +import org.apache.ojb.otm.lock.wait.NoWaitStrategy;
   import org.apache.ojb.otm.swizzle.NoSwizzling;
   import org.apache.ojb.otm.swizzle.Swizzling;
   import org.apache.ojb.otm.transaction.LocalTransactionFactory;
  @@ -83,6 +84,7 @@
   
       private TransactionFactory _txFactory;
       private Swizzling _swizzlingStrategy;
  +    private LockWaitStrategy _lockWaitStrategy;
       private LockMap _lockMap;
       private ObjectCopyStrategy _copyStrategy;
       private ObjectStore _cacheStore;
  @@ -96,6 +98,7 @@
           super();
           _txFactory = new LocalTransactionFactory();
           _swizzlingStrategy = new NoSwizzling();
  +        _lockWaitStrategy = new NoWaitStrategy();
           _lockMap = new InMemoryLockMap();
           _copyStrategy = new SerializeObjectCopyStrategy();
           _cacheStore = new HashMapObjectStore();
  @@ -137,7 +140,7 @@
       */
       public LockWaitStrategy getLockWaitStrategy ()
       {
  -        return null;
  +        return _lockWaitStrategy;
       }
   
       /**
  
  
  
  1.3       +16 -22    db-ojb/src/java/org/apache/ojb/otm/lock/LockManager.java
  
  Index: LockManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/lock/LockManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LockManager.java	16 Mar 2003 18:13:06 -0000	1.2
  +++ LockManager.java	18 May 2003 09:49:10 -0000	1.3
  @@ -62,49 +62,43 @@
   /**
    *
    * Manages locks on objects across transactions.
  - * 
  + *
    * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
  - * 
  + *
    */
   public class LockManager
   {
       private static LockManager _Instance = new LockManager();
  -    
  +
       public static LockManager getInstance ()
       {
           return _Instance;
       }
  -    
  -    private LockManager ()
  +
  +    private LockManager()
       {
  -        
  +
       }
   
  -    public void ensureLock (OTMKit kit, Identity oid, Transaction tx, int lock)
  +    public void ensureLock(Identity oid, Transaction tx, int lock)
           throws LockingException
       {
  -        LockMap lockMap = kit.getLockMap();
  +        LockMap lockMap = tx.getKit().getLockMap();
   
           ObjectLock objectLock = lockMap.getLock(oid);
           if (lock == LockType.READ_LOCK)
           {
  -            if (!objectLock.isReader(tx))
  -            {
  -                readLock(objectLock, tx);
  -            }
  +            objectLock.readLock(tx);
           }
           else if (lock == LockType.WRITE_LOCK)
           {
  -            if (!tx.equals(objectLock.getWriter()))
  -            {
  -                writeLock(objectLock, tx);
  -            }
  +            objectLock.writeLock(tx);
           }
       }
   
  -    public int getLockHeld (OTMKit kit, Identity oid, Transaction tx)
  +    public int getLockHeld(Identity oid, Transaction tx)
       {
  -        LockMap lockMap = kit.getLockMap();
  +        LockMap lockMap = tx.getKit().getLockMap();
           ObjectLock lock = lockMap.getLock(oid);
   
           int lockHeld = LockType.NO_LOCK;
  @@ -120,11 +114,11 @@
           return lockHeld;
       }
   
  -    private void readLock (ObjectLock lock, Transaction tx)
  +    public void releaseLock(Identity oid, Transaction tx)
       {
  -    }
  +        LockMap lockMap = tx.getKit().getLockMap();
   
  -    private void writeLock (ObjectLock lock, Transaction tx)
  -    {
  +        ObjectLock objectLock = lockMap.getLock(oid);
  +        objectLock.releaseLock(tx);
       }
   }
  
  
  
  1.4       +4 -1      db-ojb/src/java/org/apache/ojb/otm/lock/ObjectLock.java
  
  Index: ObjectLock.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/lock/ObjectLock.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ObjectLock.java	16 Mar 2003 18:13:06 -0000	1.3
  +++ ObjectLock.java	18 May 2003 09:49:10 -0000	1.4
  @@ -260,10 +260,13 @@
   
               _readers.remove(_tx);
   
  -            for (Iterator iterator = _listeners.iterator(); iterator.hasNext();)
  +            if (_listeners != null)
               {
  +                for (Iterator iterator = _listeners.iterator(); iterator.hasNext();)
  +                {
                     LockListener listener = (LockListener) iterator.next();
                     listener.lockReleased(_tx, _oid);
  +                }
               }
           }
       }
  
  
  

Mime
View raw message