db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/core PersistenceBrokerImpl.java QueryReferenceBroker.java
Date Fri, 04 Mar 2005 18:07:23 GMT
arminw      2005/03/04 10:07:23

  Modified:    src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_1_0_RELEASE RsIterator.java
               src/java/org/apache/ojb/broker/cache Tag: OJB_1_0_RELEASE
                        MaterializationCache.java
               src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        PersistenceBrokerImpl.java
                        QueryReferenceBroker.java
  Log:
  - improve PB#retrieveAllReferences/retrieveReference methods to work proper with circular
references
  - add new methods to LocalCache to allow add/remove cached objects from LocalCache
  - rename LocalCache method
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.63.2.9  +2 -2      db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.63.2.8
  retrieving revision 1.63.2.9
  diff -u -r1.63.2.8 -r1.63.2.9
  --- RsIterator.java	15 Feb 2005 19:17:48 -0000	1.63.2.8
  +++ RsIterator.java	4 Mar 2005 18:07:22 -0000	1.63.2.9
  @@ -484,7 +484,7 @@
                           catch(RuntimeException e)
                           {
                               // catch runtime exc. to guarantee clearing of internal buffer
on failure
  -                            getCache().doInternalClear();
  +                            getCache().doLocalClear();
                               throw e;
                           }
                       }
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +21 -21    db-ojb/src/java/org/apache/ojb/broker/cache/Attic/MaterializationCache.java
  
  Index: MaterializationCache.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/Attic/MaterializationCache.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- MaterializationCache.java	23 Jan 2005 03:07:31 -0000	1.1.2.1
  +++ MaterializationCache.java	4 Mar 2005 18:07:23 -0000	1.1.2.2
  @@ -60,7 +60,7 @@
        * references.
        * <br/>
        * If an code block with 'enabledMaterializationCache' throws an exception, in catch-block
  -     * method {@link #doInternalClear()} have to be called.
  +     * method {@link #doLocalClear()} have to be called.
        */
       public void enableMaterializationCache()
       {
  @@ -94,7 +94,7 @@
               }
               finally
               {
  -                doInternalClear();
  +                doLocalClear();
               }
           }
       }
  @@ -105,7 +105,7 @@
           // else use the application cache
           if(enabledReadCache)
           {
  -            cacheObject(oid, obj, type);
  +            doLocalCache(oid, obj, type);
           }
           else
           {
  @@ -119,7 +119,7 @@
       }
   
       /**
  -     * @see ObjectCache#cacheIfNew(org.apache.ojb.broker.Identity, Object)
  +     * @see ObjectCacheInternal#cacheIfNew(org.apache.ojb.broker.Identity, Object)
        */ 
       public boolean cacheIfNew(Identity oid, Object obj)
       {
  @@ -131,7 +131,7 @@
           Object result = null;
           if(enabledReadCache)
           {
  -            result = lookupObject(oid);
  +            result = doLocalLookup(oid);
           }
           if(result == null)
           {
  @@ -140,19 +140,30 @@
           return result;
       }
   
  +    public Object doLocalLookup(Identity oid)
  +    {
  +        ObjectEntry entry = (ObjectEntry) objectBuffer.get(oid);
  +        return entry != null ? entry.obj : null;
  +    }
  +
       public void remove(Identity oid)
       {
           if(enabledReadCache)
           {
  -            removeObject(oid);
  +            doLocalRemove(oid);
           }
           cacheDistributor.remove(oid);
       }
   
  +    public void doLocalRemove(Identity oid)
  +    {
  +        objectBuffer.remove(oid);
  +    }
  +
       /**
        * Clears the internal used cache for object materialization.
        */
  -    public void doInternalClear()
  +    public void doLocalClear()
       {
           if(log.isDebugEnabled()) log.debug("Clear materialization cache");
           invokeCounter = 0;
  @@ -163,26 +174,15 @@
       public void clear()
       {
           if(log.isDebugEnabled()) log.debug("Clear used caches");
  -        doInternalClear();
  +        doLocalClear();
           cacheDistributor.clear();
       }
   
  -    private void cacheObject(Identity oid, Object obj, int type)
  +    private void doLocalCache(Identity oid, Object obj, int type)
       {
           objectBuffer.put(oid, new ObjectEntry(obj, type));
       }
   
  -    private Object lookupObject(Identity oid)
  -    {
  -        ObjectEntry entry = (ObjectEntry) objectBuffer.get(oid);
  -        return entry != null ? entry.obj : null;
  -    }
  -
  -    private void removeObject(Identity oid)
  -    {
  -        objectBuffer.remove(oid);
  -    }
  -
       private void pushObjects()
       {
           Iterator it = objectBuffer.entrySet().iterator();
  
  
  
  No                   revision
  No                   revision
  1.83.2.13 +62 -20    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.83.2.12
  retrieving revision 1.83.2.13
  diff -u -r1.83.2.12 -r1.83.2.13
  --- PersistenceBrokerImpl.java	15 Feb 2005 19:17:49 -0000	1.83.2.12
  +++ PersistenceBrokerImpl.java	4 Mar 2005 18:07:23 -0000	1.83.2.13
  @@ -1226,11 +1226,36 @@
        */
       public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException
       {
  +        if (logger.isDebugEnabled())
  +        {
  +        	logger.debug("Manually retrieving all references for object " + serviceIdentity().buildIdentity(pInstance));
  +        }
           ClassDescriptor cld = getClassDescriptor(pInstance.getClass());
           // force loading of references
           final boolean forced = true;
  -        referencesBroker.retrieveReferences(pInstance, cld, forced);
  -        referencesBroker.retrieveCollections(pInstance, cld, forced);
  +        getInternalCache().enableMaterializationCache();
  +        // to avoid problems with circular references, locally cache the current object
instance
  +        Identity oid = serviceIdentity().buildIdentity(pInstance);
  +        boolean needLocalRemove = false;
  +        if(getInternalCache().doLocalLookup(oid) == null)
  +        {
  +            getInternalCache().doInternalCache(oid, pInstance, MaterializationCache.TYPE_UNKNOWN);
  +            needLocalRemove = true;
  +        }
  +        try
  +        {
  +            referencesBroker.retrieveReferences(pInstance, cld, forced);
  +            referencesBroker.retrieveCollections(pInstance, cld, forced);
  +            // do locally remove the object to avoid problems with object state detection
(insert/update),
  +            // because objects found in the cache detected as 'old' means 'update'
  +            if(needLocalRemove) getInternalCache().doLocalRemove(oid);
  +            getInternalCache().disableMaterializationCache();
  +        }
  +        catch(RuntimeException e)
  +        {
  +            getInternalCache().doLocalClear();
  +            throw e;
  +        }
       }
   
       /**
  @@ -1241,33 +1266,50 @@
        */
       public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException
       {
  -        // tomdz: This message is perhaps not so useful as to generate it for each
  -        //        call to this method (which is used for manual maintenance of relations)
?
  -/*
  -        if (logger.isEnabledFor(Logger.INFO))
  +        if (logger.isDebugEnabled())
           {
  -        	logger.info("Retrieving reference named["+pAttributeName+"] on ["+
  +        	logger.debug("Retrieving reference named ["+pAttributeName+"] on object of type
["+
           	            pInstance.getClass().getName()+"]");
           }
  -*/
           ClassDescriptor cld = getClassDescriptor(pInstance.getClass());
           CollectionDescriptor cod = cld.getCollectionDescriptorByName(pAttributeName);
  -        if (cod != null)
  +        getInternalCache().enableMaterializationCache();
  +        // to avoid problems with circular references, locally cache the current object
instance
  +        Identity oid = serviceIdentity().buildIdentity(pInstance);
  +        boolean needLocalRemove = false;
  +        if(getInternalCache().doLocalLookup(oid) == null)
           {
  -            referencesBroker.retrieveCollection(pInstance, cld, cod, true);
  +            getInternalCache().doInternalCache(oid, pInstance, MaterializationCache.TYPE_UNKNOWN);
  +            needLocalRemove = true;
           }
  -        else
  +        try
           {
  -            ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName(pAttributeName);
  -            if (ord != null)
  +            if (cod != null)
               {
  -                referencesBroker.retrieveReference(pInstance, cld, ord, true);
  +                referencesBroker.retrieveCollection(pInstance, cld, cod, true);
               }
               else
               {
  -                throw new PersistenceBrokerException("did not find attribute " + pAttributeName
+
  -                        " for class " + pInstance.getClass().getName());
  +                ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName(pAttributeName);
  +                if (ord != null)
  +                {
  +                    referencesBroker.retrieveReference(pInstance, cld, ord, true);
  +                }
  +                else
  +                {
  +                    throw new PersistenceBrokerException("did not find attribute " + pAttributeName
+
  +                            " for class " + pInstance.getClass().getName());
  +                }
               }
  +            // do locally remove the object to avoid problems with object state detection
(insert/update),
  +            // because objects found in the cache detected as 'old' means 'update'
  +            if(needLocalRemove) getInternalCache().doLocalRemove(oid);
  +            getInternalCache().disableMaterializationCache();
  +        }
  +        catch(RuntimeException e)
  +        {
  +            getInternalCache().doLocalClear();
  +            throw e;
           }
       }
   
  @@ -1416,7 +1458,7 @@
                   }
                   catch(RuntimeException e)
                   {
  -                    objectCache.doInternalClear();
  +                    objectCache.doLocalClear();
                       throw e;
                   }
               }
  @@ -1470,7 +1512,7 @@
           catch(RuntimeException e)
           {
               // catch runtime exc. to guarantee clearing of internal buffer on failure
  -            objectCache.doInternalClear();
  +            objectCache.doLocalClear();
               throw e;
           }
           return result;
  @@ -1960,7 +2002,7 @@
       private void clearRegistrationLists()
       {
           nowStoring.clear();
  -        objectCache.doInternalClear();
  +        objectCache.doLocalClear();
           deletedDuringTransaction.clear();
           /*
           arminw:
  
  
  
  1.17.2.4  +8 -8      db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
  
  Index: QueryReferenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
  retrieving revision 1.17.2.3
  retrieving revision 1.17.2.4
  diff -u -r1.17.2.3 -r1.17.2.4
  --- QueryReferenceBroker.java	15 Feb 2005 19:17:49 -0000	1.17.2.3
  +++ QueryReferenceBroker.java	4 Mar 2005 18:07:23 -0000	1.17.2.4
  @@ -174,19 +174,19 @@
           catch(RuntimeException e)
           {
               // ==> clear materialization cache
  -            pb.getInternalCache().doInternalClear();
  +            pb.getInternalCache().doLocalClear();
               throw e;
           }
           catch (InstantiationException ex)
           {
               // ==> clear materialization cache
  -            pb.getInternalCache().doInternalClear();
  +            pb.getInternalCache().doLocalClear();
               log.error(ex);
               throw new PersistenceBrokerException(ex);
           }
           catch (IllegalAccessException ex)
           {
  -            pb.getInternalCache().doInternalClear();
  +            pb.getInternalCache().doLocalClear();
               log.error(ex);
               throw new PersistenceBrokerException(ex);
           }
  @@ -411,7 +411,7 @@
               }
               catch(RuntimeException e)
               {
  -                pb.getInternalCache().doInternalClear();
  +                pb.getInternalCache().doLocalClear();
                   throw e;
               }
           }
  @@ -444,7 +444,7 @@
           }
           catch(RuntimeException e)
           {
  -            pb.getInternalCache().doInternalClear();
  +            pb.getInternalCache().doLocalClear();
               throw e;
           }
           classToPrefetch = saveClassToPrefetch;
  @@ -645,7 +645,7 @@
                   }
                   catch(RuntimeException e)
                   {
  -                    pb.getInternalCache().doInternalClear();
  +                    pb.getInternalCache().doLocalClear();
                       throw e;
                   }
               }
  @@ -799,7 +799,7 @@
           }
           catch(RuntimeException e)
           {
  -            pb.getInternalCache().doInternalClear();
  +            pb.getInternalCache().doLocalClear();
               throw e;
           }
           classToPrefetch = saveClassToPrefetch;
  
  
  

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


Mime
View raw message