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/broker/core PersistenceBrokerImpl.java
Date Sun, 15 Feb 2004 22:17:09 GMT
olegnitz    2004/02/15 14:17:09

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
  Log:
  Improved algorithm of choice of INSERT or UPDATE during store() so that now
  it works with batch mode correctly, namely, it doesn't try to UPDATE object
  that has been deleted in the current transaction.
  
  Revision  Changes    Path
  1.67      +38 -2     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.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- PersistenceBrokerImpl.java	13 Feb 2004 12:58:51 -0000	1.66
  +++ PersistenceBrokerImpl.java	15 Feb 2004 22:17:09 -0000	1.67
  @@ -58,8 +58,10 @@
   import java.util.Collection;
   import java.util.Collections;
   import java.util.Enumeration;
  +import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Set;
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
  @@ -185,6 +187,19 @@
       */
       private List markedForDelete = new IdentityArrayList();
   
  +    /**
  +     * The set of identities of all deleted objects during current transaction
  +     */
  +    /*
  +    olegnitz: this is the only way I know that solves the following problem
  +    of batch mode: if one does store() after delete() for the same OID,
  +    the broker checks whether the given OID exists in database to decide
  +    which action to do: INSERT or UPDATE. If the preceding DELETE statement is
  +    still in batch (not executed yet), then the OID exists in database so
  +    the broker does UPDATE. Due the the following set of deleted OIDs
  +    the broker will know that it should do INSERT.
  +    */
  +    private Set deletedDuringTransaction = new HashSet();
   
       /**
        * Constructor used by {@link PersistenceBrokerFactoryIF} implementation.
  @@ -486,7 +501,10 @@
               // 2. delete object from directly mapped table
               dbAccess.executeDelete(cld, obj); // use obj not oid to delete, BRJ
   
  -            // 3. delete dependend upon objects last to avoid FK violations
  +            // 3. Add OID to the set of deleted objects
  +            deletedDuringTransaction.add(oid);
  +
  +            // 4. delete dependend upon objects last to avoid FK violations
               if (cld.getObjectReferenceDescriptors().size() > 0)
               {
                   deleteReferences(obj, cld.getObjectReferenceDescriptors());
  @@ -687,6 +705,18 @@
               */
               boolean doInsert = serviceBrokerHelper().hasNullPKField(cld, obj);
               Identity oid = new Identity(obj, this, cld);
  +
  +            /*
  +            if the object has been deleted during this transaction,
  +            then we must insert it
  +            */
  +            boolean shouldRemoveFromDeleted = false;
  +            if (!doInsert)
  +            {
  +                doInsert = deletedDuringTransaction.contains(oid);
  +                shouldRemoveFromDeleted = true;
  +            }
  +
               /*
               if PK values are set, lookup cache or db to see whether object
               needs insert or update
  @@ -699,6 +729,11 @@
               // now store it:
               store(obj, oid, cld, doInsert);
   
  +            if (shouldRemoveFromDeleted)
  +            {
  +                deletedDuringTransaction.remove(oid);
  +            }
  +
               // let the connection manager to execute batch
               connectionManager.executeBatchIfNecessary();
           }
  @@ -1728,6 +1763,7 @@
       {
           nowStoring.clear();
           objectCache.localClear();
  +        deletedDuringTransaction.clear();
       }
   
       /**
  
  
  

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