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/accesslayer RsIterator.java
Date Mon, 28 Jul 2003 08:14:51 GMT
arminw      2003/07/28 01:14:51

  Modified:    src/java/org/apache/ojb/odmg ObjectEnvelope.java
               src/java/org/apache/ojb/odmg/states ModificationState.java
               src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/accesslayer RsIterator.java
  Added:       src/java/org/apache/ojb/odmg LoadedObjectsRegistry.java
  Log:
  move LoadedObjectsRegistry from PB-layer
  to ODMG-layer
  
  Revision  Changes    Path
  1.22      +22 -15    db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
  
  Index: ObjectEnvelope.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelope.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ObjectEnvelope.java	1 May 2003 16:39:56 -0000	1.21
  +++ ObjectEnvelope.java	28 Jul 2003 08:14:43 -0000	1.22
  @@ -70,17 +70,18 @@
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.VirtualProxy;
  +import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  -import org.apache.ojb.broker.core.LoadedObjectsRegistry;
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.states.ModificationState;
  +import org.odmg.ODMGRuntimeException;
   
   //#ifdef JDK13
   import java.lang.reflect.Proxy;
  @@ -230,8 +231,7 @@
        * getMap() will return the image of the Object.
        *
        */
  - private Map getMap()
  -            throws org.apache.ojb.broker.PersistenceBrokerException
  +    private Map getMap() throws PersistenceBrokerException
       {
           Map fieldValues = new HashMap();
           ClassDescriptor mif = tx.getBroker().getClassDescriptor(getObject().getClass());
  @@ -402,7 +402,7 @@
       private void setInitialModificationState()
       {
           // determine appropriate modification state
  -        ModificationState initialState;
  +        ModificationState initialState = null;
           Object result;
   
           if (LoadedObjectsRegistry.isRegistered(myObj))
  @@ -411,6 +411,12 @@
           }
           else
           {
  +            /*
  +            arminw:
  +            TODO: check out
  +            initial point to register used objects
  +            */
  +            LoadedObjectsRegistry.register(myObj);
               Identity id = new Identity(myObj, tx.getBroker());
   
               try
  @@ -418,9 +424,10 @@
                   // try to lookup the object.
                   result = tx.getBroker().getObjectByIdentity(id);
               }
  -            catch (org.apache.ojb.broker.PersistenceBrokerException ex)
  +            catch (PersistenceBrokerException ex)
               {
  -                throw new org.odmg.ODMGRuntimeException(ex.getMessage());
  +                LoggerFactory.getDefaultLogger().error("ObjectEnvelope: ", ex);
  +                throw new ODMGRuntimeException(ex.getMessage());
               }
               if (result == null)
               {
  @@ -502,7 +509,7 @@
           else
               return true;
       }
  -    
  +
       public void rollback()
       {
       	if(myObj != null && beforeImage != null)
  @@ -516,12 +523,12 @@
   			{
   				 FieldDescriptor fd = fieldDescs[i];
   				 PersistentField f = fd.getPersistentField();
  -				 
  +
   				 Object value = beforeImage.get(fd.getColumnName());
  -				 
  +
   				 f.set(myObj, value);
   			}
  -			
  +
   			/**
   			 * Set all the Object Reference values back
   			 * Don't know exactly what to do when the are identiy objects
  @@ -532,22 +539,22 @@
   			{
   				ObjectReferenceDescriptor rds = (ObjectReferenceDescriptor) iter.next();
   			 	Object temp = beforeImage.get(rds);
  -			 	
  +
   			 	if(temp instanceof Identity)
   				{
  -					// TODO what to do now? It was a VirtualProxy instance or a Proxy class.		 	
  +					// TODO what to do now? It was a VirtualProxy instance or a Proxy class.
   				}
   				else
   				{
   					rds.getPersistentField().set(myObj, temp);
   				}
  -			}		
  -			
  +			}
  +
   			/**
   			 * Now set all collections back. But we only stored DirtyMarks.
   			 * So what can be rolledback.?
   			 */
  -			Iterator collections = mif.getCollectionDescriptors().iterator();	
  +			Iterator collections = mif.getCollectionDescriptors().iterator();
       	}
       }
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/LoadedObjectsRegistry.java
  
  Index: LoadedObjectsRegistry.java
  ===================================================================
  package org.apache.ojb.odmg;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.WeakHashMap;
  
  /**
   * This is a helper class which registers all objects loaded
   * from database. It is used by ODMG layer to determine the state of
   * objects: if an object was not loaded from database then it is new.
   * Note: objects remain registered even after they are deleted. This
   * is necessary to prevent creation of deleted objects by another
   * thread, see <a href="http://archives.apache.org/eyebrowse/ReadMsg?listId=106&msgNo=1382">this<a>
   * for details.
   *
   * @author <a href="mailto:olegnitz@apache.org">Oleg Nitz<a>
   * @version $Id: LoadedObjectsRegistry.java,v 1.1 2003/07/28 08:14:43 arminw Exp $
   */
  public class LoadedObjectsRegistry
  {
      private static WeakHashMap registry = new WeakHashMap();
  
      private static final Object DUMMY = new Object();
  
      public static void register(Object object)
      {
          registry.put(object, DUMMY);
      }
  
      public static boolean isRegistered(Object object)
      {
          return (registry.get(object) != null);
      }
  
      public static void clear()
      {
          registry.clear();
      }
  
      public static void remove(Object object)
      {
          if(object != null)
              registry.remove(object);
      }
  }
  
  
  
  1.7       +10 -23    db-ojb/src/java/org/apache/ojb/odmg/states/ModificationState.java
  
  Index: ModificationState.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/states/ModificationState.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ModificationState.java	18 Apr 2003 13:04:33 -0000	1.6
  +++ ModificationState.java	28 Jul 2003 08:14:43 -0000	1.7
  @@ -58,6 +58,7 @@
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.ObjectEnvelope;
  +import org.apache.ojb.odmg.LoadedObjectsRegistry;
   
   /**
    * Describes an objects transactional state regarding commiting and rollbacking
  @@ -131,7 +132,6 @@
           return false;
       }
   
  -
       /**
        * remove Object from the ObjectCache
        */
  @@ -140,6 +140,13 @@
           try
           {
               broker.removeFromCache(objToBeRemoved);
  +            /*
  +            arminw:
  +            TODO: check out
  +            objects must also be remove from
  +            LoadedObjectsRegistry - Fix by Jamie Burns ????
  +            */
  +            LoadedObjectsRegistry.remove(objToBeRemoved);
           }
           catch (PersistenceBrokerException e)
           {
  @@ -148,39 +155,19 @@
           }
       }
   
  -
       /**
  -     * Method declaration
  -     *
  -     *
  -     * @param mod
  -     *
  -     * @throws org.apache.ojb.broker.PersistenceBrokerException
  -     *
        *
        */
       public abstract void checkpoint(ObjectEnvelope mod, PersistenceBroker broker)
  -            throws org.apache.ojb.broker.PersistenceBrokerException;
  +            throws PersistenceBrokerException;
   
       /**
  -     * Method declaration
  -     *
  -     *
  -     * @param mod
  -     *
  -     * @throws org.apache.ojb.broker.PersistenceBrokerException
  -     *
        *
        */
       public abstract void commit(ObjectEnvelope mod, PersistenceBroker broker)
  -            throws org.apache.ojb.broker.PersistenceBrokerException;
  +            throws PersistenceBrokerException;
   
       /**
  -     * Method declaration
  -     *
  -     *
  -     * @param mod
  -     *
        *
        */
       public abstract void rollback(ObjectEnvelope mod, PersistenceBroker broker);
  
  
  
  1.30      +23 -14    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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- PersistenceBrokerImpl.java	16 Jul 2003 15:53:03 -0000	1.29
  +++ PersistenceBrokerImpl.java	28 Jul 2003 08:14:43 -0000	1.30
  @@ -1603,7 +1603,11 @@
                   // cache object immediately , so that references
                   // can be established from referenced Objects back to this Object
                   objectCache.cache(oid, newObj);
  -                LoadedObjectsRegistry.register(newObj);
  +                /*
  +                arminw:
  +                LoadedOnjectsRegistry moved to odmg-layer
  +                */
  +                // LoadedObjectsRegistry.register(newObj);
   
                   /*
   				 * Chris Lewington: can cause problems with multiple objects
  @@ -2089,15 +2093,11 @@
               FieldDescriptor currIdField = cld.getPrimaryKey();
               pf.set(obj, new Integer(newid));*/
   
  -            // cache object for symmetry with getObjectByXXX()
               /*
  -
  -            arminw
  -            TODO: Check it out. I comment out this, because the storeToDB-method
  -            does cache the given object too.
  +            arminw:
  +            move LoadedObjectsRegistry to odmg-layer
               */
  -            // objectCache.cache(obj);
  -            LoadedObjectsRegistry.register(obj);
  +            // LoadedObjectsRegistry.register(obj);
               // 4. store 1:n and m:n associations
               storeCollections(obj, cld.getCollectionDescriptors());
           }
  @@ -2187,8 +2187,7 @@
        */
       public void removeFromCache(Object obj) throws PersistenceBrokerException
       {
  -    	// objects must also be remove from LoadedObjectsRegistry
  -    	// Fix by Jamie Burns
  +
           Identity identity;
           if (obj instanceof Identity)
           {
  @@ -2199,7 +2198,13 @@
               identity = new Identity(obj, this);
           }
           Object objectToRemove = objectCache.lookup(identity);
  -        LoadedObjectsRegistry.remove(objectToRemove);
  +        /*
  +        objects must also be remove from LoadedObjectsRegistry
  +    	Fix by Jamie Burns
  +        arminw:
  +        move LoadedObjectsRegistry to odmg-layer
  +        */
  +        // LoadedObjectsRegistry.remove(objectToRemove);
           objectCache.remove(identity);
       }
   
  @@ -2227,8 +2232,12 @@
        */
       public void clearCache() throws PersistenceBrokerException
       {
  -    	// fix by Jamie Burns
  -    	LoadedObjectsRegistry.clear();
  +    	/*
  +        arminw:
  +        move LoadedObjectsRegistry to odmg-layer
  +        */
  +        // fix by Jamie Burns
  +    	// LoadedObjectsRegistry.clear();
           objectCache.clear();
       }
   
  
  
  
  1.39      +6 -3      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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- RsIterator.java	1 Jul 2003 17:41:27 -0000	1.38
  +++ RsIterator.java	28 Jul 2003 08:14:50 -0000	1.39
  @@ -65,7 +65,6 @@
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
  -import org.apache.ojb.broker.core.LoadedObjectsRegistry;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -441,7 +440,11 @@
                       synchronized (result)
                       {
                           cache.cache(oid, result);
  -                        LoadedObjectsRegistry.register(result);
  +                        /*
  +                        arminw:
  +                        move LoadedObjectsRegistry to odmg-layer
  +                        */
  +                        // LoadedObjectsRegistry.register(result);
                           /**
                            * MBAIRD
                            * if you have multiple classes mapped to a table, and you query
on the base class
  
  
  

---------------------------------------------------------------------
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