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/kit SimpleKit.java
Date Fri, 11 Jul 2003 19:30:26 GMT
olegnitz    2003/07/11 12:30:26

  Modified:    src/java/org/apache/ojb/otm/core ConcreteEditingContext.java
               src/java/org/apache/ojb/otm/kit SimpleKit.java
  Log:
  Batch INSERTs now are used only for classes without bidirectional associations
  
  Revision  Changes    Path
  1.19      +86 -1     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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ConcreteEditingContext.java	11 Jul 2003 16:38:32 -0000	1.18
  +++ ConcreteEditingContext.java	11 Jul 2003 19:30:26 -0000	1.19
  @@ -68,11 +68,13 @@
   import java.util.Comparator;
   import java.util.Iterator;
   import java.util.HashMap;
  +import java.util.HashSet;
   import java.util.Date;
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.OJBRuntimeException;
  +import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.accesslayer.CollectionProxy;
  @@ -105,6 +107,15 @@
   public class ConcreteEditingContext
           implements EditingContext, MaterializationListener
   {
  +    // for hasBidirectionalAssociation method
  +    // Maps PBKeys to the sets of classes with/without
  +    // bidirectional associations
  +    private static HashMap _withBidirAsscMap = new HashMap();
  +    private static HashMap _withoutBidirAsscMap = new HashMap();
  +
  +    private HashSet _withBidirAssc;
  +    private HashSet _withoutBidirAssc;
  +
       private HashMap _objects;
       private ArrayList _order;
       private Transaction _tx;
  @@ -118,12 +129,27 @@
   
       public ConcreteEditingContext(Transaction tx, PersistenceBroker pb)
       {
  +        PBKey pbkey;
  +
           _tx = tx;
           _pb = pb;
           _objects = new HashMap();
           _order = new ArrayList();
           _original = new HashMap();
           _checkpointed = _original;
  +        pbkey = _pb.getPBKey();
  +        _withoutBidirAssc = (HashSet) _withoutBidirAsscMap.get(pbkey);
  +        if (_withoutBidirAssc != null)
  +        {
  +            _withBidirAssc = (HashSet) _withBidirAsscMap.get(pbkey);
  +        }
  +        else
  +        {
  +            _withoutBidirAssc = new HashSet();
  +            _withoutBidirAsscMap.put(pbkey, _withoutBidirAssc);
  +            _withBidirAssc = new HashSet();
  +            _withBidirAsscMap.put(pbkey, _withBidirAssc);
  +        }
       }
   
       //////////////////////////////////////////
  @@ -193,7 +219,8 @@
                   if (origObj == null)
                   {
                       entry.state = State.PERSISTENT_NEW;
  -                    if (kit.isEagerInsert(newObj))
  +                    if (kit.isEagerInsert(newObj)
  +                            || hasBidirectionalAssociation(newObj.getClass()))
                       {
                           _pb.store(newObj, entry.state);
                           entry.state = State.PERSISTENT_CLEAN;
  @@ -761,6 +788,64 @@
               PersistentField f = rds.getPersistentField();
               f.set(obj, fields[1 + fieldDescs.length + i]);
           }
  +    }
  +
  +    /**
  +     * Does the given class has bidirectional assiciation
  +     * with some other class?
  +     */
  +    private boolean hasBidirectionalAssociation(Class clazz)
  +    {
  +        ClassDescriptor cdesc;
  +        Collection refs;
  +        boolean hasBidirAssc;
  +
  +        if (_withoutBidirAssc.contains(clazz))
  +        {
  +            return false;
  +        }
  +
  +        if (_withBidirAssc.contains(clazz))
  +        {
  +            return true;
  +        }
  +
  +        // first time we meet this class, let's look at metadata
  +        cdesc = _pb.getClassDescriptor(clazz);
  +        refs = cdesc.getObjectReferenceDescriptors();
  +        hasBidirAssc = false;
  +        REFS_CYCLE:
  +        for (Iterator it = refs.iterator(); it.hasNext(); )
  +        {
  +            ObjectReferenceDescriptor ord;
  +            ClassDescriptor relCDesc;
  +            Collection relRefs;
  +
  +            ord = (ObjectReferenceDescriptor) it.next();
  +            relCDesc = _pb.getClassDescriptor(ord.getItemClass());
  +            relRefs = relCDesc.getObjectReferenceDescriptors();
  +            for (Iterator relIt = relRefs.iterator(); relIt.hasNext(); )
  +            {
  +                ObjectReferenceDescriptor relOrd;
  +
  +                relOrd = (ObjectReferenceDescriptor) relIt.next();
  +                if (relOrd.getItemClass().equals(clazz))
  +                {
  +                    hasBidirAssc = true;
  +                    break REFS_CYCLE;
  +                }
  +            }
  +        }
  +        if (hasBidirAssc)
  +        {
  +            _withBidirAssc.add(clazz);
  +        }
  +        else
  +        {
  +            _withoutBidirAssc.add(clazz);
  +        }
  +
  +        return hasBidirAssc;
       }
   
   
  
  
  
  1.12      +1 -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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SimpleKit.java	11 Jul 2003 16:38:32 -0000	1.11
  +++ SimpleKit.java	11 Jul 2003 19:30:26 -0000	1.12
  @@ -197,6 +197,6 @@
        **/
       public boolean isEagerInsert(Object obj)
       {
  -        return true;
  +        return false; 
       }
   }
  
  
  

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