db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/odmg ObjectEnvelopeTable.java
Date Thu, 26 Dec 2002 19:33:00 GMT
arminw      2002/12/26 11:33:00

  Modified:    src/java/org/apache/ojb/odmg ObjectEnvelopeTable.java
  Log:
  adapt Identity usage, minor other changes
  
  Revision  Changes    Path
  1.12      +26 -35    jakarta-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java
  
  Index: ObjectEnvelopeTable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/odmg/ObjectEnvelopeTable.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ObjectEnvelopeTable.java	24 Dec 2002 13:42:49 -0000	1.11
  +++ ObjectEnvelopeTable.java	26 Dec 2002 19:33:00 -0000	1.12
  @@ -66,6 +66,7 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
   import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.accesslayer.ConnectionManagerIF;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
  @@ -73,6 +74,8 @@
   import org.apache.ojb.broker.util.ArrayIterator;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.commons.lang.builder.ToStringBuilder;
  +import org.apache.commons.lang.builder.ToStringStyle;
   import org.odmg.Transaction;
   import org.odmg.TransactionAbortedException;
   
  @@ -102,7 +105,7 @@
        * in the order they were added. If an ObjectEnvelope is added twice, only
        * the the second addition is ignored.
        */
  -    private List mvOrderOfIds = new ArrayList();
  +    private ArrayList mvOrderOfIds = new ArrayList();
   
       public void close()
       {
  @@ -163,25 +166,20 @@
   
               // 0. turn on the batch mode
               connMan.setBatchMode(true);
  +            // 1. upgrade locks
   
  -            // Using iter.next() directly in the get() call causes a Concurrent Modification
  -            // Exception when the process of commiting envolves object with complex relations
  -            // some of which may refer to the same object through different relational
paths.
  -            // Iteration a temporary vector instead seams to solve the problem
  -            Vector temp = new Vector();
  -            Iterator iter = mvOrderOfIds.iterator();
  +            /* Using iter.next() directly in the get() call causes a Concurrent Modification
  +             Exception when the process of commiting envolves object with complex relations
  +             some of which may refer to the same object through different relational paths.
  +             Iteration a temporary vector instead seams to solve the problem
  +             arminw:
  +             clone the list should solve the problem ditto??
  +             */
  +            Iterator iter = ((ArrayList) mvOrderOfIds.clone()).iterator();
               while (iter.hasNext())
               {
  -                temp.add(iter.next());
  -            }
  -
  -            // 1. upgrade locks
  -            for (int i = 0; i < temp.size(); i++)
  -            {
  -                ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(temp.get(i));
  -
  -                if (log.isDebugEnabled())
  -                    log.debug("commit: " + mod);
  +                ObjectEnvelope mod = (ObjectEnvelope) mhtObjectEnvelopes.get(iter.next());
  +                if (log.isDebugEnabled()) log.debug("commit: " + mod);
                   // if the Object has been modified by transaction, mark object as dirty
                   if (mod.hasChanged())
                   {
  @@ -256,7 +254,7 @@
           }
           else
           {
  -            id = new Identity(pKey);
  +            id = new Identity(pKey, transaction.getBroker());
           }
           mhtObjectEnvelopes.remove(id);
           mvOrderOfIds.remove(id);
  @@ -290,7 +288,7 @@
        */
       public ObjectEnvelope get(Object pKey)
       {
  -        Identity id = new Identity(pKey);
  +        Identity id = new Identity(pKey, transaction.getBroker());
           //Integer keyInteger = new Integer(System.identityHashCode(key));
           ObjectEnvelope result = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
           if (result == null)
  @@ -319,24 +317,17 @@
       }
   
       /**
  -     *
  -     * Insert the method's description here.
  -     *
  -     * Creation date: (11.02.2001 12:45:08)
  -     *
  -     * @return java.lang.String
  -     *
  +     * Returns a String representation of this object
        */
       public String toString()
       {
  -        StringBuffer buf = new StringBuffer();
  -        buf.append("### ObjectEnvelopeTable dump:\n");
  -        java.util.Enumeration enum = elements();
  +        ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
  +        buf.append("### ObjectEnvelopeTable dump:");
  +        Enumeration enum = elements();
           while (enum.hasMoreElements())
           {
               ObjectEnvelope mod = (ObjectEnvelope) enum.nextElement();
               buf.append(mod.toString());
  -            buf.append("\n");
           }
           return buf.toString();
       }
  @@ -346,7 +337,7 @@
        */
       public boolean contains(Object pKey)
       {
  -        Identity id = new Identity(pKey);
  +        Identity id = new Identity(pKey, transaction.getBroker());
           //Integer keyInteger = new Integer(System.identityHashCode(key));
           return mhtObjectEnvelopes.containsKey(id);
       }
  @@ -356,7 +347,7 @@
        */
       private void reorder() throws IllegalAccessException
       {
  -        List vNewVector = new ArrayList(mvOrderOfIds.size());
  +        ArrayList vNewVector = new ArrayList(mvOrderOfIds.size());
           Map htNewHashtable = new HashMap((int) (mvOrderOfIds.size() * 1.1), 1f);
           Map htOldVectorPosition = new HashMap((int) (mvOrderOfIds.size() * 1.1), 1f);
           for (int i = 0; i < mvOrderOfIds.size(); i++)
  @@ -446,7 +437,7 @@
                   }
                   else
                   {
  -                    throw new RuntimeException(
  +                    throw new OJBRuntimeException(
                           col.getClass()
                               + " can not be managed by OJB, use Array, Collection or ManageableCollection
instead !");
                   }
  @@ -456,7 +447,7 @@
                       // Now we have to retrieve the ObjectEnvelope representing this
                       // Object from the hashtable, remove it from the vector and reorder
                       // the retrieved ObjectEnvelope.
  -                    Identity id = new Identity(colIterator.next());
  +                    Identity id = new Identity(colIterator.next(), transaction.getBroker());
                       ObjectEnvelope oe = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
                       if (oe != null)
                       {
  @@ -492,7 +483,7 @@
               Object refObj = rds.getPersistentField().get(objectToReorder.getObject());
               if (refObj != null)
               {
  -                Identity id = new Identity(refObj);
  +                Identity id = new Identity(refObj, transaction.getBroker());
                   ObjectEnvelope oe = (ObjectEnvelope) mhtObjectEnvelopes.get(id);
                   if (oe != null)
                   {
  
  
  

Mime
View raw message