User: dsundstrom
  Date: 02/01/15 14:27:34

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc
                        JDBCStoreEntityCommand.java
  Log:
  Converted from field arrays to field lists.
  
  Revision  Changes    Path
  1.11      +22 -19    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreEntityCommand.java
  
  Index: JDBCStoreEntityCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStoreEntityCommand.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JDBCStoreEntityCommand.java       2002/01/05 12:08:51     1.10
  +++ JDBCStoreEntityCommand.java       2002/01/15 22:27:34     1.11
  @@ -9,10 +9,12 @@
   
   import java.sql.Connection;
   import java.sql.PreparedStatement;
  +import java.util.Iterator;
  +import java.util.List;
   import javax.ejb.EJBException;
   
   import org.jboss.ejb.EntityEnterpriseContext;
  -import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge;
  +import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCFieldBridge;
   import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge;
   import org.jboss.logging.Logger;
   
  @@ -27,7 +29,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Sebastien Alborini</a>
  - * @version $Revision: 1.10 $
  + * @version $Revision: 1.11 $
    */
   public class JDBCStoreEntityCommand {
      private JDBCStoreManager manager;
  @@ -46,23 +48,20 @@
      }
      
      public void execute(EntityEnterpriseContext ctx) {
  -      JDBCCMPFieldBridge[] dirtyFields = 
  -            (JDBCCMPFieldBridge[])entity.getDirtyFields(ctx);
  -
  -      boolean debug = log.isDebugEnabled();
  -      if(dirtyFields.length == 0) {
  -         if (debug)
  -            log.debug("Store command NOT executed. Entity is not dirty: pk=" +
  +      List dirtyFields = entity.getDirtyFields(ctx);
  +         
  +      if(dirtyFields.isEmpty()) {
  +         log.debug("Store command NOT executed. Entity is not dirty: pk=" + 
                  ctx.getId());
            return;
         }
   
         // generate sql
  -      StringBuffer sql = new StringBuffer();
  +      StringBuffer sql = new StringBuffer(); 
         sql.append("UPDATE ").append(entity.getTableName());
         sql.append(" SET ").append(SQLUtil.getSetClause(dirtyFields));
         sql.append(" WHERE ").append(
  -            SQLUtil.getWhereClause(entity.getJDBCPrimaryKeyFields()));
  +            SQLUtil.getWhereClause(entity.getPrimaryKeyFields()));
   
         Connection con = null;
         PreparedStatement ps = null;
  @@ -70,19 +69,23 @@
         try {
            // get the connection
            con = entity.getDataSource().getConnection();
  -
  +         
            // create the statement
  -         if (debug)
  -            log.debug("Executing SQL: " + sql);
  +         log.debug("Executing SQL: " + sql);
            ps = con.prepareStatement(sql.toString());
  -
  +         
            // set the parameters
            int index = 1;
  -         index = entity.setInstanceParameters(ps, index, ctx, dirtyFields);
  +         for(Iterator iter = dirtyFields.iterator(); iter.hasNext(); ) {
  +            JDBCFieldBridge field = (JDBCFieldBridge)iter.next();
  +            index = field.setInstanceParameters(ps, index, ctx);
  +         }
            index = entity.setPrimaryKeyParameters(ps, index, ctx.getId());
   
            // execute statement
            rowsAffected = ps.executeUpdate();
  +      } catch(EJBException e) {
  +         throw e;
         } catch(Exception e) {
            throw new EJBException("Store failed", e);
         } finally {
  @@ -96,12 +99,12 @@
                  "affected row: rowsAffected=" + rowsAffected +
                  "id=" + ctx.getId());
         }
  -      if (debug)
  -         log.debug("Create: Rows affected = " + rowsAffected);
  +      log.debug("Create: Rows affected = " + rowsAffected);
   
         // Mark the inserted fields as clean.
  -      for(int i=0; i<dirtyFields.length; i++) {
  -         dirtyFields[i].setClean(ctx);
  +      for(Iterator iter = dirtyFields.iterator(); iter.hasNext(); ) {
  +         JDBCFieldBridge field = (JDBCFieldBridge)iter.next();
  +         field.setClean(ctx);
         }
      }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to