db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer JdbcAccessImpl.java
Date Fri, 23 Apr 2004 18:36:21 GMT
brj         2004/04/23 11:36:20

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        JdbcAccessImpl.java
  Log:
  executeUpdate: restore old locking values in case of exception
  
  Revision  Changes    Path
  1.22      +39 -6     db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
  
  Index: JdbcAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- JdbcAccessImpl.java	22 Apr 2004 19:12:21 -0000	1.21
  +++ JdbcAccessImpl.java	23 Apr 2004 18:36:20 -0000	1.22
  @@ -34,6 +34,7 @@
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.ProcedureDescriptor;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -102,7 +103,7 @@
               }
   
               // Harvest any return values.
  -            this.harvestReturnValues(cld.getDeleteProcedure(), obj, stmt);
  +            harvestReturnValues(cld.getDeleteProcedure(), obj, stmt);
           }
           catch (OptimisticLockException e)
           {
  @@ -197,7 +198,7 @@
               stmt.executeUpdate();
   
               // Harvest any return values.
  -            this.harvestReturnValues(cld.getInsertProcedure(), obj, stmt);
  +            harvestReturnValues(cld.getInsertProcedure(), obj, stmt);
           }
           catch (PersistenceBrokerException e)
           {
  @@ -460,8 +461,14 @@
           {
               return;
           }
  +        
  +        // BRJ: preserve current locking values
  +        // locking values will be restored in case of exception
  +        ValueContainer[] oldLockingValues;
  +        oldLockingValues = cld.getCurrentLockingValues(obj);
  +
           try
  -        {
  +        {           
               stmt = broker.serviceStatementManager().getUpdateStatement(cld);
               if (stmt == null)
               {
  @@ -479,7 +486,7 @@
               }
   
               // Harvest any return values.
  -            this.harvestReturnValues(cld.getUpdateProcedure(), obj, stmt);
  +            harvestReturnValues(cld.getUpdateProcedure(), obj, stmt);
           }
           catch (OptimisticLockException e)
           {
  @@ -492,6 +499,9 @@
           }
           catch (PersistenceBrokerException e)
           {
  +            // BRJ: restore old locking values
  +            setLockingValues(cld, obj, oldLockingValues);
  +
               logger.error(
                   "PersistenceBrokerException during the execution of the update: " + e.getMessage(),
                   e);
  @@ -499,12 +509,16 @@
           }
           catch (SQLException e)
           {
  +            // BRJ: restore old locking values
  +            setLockingValues(cld, obj, oldLockingValues);
  +
               logger.error(
                   "SQLException during the execution of the update (for a "
                       + cld.getClassOfObject().getName()
                       + "): "
                       + e.getMessage(),
                   e);
  +            
               if (SQL_STATE_KEY_VIOLATED.equals(e.getSQLState()))
               {
                   throw new KeyConstraintViolatedException(e);
  @@ -512,7 +526,7 @@
               throw new PersistenceBrokerSQLException(e);
           }
           finally
  -        {
  +        {           
               broker.serviceStatementManager().closeResources(stmt, null);
           }
       }
  @@ -577,6 +591,25 @@
           }
       }
   
  +    /**
  +     * Set the locking values
  +     * @param cld
  +     * @param obj
  +     * @param oldLockingValues
  +     */
  +    private void setLockingValues(ClassDescriptor cld, Object obj, ValueContainer[] oldLockingValues)
  +    {
  +        FieldDescriptor fields[] = cld.getLockingFields();
  +        
  +        for (int i=0; i<fields.length; i++)
  +        {
  +            PersistentField field = fields[i].getPersistentField();
  +            Object lockVal = oldLockingValues[i].getValue();
  +            
  +            field.set(obj, lockVal);
  +        }
  +    }
  +    
       /**
        * Harvest any values that may have been returned during the execution
        * of a procedure.
  
  
  

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