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/odmg ObjectEnvelope.java
Date Tue, 27 Jul 2004 00:33:12 GMT
arminw      2004/07/26 17:33:12

  Modified:    src/ejb/org/apache/ojb/ejb/pb Tag: OJB_1_0_RELEASE
                        PersonArticleClient.java
                        PersonArticleManagerPBBean.java
               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
                        ObjectCachePerClassImpl.java
               src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        DelegatingPersistenceBroker.java
                        PersistenceBrokerBean.java
                        PersistenceBrokerFactorySyncImpl.java
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/metadata/fieldaccess Tag:
                        OJB_1_0_RELEASE
                        AnonymousPersistentFieldForInheritance.java
                        AnonymousPersistentFieldHelper.java
               src/java/org/apache/ojb/broker/util/sequence Tag:
                        OJB_1_0_RELEASE AbstractSequenceManager.java
                        SequenceManagerHelper.java
               src/java/org/apache/ojb/broker/util Tag: OJB_1_0_RELEASE
                        WrappedConnection.java
               src/java/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        Identity.java PersistenceBroker.java
               src/java/org/apache/ojb/odmg Tag: OJB_1_0_RELEASE
                        ObjectEnvelope.java
  Log:
  merge changes made since 1.0 from trunk to OJB_1_0_RELEASE branch
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.5.2.1   +32 -17    db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleClient.java
  
  Index: PersonArticleClient.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleClient.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- PersonArticleClient.java	9 Jun 2004 00:49:29 -0000	1.5
  +++ PersonArticleClient.java	27 Jul 2004 00:33:10 -0000	1.5.2.1
  @@ -46,12 +46,41 @@
   
       public static void main(String[] args)
       {
  -//        PersonArticleClient client = new PersonArticleClient();
  -//        client.start();
           String[] arr = {PersonArticleClient.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  +    public void testNestedBrokerStore() throws Exception
  +    {
  +        int personsBefore = bean.personCount();
  +        int articlesBefore = bean.articleCount();
  +
  +        List articleList = VOHelper.createNewArticleList(6);
  +        List personList = VOHelper.createNewPersonList(4);
  +        bean.storeUsingNestedPB(articleList, personList);
  +
  +        int personsAfterStore = bean.personCount();
  +        int articlesAfterStore = bean.articleCount();
  +        assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore);
  +        assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore);
  +    }
  +
  +    public void testNestedBeans() throws Exception
  +    {
  +        int personsBefore = bean.personCount();
  +        int articlesBefore = bean.articleCount();
  +
  +        List articleList = VOHelper.createNewArticleList(6);
  +        List personList = VOHelper.createNewPersonList(4);
  +        // storing objects
  +        bean.storeUsingSubBeans(articleList, personList);
  +
  +        int personsAfterStore = bean.personCount();
  +        int articlesAfterStore = bean.articleCount();
  +        assertEquals("wrong number of articles after store", articlesBefore + 6, articlesAfterStore);
  +        assertEquals("wrong number of persons after store", personsBefore + 4, personsAfterStore);
  +    }
  +
       public void testNestedRollback() throws Exception
       {
           int articlesBefore = bean.articleCount();
  @@ -141,20 +170,6 @@
   
           int articlesAfterDelete = bean.articleCount();
           assertEquals("wrong number of articles after delete", articlesBefore, articlesAfterDelete);
  -    }
  -
  -    // only used when running outside junit
  -    public void start()
  -    {
  -        try
  -        {
  -            init();
  -            testNestedStoreDelete();
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -        }
       }
   
       protected void setUp() throws Exception
  
  
  
  1.5.2.1   +67 -1     db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleManagerPBBean.java
  
  Index: PersonArticleManagerPBBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/pb/PersonArticleManagerPBBean.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- PersonArticleManagerPBBean.java	9 Jun 2004 00:49:29 -0000	1.5
  +++ PersonArticleManagerPBBean.java	27 Jul 2004 00:33:10 -0000	1.5.2.1
  @@ -22,11 +22,19 @@
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
   import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
   import java.util.List;
   
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory;
  +import org.apache.ojb.broker.core.PersistenceBrokerFactoryIF;
  +import org.apache.ojb.broker.query.Query;
  +import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.ejb.ArticleVO;
  +import org.apache.ojb.ejb.PersonVO;
   import org.apache.ojb.ejb.SessionBeanImpl;
   
   /**
  @@ -78,6 +86,7 @@
       private Logger log = LoggerFactory.getLogger(PersonArticleManagerPBBean.class);
       private ArticleManagerPBLocal am;
       private PersonManagerPBLocal pm;
  +    private PersistenceBrokerFactoryIF pbf;
   
       public PersonArticleManagerPBBean()
       {
  @@ -85,9 +94,66 @@
   
       public void ejbCreate()
       {
  +        pbf = PersistenceBrokerFactoryFactory.instance();
  +    }
   
  +    /**
  +     * Stores article and persons using other beans.
  +     *
  +     * @ejb:interface-method
  +     */
  +    public void storeUsingNestedPB(List articles, List persons)
  +    {
  +        PersistenceBroker broker = pbf.defaultPersistenceBroker();
  +        try
  +        {
  +            // do something with broker
  +            Query q = new QueryByCriteria(PersonVO.class, null);
  +            broker.getCollectionByQuery(q);
  +            // System.out.println("## broker1: con=" + broker.serviceConnectionManager().getConnection());
  +            //now use nested bean call
  +            // System.out.println("####### DO nested bean call");
  +            ArticleManagerPBLocal am = getArticleManager();
  +            am.storeArticles(articles);
  +            // System.out.println("####### END nested bean call");
  +            // do more with broker
  +            // System.out.println("## broker1: now store objects");
  +            storeObjects(broker, persons);
  +            // System.out.println("## broker1: end store, con=" + broker.serviceConnectionManager().getConnection());
  +        }
  +//        catch(LookupException e)
  +//        {
  +//            throw new EJBException(e);
  +//        }
  +        finally
  +        {
  +            // System.out.println("## close broker1 now");
  +            if(broker != null) broker.close();
  +        }
       }
   
  +    private Collection storeObjects(PersistenceBroker broker, Collection objects)
  +    {
  +        for (Iterator it = objects.iterator(); it.hasNext();)
  +        {
  +            broker.store(it.next());
  +        }
  +        return objects;
  +    }
  +
  +    /**
  +     * Stores article and persons using other beans.
  +     *
  +     * @ejb:interface-method
  +     */
  +    public void storeUsingSubBeans(List articles, List persons)
  +    {
  +        //store all objects
  +        ArticleManagerPBLocal am = getArticleManager();
  +        PersonManagerPBLocal pm = getPersonManager();
  +        am.storeArticles(articles);
  +        pm.storePersons(persons);
  +    }
   
       /**
        * First stores all articles, persons form
  
  
  
  No                   revision
  No                   revision
  1.63.2.1  +16 -13    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
  retrieving revision 1.63.2.1
  diff -u -r1.63 -r1.63.2.1
  --- RsIterator.java	22 May 2004 09:51:26 -0000	1.63
  +++ RsIterator.java	27 Jul 2004 00:33:10 -0000	1.63.2.1
  @@ -269,6 +269,7 @@
                   // set target object
                   getAfterLookupEvent().setTarget(obj);
                   getBroker().fireBrokerEvent(getAfterLookupEvent());
  +                getAfterLookupEvent().setTarget(null);
                   return obj;
               }
               else
  @@ -414,19 +415,17 @@
            * itemProxyClass should NOT be a member variable.
            */
   
  +        // in any case we need the PK values of result set row
  +        // provide m_row with primary key data of current row
  +        getQueryObject().getClassDescriptor().getRowReader().readPkValuesFrom(getRsAndStmt().m_rs,
getRow());
  +
           if (getItemProxyClass() != null)
           {
  -            // provide m_row with primary key data of current row
  -            getQueryObject().getClassDescriptor().getRowReader().readPkValuesFrom(getRsAndStmt().m_rs,
getRow());
               // assert: m_row is filled with primary key values from db
               return getProxyFromResultSet();
           }
           else
           {
  -            // 0. provide m_row with data of current row
  -            getQueryObject().getClassDescriptor().getRowReader().readObjectArrayFrom(getRsAndStmt().m_rs,
getRow());
  -            // assert: m_row is filled from db
  -
               // 1.read Identity
               Identity oid = getIdentityFromResultSet();
               Object result = null;
  @@ -435,9 +434,11 @@
               result = getCache().lookup(oid);
               if (result == null)
               {
  +
  +                // map all field values from the current result set
  +                getQueryObject().getClassDescriptor().getRowReader().readObjectArrayFrom(getRsAndStmt().m_rs,
getRow());
                   // 3. If Object is not in cache
  -                // materialize Object with primitive attributes filled from
  -                // current row
  +                // materialize Object with primitive attributes filled from current row
                   result = getQueryObject().getClassDescriptor().getRowReader().readObjectFrom(getRow());
                   // result may still be null!
                   if (result != null)
  @@ -463,7 +464,7 @@
                            * actual class.
                            */
                           // fill reference and collection attributes
  -                        ClassDescriptor cld = getQueryObject().getClassDescriptor().getRepository().getDescriptorFor(result.getClass());
  +                        ClassDescriptor cld = getBroker().getClassDescriptor(result.getClass());
                           // don't force loading of reference
                           final boolean unforced = false;
                           // Maps ReferenceDescriptors to HashSets of owners
  @@ -475,11 +476,13 @@
               }
               else // Object is in cache
               {
  -                ClassDescriptor cld = getQueryObject().getClassDescriptor().getRepository().getDescriptorFor(result.getClass());
  -                // if refresh is required, update the cache instance from the
  -                // db
  +                ClassDescriptor cld = getBroker().getClassDescriptor(result.getClass());
  +                // if refresh is required, read all values from the result set and
  +                // update the cache instance from the db
                   if (cld.isAlwaysRefresh())
                   {
  +                    // map all field values from the current result set
  +                    getQueryObject().getClassDescriptor().getRowReader().readObjectArrayFrom(getRsAndStmt().m_rs,
getRow());
                       getQueryObject().getClassDescriptor().getRowReader().refreshObject(result,
getRow());
                   }
                   getBroker().refreshRelationships(result, cld);
  
  
  
  No                   revision
  No                   revision
  1.6.2.1   +34 -19    db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCachePerClassImpl.java
  
  Index: ObjectCachePerClassImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCachePerClassImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- ObjectCachePerClassImpl.java	4 Apr 2004 23:53:33 -0000	1.6
  +++ ObjectCachePerClassImpl.java	27 Jul 2004 00:33:11 -0000	1.6.2.1
  @@ -1,13 +1,13 @@
   package org.apache.ojb.broker.cache;
   
  -import org.apache.ojb.broker.PersistenceBroker;
  -import org.apache.ojb.broker.Identity;
  -
  -import java.util.Map;
  +import java.util.Collections;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Map;
   import java.util.Properties;
  -import java.util.Collections;
  +
  +import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
   
   /* Copyright 2003-2004 The Apache Software Foundation
    *
  @@ -23,6 +23,13 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
  +
  +/**
  + * Global {@link ObjectCache} implementation.
  + *
  + * @author matthew.baird
  + * @version $Id$
  + */
   public class ObjectCachePerClassImpl extends AbstractMetaCache
   {
       private static Map cachesByClass = Collections.synchronizedMap(new HashMap());
  @@ -37,7 +44,14 @@
   
       public ObjectCache getCache(Identity oid, Object obj, int methodCall)
       {
  -        return getCachePerClass(oid.getObjectsRealClass(), methodCall);
  +        if(oid.getObjectsRealClass() == null)
  +        {
  +            return null;
  +        }
  +        else
  +        {
  +            return getCachePerClass(oid.getObjectsRealClass(), methodCall);
  +        }
       }
   
       /**
  @@ -60,12 +74,12 @@
        * Sets the ObjectCache implementation to use for objects with the given
        * type and subclasses
        *
  -     * @param objectClass  The object's class, use java.lang.Object to alter
  -     *                     default caching for all objects which have no special
  -     *                     caching defined
  -     * @param cache        The new ObjectCache implementation to use for this
  -     *                     class and subclasses, null to switch off caching
  -     *                     for the given class
  +     * @param objectClass The object's class, use java.lang.Object to alter
  +     *                    default caching for all objects which have no special
  +     *                    caching defined
  +     * @param cache       The new ObjectCache implementation to use for this
  +     *                    class and subclasses, null to switch off caching
  +     *                    for the given class
        */
       public void setClassCache(Class objectClass, ObjectCache cache)
   
  @@ -76,8 +90,8 @@
       /**
        * Sets the ObjectCache implementation for the given class name
        *
  -     * @param className  The name of the class to cache
  -     * @param cache      The ObjectCache to use for this class and subclasses
  +     * @param className The name of the class to cache
  +     * @param cache     The ObjectCache to use for this class and subclasses
        */
       private void setClassCache(String className, ObjectCache cache)
       {
  @@ -87,16 +101,17 @@
       /**
        * Gets the cache for the given class
        *
  -     * @param objectClass  The class to look up the cache for
  -     * @return             The cache
  +     * @param objectClass The class to look up the cache for
  +     * @return The cache
        */
       private ObjectCache getCachePerClass(Class objectClass, int methodCall)
       {
           ObjectCache cache = (ObjectCache) cachesByClass.get(objectClass.getName());
  -        if (cache == null && AbstractMetaCache.METHOD_CACHE == methodCall)
  +        if (cache == null && AbstractMetaCache.METHOD_CACHE == methodCall
  +                && !cachesByClass.containsKey(objectClass.getName()))
           {
  -			cache = new ObjectCacheDefaultImpl(null, null);
  -			setClassCache(objectClass.getName(), cache);
  +            cache = new ObjectCacheDefaultImpl(null, null);
  +            setClassCache(objectClass.getName(), cache);
           }
           return cache;
       }
  
  
  
  No                   revision
  No                   revision
  1.11.2.1  +6 -0      db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java
  
  Index: DelegatingPersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/DelegatingPersistenceBroker.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- DelegatingPersistenceBroker.java	22 May 2004 09:51:25 -0000	1.11
  +++ DelegatingPersistenceBroker.java	27 Jul 2004 00:33:11 -0000	1.11.2.1
  @@ -14,6 +14,7 @@
   import org.apache.ojb.broker.TransactionAbortedException;
   import org.apache.ojb.broker.TransactionInProgressException;
   import org.apache.ojb.broker.TransactionNotInProgressException;
  +import org.apache.ojb.broker.IdentityFactory;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.accesslayer.JdbcAccess;
   import org.apache.ojb.broker.accesslayer.StatementManagerIF;
  @@ -244,6 +245,11 @@
   	{
   		return getBroker().serviceObjectCache();
   	}
  +
  +    public IdentityFactory serviceIdentity()
  +    {
  +        return getBroker().serviceIdentity();
  +    }
   
   	public void fireBrokerEvent(PersistenceBrokerEvent event)
   	{
  
  
  
  1.6.2.1   +6 -0      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerBean.java
  
  Index: PersistenceBrokerBean.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerBean.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- PersistenceBrokerBean.java	4 Apr 2004 23:53:33 -0000	1.6
  +++ PersistenceBrokerBean.java	27 Jul 2004 00:33:11 -0000	1.6.2.1
  @@ -28,6 +28,7 @@
   import org.apache.ojb.broker.TransactionAbortedException;
   import org.apache.ojb.broker.TransactionInProgressException;
   import org.apache.ojb.broker.TransactionNotInProgressException;
  +import org.apache.ojb.broker.IdentityFactory;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.accesslayer.JdbcAccess;
   import org.apache.ojb.broker.accesslayer.StatementManagerIF;
  @@ -391,6 +392,11 @@
   	{
   		return getBroker().serviceObjectCache();
   	}
  +
  +    public IdentityFactory serviceIdentity()
  +    {
  +        return getBroker().serviceIdentity();
  +    }
   
   	public void fireBrokerEvent(PersistenceBrokerEvent event)
   	{
  
  
  
  1.7.2.1   +2 -2      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java
  
  Index: PersistenceBrokerFactorySyncImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerFactorySyncImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- PersistenceBrokerFactorySyncImpl.java	19 Jun 2004 14:39:22 -0000	1.7
  +++ PersistenceBrokerFactorySyncImpl.java	27 Jul 2004 00:33:11 -0000	1.7.2.1
  @@ -118,7 +118,7 @@
           else
           {
               // wrap with PB handle
  -            super.wrapRequestedBrokerInstance(result);
  +            result = super.wrapRequestedBrokerInstance(result);
           }
           return result;
       }
  
  
  
  1.83.2.2  +16 -1     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.1
  retrieving revision 1.83.2.2
  diff -u -r1.83.2.1 -r1.83.2.2
  --- PersistenceBrokerImpl.java	26 Jul 2004 15:49:52 -0000	1.83.2.1
  +++ PersistenceBrokerImpl.java	27 Jul 2004 00:33:11 -0000	1.83.2.2
  @@ -24,6 +24,7 @@
   import java.util.Set;
   
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.IdentityFactory;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.MtoNImplementor;
   import org.apache.ojb.broker.PBKey;
  @@ -119,6 +120,7 @@
       private SequenceManager sequenceManager = null;
       private StatementManagerIF statementManager = null;
       private SqlGenerator sqlGenerator;
  +    private IdentityFactory identityFactory;
       private PBKey pbKey;
   
       /**
  @@ -190,6 +192,7 @@
                           connectionManager.getSupportedPlatform());
           mtoNBroker = new MtoNBroker(this);
           referencesBroker = new QueryReferenceBroker(this);
  +        identityFactory = new IdentityFactoryImpl(this);
       }
   
       public InternalCache getInternalCache()
  @@ -197,6 +200,11 @@
           return objectCache;
       }
   
  +    public IdentityFactory serviceIdentity()
  +    {
  +        return this.identityFactory;
  +    }
  +
       public SqlGenerator serviceSqlGenerator()
       {
           return this.sqlGenerator;
  @@ -483,6 +491,7 @@
               // Invoke events on PersistenceBrokerAware instances and listeners
               BEFORE_DELETE_EVENT.setTarget(obj);
               fireBrokerEvent(BEFORE_DELETE_EVENT);
  +            BEFORE_DELETE_EVENT.setTarget(null);
   
               // 1. delete dependend collections
               if (cld.getCollectionDescriptors().size() > 0)
  @@ -506,6 +515,7 @@
               // Invoke events on PersistenceBrokerAware instances and listeners
               AFTER_DELETE_EVENT.setTarget(obj);
               fireBrokerEvent(AFTER_DELETE_EVENT);
  +            AFTER_DELETE_EVENT.setTarget(null);
   
               // let the connection manager to execute batch
               connectionManager.executeBatchIfNecessary();
  @@ -1371,6 +1381,7 @@
           // Invoke events on PersistenceBrokerAware instances and listeners
           AFTER_LOOKUP_EVENT.setTarget(obj);
           fireBrokerEvent(AFTER_LOOKUP_EVENT);
  +        AFTER_LOOKUP_EVENT.setTarget(null);
   
           //logger.info("RETRIEVING object " + obj);
           return obj;
  @@ -1529,11 +1540,13 @@
           {
               BEFORE_STORE_EVENT.setTarget(obj);
               fireBrokerEvent(BEFORE_STORE_EVENT);
  +            BEFORE_STORE_EVENT.setTarget(null);
           }
           else
           {
               BEFORE_UPDATE_EVENT.setTarget(obj);
               fireBrokerEvent(BEFORE_UPDATE_EVENT);
  +            BEFORE_UPDATE_EVENT.setTarget(null);
           }
   
           if (obj != null)
  @@ -1557,11 +1570,13 @@
           {
               AFTER_STORE_EVENT.setTarget(obj);
               fireBrokerEvent(AFTER_STORE_EVENT);
  +            AFTER_STORE_EVENT.setTarget(null);
           }
           else
           {
               AFTER_UPDATE_EVENT.setTarget(obj);
               fireBrokerEvent(AFTER_UPDATE_EVENT);
  +            AFTER_UPDATE_EVENT.setTarget(null);
           }
       }
   
  
  
  
  No                   revision
  No                   revision
  1.11.2.1  +6 -5      db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldForInheritance.java
  
  Index: AnonymousPersistentFieldForInheritance.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldForInheritance.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- AnonymousPersistentFieldForInheritance.java	4 Apr 2004 23:53:35 -0000	1.11
  +++ AnonymousPersistentFieldForInheritance.java	27 Jul 2004 00:33:11 -0000	1.11.2.1
  @@ -15,12 +15,12 @@
    * limitations under the License.
    */
   
  +import java.util.Vector;
  +
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.MetadataException;
   import org.apache.ojb.broker.util.ClassHelper;
   
  -import java.util.Vector;
  -
   /**
    * @author Houar TINE
    * @version $Id$
  @@ -75,11 +75,12 @@
           {
               try
               {
  -                value = ClassHelper.newInstance(cld.getBaseClass());
  +                ClassDescriptor baseCld = cld.getRepository().getDescriptorFor(cld.getBaseClass());
  +                value = ClassHelper.buildNewObjectInstance(baseCld);
               }
               catch (Exception e)
               {
  -                throw new MetadataException(e);
  +                throw new MetadataException("Can't create new base class object for '"
+ cld.getBaseClass()+"'", e);
               }
               putToFieldCache(obj, value);
           }
  
  
  
  1.7.2.1   +17 -60    db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldHelper.java
  
  Index: AnonymousPersistentFieldHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AnonymousPersistentFieldHelper.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- AnonymousPersistentFieldHelper.java	4 Apr 2004 23:53:35 -0000	1.7
  +++ AnonymousPersistentFieldHelper.java	27 Jul 2004 00:33:11 -0000	1.7.2.1
  @@ -15,6 +15,10 @@
    * limitations under the License.
    */
   
  +import java.util.Iterator;
  +import java.util.Map;
  +import java.util.Vector;
  +
   import org.apache.ojb.broker.metadata.AnonymousFieldDescriptor;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  @@ -22,56 +26,14 @@
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   
  -import java.lang.reflect.Field;
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Vector;
  -
   /**
    * Helper class for anonymous fields.
    *
    * @author Houar TINE
  - * @version $Id$ 
  + * @version $Id$
    */
   public class AnonymousPersistentFieldHelper
   {
  -    /**
  -     * An iterative version of org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldxxx
  -     * This implementastion is more efficient than recursive version
  -     * If fieldname not exist null is returned
  -     */
  -    public static Field getFieldIterative(final Class c, final String fieldname)
  -    {
  -        Field f = null;
  -        Class clazz = c;
  -        do
  -        {
  -            try
  -            {
  -                f = clazz.getDeclaredField(fieldname);
  -                break;
  -            }
  -            catch (NoSuchFieldException e)
  -            {
  -                // ignore
  -            }
  -            clazz = clazz.getSuperclass();
  -        }
  -        while (clazz != Object.class);
  -        return f;
  -    }
  -
  -    public static Vector getPkFieldNames(final ClassDescriptor cld)
  -    {
  -        FieldDescriptor[] pks = cld.getPkFields();
  -        Vector v = new Vector(pks.length);
  -        for (int i = pks.length - 1; i >= 0; i--)
  -        {
  -            v.add(pks[i].getPersistentField().getName());
  -        }
  -        return v;
  -    }
  -
       public static void computeInheritedPersistentFields(final DescriptorRepository repository)
       {
           Map descriptorTable = repository.getDescriptorTable();
  @@ -83,44 +45,39 @@
               String baseClass = cld.getBaseClass();
               if (null != baseClass)
               {
  -                Vector v = new Vector();
  +                Vector inheritedFields = new Vector();
                   do
                   {
  -                    ClassDescriptor tempCld = repository.getDescriptorFor(baseClass);
  -                    FieldDescriptor[] fields = tempCld.getFieldDescriptions();
  -                    Vector pkFields = getPkFieldNames(tempCld);
  -                    for (int i = fields.length - 1; i >= 0; i--)
  +                    ClassDescriptor baseCld = repository.getDescriptorFor(baseClass);
  +                    FieldDescriptor[] baseFields = baseCld.getFieldDescriptions();
  +                    for (int i = baseFields.length - 1; i >= 0; i--)
                       {
  -                        FieldDescriptor f = fields[i];
  +                        FieldDescriptor f = baseFields[i];
                           if (!(f instanceof AnonymousFieldDescriptor))
                           {
  -                            PersistentField pf = f.getPersistentField();
  -                            if (!pkFields.contains(pf.getName()))
  -                            {
  -                                v.add(f.getPersistentField());
  -                            }
  +                            inheritedFields.add(f.getPersistentField());
                           }
                       }
  -                    Vector ords = tempCld.getObjectReferenceDescriptors();
  +                    Vector ords = baseCld.getObjectReferenceDescriptors();
                       for (int i = ords.size() - 1; i >= 0; i--)
                       {
                           ObjectReferenceDescriptor ord = (ObjectReferenceDescriptor) ords.get(i);
                           PersistentField pf = ord.getPersistentField();
                           if (!(pf instanceof AnonymousPersistentFieldForInheritance))
                           {
  -                            v.add(pf);
  +                            inheritedFields.add(pf);
                           }
                       }
  -                    Vector cds = tempCld.getCollectionDescriptors();
  +                    Vector cds = baseCld.getCollectionDescriptors();
                       for (int i = cds.size() - 1; i >= 0; i--)
                       {
                           CollectionDescriptor cd = (CollectionDescriptor) cds.get(i);
  -                        v.add(cd.getPersistentField());
  +                        inheritedFields.add(cd.getPersistentField());
                       }
  -                    baseClass = tempCld.getBaseClass();
  +                    baseClass = baseCld.getBaseClass();
                   }
                   while ((null != baseClass) && !(baseClass.equals(OBJECT)));
  -                cld.setSuperPersistentFieldDescriptors(v);
  +                cld.setSuperPersistentFieldDescriptors(inheritedFields);
               }
           }
       }
  
  
  
  No                   revision
  No                   revision
  1.17.2.1  +3 -2      db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java
  
  Index: AbstractSequenceManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/AbstractSequenceManager.java,v
  retrieving revision 1.17
  retrieving revision 1.17.2.1
  diff -u -r1.17 -r1.17.2.1
  --- AbstractSequenceManager.java	22 May 2004 10:03:02 -0000	1.17
  +++ AbstractSequenceManager.java	27 Jul 2004 00:33:11 -0000	1.17.2.1
  @@ -117,7 +117,8 @@
           if(seqName == null)
           {
               seqName = SequenceManagerHelper.buildSequenceName(getBrokerForClass(), field,
useAutoNaming());
  -            if(useAutoNaming()) field.setSequenceName(seqName);
  +            // already done in method above
  +            // if(useAutoNaming()) field.setSequenceName(seqName);
           }
           return seqName;
       }
  
  
  
  1.17.2.1  +23 -1     db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java
  
  Index: SequenceManagerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerHelper.java,v
  retrieving revision 1.17
  retrieving revision 1.17.2.1
  diff -u -r1.17 -r1.17.2.1
  --- SequenceManagerHelper.java	22 May 2004 10:03:02 -0000	1.17
  +++ SequenceManagerHelper.java	27 Jul 2004 00:33:11 -0000	1.17.2.1
  @@ -99,6 +99,10 @@
           }
   
           ClassDescriptor cldTargetClass = field.getClassDescriptor();
  +        /*
  +        check for inheritance on multiple table
  +        */
  +        cldTargetClass = findInheritanceRoot(brokerForClass, cldTargetClass);
           Class topLevel = brokerForClass.getTopLevelClass(cldTargetClass.getClassOfObject());
           ClassDescriptor cldTopLevel = brokerForClass.getClassDescriptor(topLevel);
           /**
  @@ -155,6 +159,24 @@
               field.setSequenceName(seqName);
           }
           return seqName;
  +    }
  +
  +    /**
  +     * Returns the root {@link org.apache.ojb.broker.metadata.ClassDescriptor} of the inheriatance
  +     * hierachy of the given descriptor or the descriptor itself if no inheriatance on
multiple table is
  +     * used.
  +     * @see ClassDescriptor#getBaseClass()
  +     * @see ClassDescriptor#getSuperPersistentFieldDescriptors()
  +     */
  +    private static ClassDescriptor findInheritanceRoot(PersistenceBroker broker, ClassDescriptor
cld)
  +    {
  +        ClassDescriptor result = cld;
  +        if(cld.getBaseClass() != null)
  +        {
  +            ClassDescriptor baseCld = broker.getDescriptorRepository().getDescriptorFor(cld.getBaseClass());
  +            result = findInheritanceRoot(broker, baseCld);
  +        }
  +        return result;
       }
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.4.2.1   +10 -0     db-ojb/src/java/org/apache/ojb/broker/util/WrappedConnection.java
  
  Index: WrappedConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/WrappedConnection.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- WrappedConnection.java	4 Apr 2004 23:53:37 -0000	1.4
  +++ WrappedConnection.java	27 Jul 2004 00:33:12 -0000	1.4.2.1
  @@ -24,6 +24,9 @@
   import java.sql.Statement;
   import java.util.Map;
   
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
  +
   /**
    * Wrapper class for connections.
    * Simplified version of {@link org.apache.commons.dbcp.DelegatingConnection}
  @@ -112,6 +115,13 @@
           {
               ((WrappedConnection) _conn).passivateConnection();
           }
  +    }
  +
  +    public String toString()
  +    {
  +        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
  +                .append("wrapped connection", (_conn != null ? _conn.toString() : null))
  +                .toString();
       }
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.36.2.1  +28 -4     db-ojb/src/java/org/apache/ojb/broker/Identity.java
  
  Index: Identity.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/Identity.java,v
  retrieving revision 1.36
  retrieving revision 1.36.2.1
  diff -u -r1.36 -r1.36.2.1
  --- Identity.java	9 Apr 2004 13:22:30 -0000	1.36
  +++ Identity.java	27 Jul 2004 00:33:12 -0000	1.36.2.1
  @@ -33,9 +33,33 @@
   import java.util.zip.GZIPOutputStream;
   
   /**
  - * represents the identity of an object.
  - * identity (it's primary keys) must be unique accross extents !
  - *
  + * Represents the identity of an object.
  + * <br/>
  + * It's composed of:
  + * <ul>
  + * <li>
  + * class of the real object
  + * </li>
  + * <li>
  + * top-level class of the real object (could be an abstract class or interface or the
  + * class of the object itself), used to make an object unique across extent classes
  + * </li>
  + * <li>
  + * an array of all primary key value objects
  + * </li>
  + * </ul>
  + * <p>
  + * If in the metadata of an persistent capable object class the attribute <em>autoincrement</em>
  + * is set true, new primary key values will be automatic assigned to the given object passed
as
  + * constructor argument.
  + * </p>
  + * <p>
  + * NOTE: An <em>Identity</em> object must be unique
  + * accross extents. Means all objects with the same top-level class need unique
  + * PK values.
  + * </p>
  + * @see org.apache.ojb.broker.IdentityFactory
  +
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  
  
  
  1.30.2.1  +6 -2      db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java
  
  Index: PersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/PersistenceBroker.java,v
  retrieving revision 1.30
  retrieving revision 1.30.2.1
  diff -u -r1.30 -r1.30.2.1
  --- PersistenceBroker.java	4 Apr 2004 23:53:30 -0000	1.30
  +++ PersistenceBroker.java	27 Jul 2004 00:33:12 -0000	1.30.2.1
  @@ -88,7 +88,11 @@
        */
       public ObjectCache serviceObjectCache();
   
  -
  +    /**
  +     * Return the {@link IdentityFactory} instance associated with this broker.
  +     * @return service to create {@link Identity} objects.
  +     */
  +    public IdentityFactory serviceIdentity();
   
   
       // *************************************************************************
  
  
  
  No                   revision
  No                   revision
  1.32.2.1  +9 -13     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.32
  retrieving revision 1.32.2.1
  diff -u -r1.32 -r1.32.2.1
  --- ObjectEnvelope.java	9 Apr 2004 13:22:30 -0000	1.32
  +++ ObjectEnvelope.java	27 Jul 2004 00:33:12 -0000	1.32.2.1
  @@ -250,7 +250,6 @@
            * MBAIRD
            * 3. now let's register the collection descriptors
            * How do we handle proxied collections and collections of proxies
  -         * @see org.apache.ojb.odmg.OneToManyTest
            */
           Iterator collections = mif.getCollectionDescriptors().iterator();
           CollectionDescriptor collectionDescriptor = null;
  @@ -406,20 +405,17 @@
        */
       public boolean hasChanged()
       {
  -        if(hasChanged == null)
  +        Map currentImage = null;
  +        try
           {
  -            Map currentImage = null;
  -            try
  -            {
  -                currentImage = getMap();
  -            }
  -            catch(Exception e)
  -            {
  -                LoggerFactory.getDefaultLogger().warn("Could not verify object changes,
return hasChanged 'true'", e);
  -            }
  -
  -            hasChanged = (beforeImage != null && beforeImage.equals(currentImage)
? Boolean.FALSE : Boolean.TRUE);
  +            currentImage = getMap();
  +        }
  +        catch(Exception e)
  +        {
  +            LoggerFactory.getDefaultLogger().warn("Could not verify object changes, return
hasChanged 'true'", e);
           }
  +        hasChanged = (beforeImage != null && beforeImage.equals(currentImage) ?
Boolean.FALSE : Boolean.TRUE);
  +
           return hasChanged.booleanValue();
       }
   
  
  
  

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