User: forder  
  Date: 00/08/20 18:23:59

  Modified:    src/main/org/jboss/ejb/plugins/jaws/jdbc
                        JDBCBeanExistsCommand.java JDBCCommand.java
                        JDBCCommandFactory.java
                        JDBCCreateEntityCommand.java
                        JDBCDestroyCommand.java JDBCFinderCommand.java
                        JDBCInitCommand.java JDBCLoadEntityCommand.java
                        JDBCRemoveEntityCommand.java
                        JDBCStoreEntityCommand.java JDBCUpdateCommand.java
  Log:
  Primary key setting factored out.
  Getting values from results factored out, and tracing added.
  Result type tweaked if a request for an integer gives a BigDecimal.
  Messages improved for situations when table creation or drop fails.
  Debug flag moved from factory to JDBCCommand.
  Some doc comments added.
  
  Revision  Changes    Path
  1.2       +1 -29     
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCBeanExistsCommand.java
  
  Index: JDBCBeanExistsCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCBeanExistsCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCBeanExistsCommand.java        2000/08/06 02:03:49     1.1
  +++ JDBCBeanExistsCommand.java        2000/08/21 01:23:57     1.2
  @@ -7,16 +7,11 @@
   
   package org.jboss.ejb.plugins.jaws.jdbc;
   
  -import java.util.Iterator;
  -
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   
   import org.jboss.ejb.EntityEnterpriseContext;
  -import org.jboss.ejb.plugins.jaws.MetaInfo;
  -import org.jboss.ejb.plugins.jaws.PkFieldInfo;
  -import org.jboss.logging.Log;
   
   /**
    * JDBCBeanExistsCommand
  @@ -24,7 +19,7 @@
    * @see <related>
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCBeanExistsCommand extends JDBCQueryCommand
   {
  @@ -72,30 +67,7 @@
      protected void setParameters(PreparedStatement stmt) 
         throws Exception
      {
  -      // Primary key in WHERE-clause
  -      Iterator it = metaInfo.getPkFieldInfos();
  -      int i = 1;   // parameter index
  -      
  -      if (metaInfo.hasCompositeKey())
  -      {
  -         // Compound key
  -         while (it.hasNext())
  -         {
  -            PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  -            int jdbcType = pkFieldInfo.getJDBCType();
  -            Object value = getPkFieldValue(idArgument, pkFieldInfo);
  -            
  -            // Set this field of the key
  -            setParameter(stmt, i++, jdbcType, value);
  -         }
  -      } else
  -      {
  -         // We have a Field key
  -         // So just set that field
  -         PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  -         int jdbcType = pkFieldInfo.getJDBCType();
  -         setParameter(stmt, i, jdbcType, idArgument);
  -      }
  +      setPrimaryKeyParameters(stmt, 1, idArgument);
      }
      
      protected void handleResult(ResultSet rs) throws Exception
  
  
  
  1.3       +155 -8    jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.java
  
  Index: JDBCCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommand.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JDBCCommand.java  2000/08/18 03:21:01     1.2
  +++ JDBCCommand.java  2000/08/21 01:23:58     1.3
  @@ -16,6 +16,7 @@
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.PreparedStatement;
  +import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Types;
   
  @@ -34,16 +35,14 @@
   import org.jboss.logging.Log;
   import org.jboss.logging.Logger;
   
  -
   /**
    * Abstract superclass for all JAWS Commands that use JDBC directly.
    * Provides a Template Method for jdbcExecute(), default implementations
    * for some of the methods called by this template, and a bunch of
    * utility methods that database commands may need to call.
    *
  - * @see <related>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public abstract class JDBCCommand
   {
  @@ -57,8 +56,21 @@
      private String sql;
      private static Map jdbcTypeNames;
      
  +   /**
  +    * Gives compile-time control of tracing.
  +    */
  +   public static boolean debug = true;
  +   
      // Constructors --------------------------------------------------
      
  +   /**
  +    * Construct a JDBCCommand with given factory and name.
  +    *
  +    * @param factory the factory which was used to create this JDBCCommand, 
  +    *  which is also used as a common repository, shared by all an
  +    *  entity's Commands. 
  +    * @param name the name to be used when tracing execution.
  +    */
      protected JDBCCommand(JDBCCommandFactory factory, String name)
      {
         this.factory = factory;
  @@ -83,7 +95,7 @@
         {
            con = getConnection();
            String theSQL = getSQL();
  -         if (factory.debug)
  +         if (debug)
            {
               log.debug(name + " command executing: " + theSQL);
            }
  @@ -117,10 +129,12 @@
      
      /**
       * Used to set static SQL in subclass constructors.
  +    *
  +    * @param sql the static SQL to be used by this Command.
       */
      protected void setSQL(String sql)
      {
  -      if (factory.debug)
  +      if (debug)
         {
            log.debug(name + " SQL: " + sql);
         }
  @@ -128,11 +142,16 @@
      }
      
      /**
  -    * Default implementation returns <code>sql</code> field value.
  +    * Gets the SQL to be used in the PreparedStatement.
  +    * The default implementation returns the <code>sql</code> field value.
       * This is appropriate in all cases where static SQL can be
       * constructed in the Command constructor.
       * Override if dynamically-generated SQL, based on the arguments
       * given to execute(), is needed.
  +    *
  +    * @return the SQL to use in the PreparedStatement.
  +    * @throws Exception if an attempt to generate dynamic SQL results in 
  +    *  an Exception.
       */
      protected String getSQL() throws Exception
      {
  @@ -142,27 +161,43 @@
      /**
       * Default implementation does nothing.
       * Override if parameters need to be set.
  +    *
  +    * @param stmt the PreparedStatement which will be executed by this Command.
  +    * @throws Exception if the parameter setting code throws an Exception.
       */
      protected void setParameters(PreparedStatement stmt) throws Exception
      {
      }
      
      /**
  -    * Execute the PreparedStatement and handle result of successful execution.
  +    * Executes the PreparedStatement and handle result of successful execution.
       * This is implemented in subclasses for queries and updates.
  +    *
  +    * @param stmt the PreparedStatement to execute.
  +    * @throws Exception if execution or result handling fails.
       */
      protected abstract void executeStatementAndHandleResult(
         PreparedStatement stmt) throws Exception;
      
      // ---------- Utility methods for use in subclasses ----------
      
  +   /**
  +    * Sets a parameter in this Command's PreparedStatement.
  +    * Handles null values, and provides tracing.
  +    *
  +    * @param stmt the PreparedStatement whose parameter needs to be set.
  +    * @param idx the index (1-based) of the parameter to be set.
  +    * @param jdbcType the JDBC type of the parameter.
  +    * @param value the value which the parameter is to be set to.
  +    * @throws SQLException if parameter setting fails.
  +    */
      protected void setParameter(PreparedStatement stmt,
                                  int idx,
                                  int jdbcType,
                                  Object value)
         throws SQLException
      {
  -      if (factory.debug)
  +      if (debug)
         {
            log.debug("Set parameter: idx=" + idx +
                      ", jdbcType=" + getJDBCTypeName(jdbcType) +
  @@ -179,6 +214,59 @@
         }
      }
      
  +   /**
  +    * Sets the PreparedStatement parameters for a primary key
  +    * in a WHERE clause.
  +    *
  +    * @param stmt the PreparedStatement
  +    * @param parameterIndex the index (1-based) of the first parameter to set
  +    * in the PreparedStatement
  +    * @param id the entity's ID
  +    * @return the index of the next unset parameter
  +    * @throws SQLException if parameter setting fails
  +    * @throws IllegalAccessException if accessing a field in the PK class fails 
  +    */
  +   protected int setPrimaryKeyParameters(PreparedStatement stmt,
  +                                         int parameterIndex,
  +                                         Object id)
  +      throws IllegalAccessException, SQLException
  +   {
  +      Iterator it = metaInfo.getPkFieldInfos();
  +      
  +      if (metaInfo.hasCompositeKey())
  +      {
  +         while (it.hasNext())
  +         {
  +            PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  +            int jdbcType = pkFieldInfo.getJDBCType();
  +            Object value = getPkFieldValue(id, pkFieldInfo);
  +            setParameter(stmt, parameterIndex++, jdbcType, value);
  +         }
  +      } else
  +      {
  +         PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  +         int jdbcType = pkFieldInfo.getJDBCType();
  +         setParameter(stmt, parameterIndex++, jdbcType, id);
  +      }
  +      
  +      return parameterIndex;
  +   }
  +   
  +   /**
  +    * Sets parameter(s) representing a foreign key in this 
  +    * Command's PreparedStatement.
  +    * TODO: (JF) tighten up the typing of the value parameter.
  +    *
  +    * @param stmt the PreparedStatement whose parameters need to be set.
  +    * @param idx the index (1-based) of the first parameter to be set.
  +    * @param fieldInfo the CMP meta-info for the field containing the 
  +    *  entity reference.
  +    * @param value the entity (EJBObject) referred to by the reference
  +    *  (may be null).
  +    * @return the index of the next unset parameter.
  +    * @throws SQLException if the access to the referred-to entity's primary
  +    *  key fails, or if parameter setting fails.
  +    */
      protected int setForeignKey(PreparedStatement stmt,
                                int idx,
                                CMPFieldInfo fieldInfo,
  @@ -226,6 +314,45 @@
         }
      }
      
  +   /**
  +    * Used for all retrieval of results from <code>ResultSet</code>s.
  +    * Implements tracing, and allows some tweaking of returned types.
  +    *
  +    * @param rs the <code>ResultSet</code> from which a result is being retrieved.
  +    * @param idx index of the result column.
  +    * @param jdbcType the JDBC type which this result is expected to be 
  +    *        compatible with.
  +    */
  +   protected Object getResultObject(ResultSet rs, int idx, int jdbcType)
  +      throws SQLException
  +   {
  +      Object result = rs.getObject(idx);
  +      
  +      if (debug) {
  +         log.debug("Got result: idx=" + idx +
  +                   ", value=" + result +
  +                   ", class=" + result.getClass().getName() +
  +                   ", JDBCtype=" + getJDBCTypeName(jdbcType));
  +      }
  +      
  +      // Trial result transformation - BigDecimal to Integer
  +      if ((result instanceof java.math.BigDecimal) && (jdbcType == Types.INTEGER))
  +      {
  +         log.debug("*** Transforming BigDecimal to Integer ***");
  +         
  +         result = new Integer(((java.math.BigDecimal)result).intValue());
  +      }
  +      
  +      return result;
  +   }
  +   
  +   /**
  +    * Gets the integer JDBC type code corresponding to the given name.
  +    *
  +    * @param name the JDBC type name.
  +    * @return the JDBC type code.
  +    * @see Types
  +    */
      protected final int getJDBCType(String name)
      {
         try
  @@ -240,6 +367,13 @@
         }
      }
      
  +   /**
  +    * Gets the JDBC type name corresponding to the given type code.
  +    *
  +    * @param jdbcType the integer JDBC type code.
  +    * @return the JDBC type name.
  +    * @see Types
  +    */
      protected final String getJDBCTypeName(int jdbcType)
      {
         if (jdbcTypeNames == null)
  @@ -250,6 +384,12 @@
         return (String)jdbcTypeNames.get(new Integer(jdbcType));
      }
      
  +   /**
  +    * Returns the comma-delimited list of primary key column names
  +    * for this entity.
  +    *
  +    * return comma-delimited list of primary key column names.
  +    */
      protected final String getPkColumnList()
      {
         StringBuffer sb = new StringBuffer();
  @@ -266,6 +406,13 @@
         return sb.toString();
      }
      
  +   /**
  +    * Returns the string to go in a WHERE clause based on
  +    * the entity's primary key.
  +    *
  +    * @return WHERE clause content, in the form
  +    *  <code>pkCol1Name=? AND pkCol2Name=?</code>
  +    */
      protected final String getPkColumnWhereList()
      {
         StringBuffer sb = new StringBuffer();
  
  
  
  1.2       +1 -6      
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommandFactory.java
  
  Index: JDBCCommandFactory.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCommandFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCCommandFactory.java   2000/08/06 02:03:49     1.1
  +++ JDBCCommandFactory.java   2000/08/21 01:23:58     1.2
  @@ -36,7 +36,7 @@
    * JAWSPersistenceManager JDBCCommandFactory
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCCommandFactory implements JPMCommandFactory
   {
  @@ -50,11 +50,6 @@
      // These support singletons (within the scope of this factory)
      private JDBCBeanExistsCommand beanExistsCommand;
      private JPMFindEntitiesCommand findEntitiesCommand;
  -   
  -   /**
  -    * Gives compile-time control of tracing.
  -    */
  -   public static boolean debug = true;
      
      // Constructors --------------------------------------------------
      
  
  
  
  1.2       +2 -2      
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCreateEntityCommand.java
  
  Index: JDBCCreateEntityCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCCreateEntityCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCCreateEntityCommand.java      2000/08/06 02:03:49     1.1
  +++ JDBCCreateEntityCommand.java      2000/08/21 01:23:58     1.2
  @@ -39,7 +39,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCCreateEntityCommand
      extends JDBCUpdateCommand
  @@ -138,7 +138,7 @@
               id = from.get(ctx.getInstance());
            }
            
  -         if (factory.debug)
  +         if (debug)
            {
               log.debug("Create, id is "+id);
            }
  
  
  
  1.2       +3 -2      
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCDestroyCommand.java
  
  Index: JDBCDestroyCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCDestroyCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCDestroyCommand.java   2000/08/06 02:03:50     1.1
  +++ JDBCDestroyCommand.java   2000/08/21 01:23:58     1.2
  @@ -21,7 +21,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCDestroyCommand
      extends JDBCUpdateCommand
  @@ -50,7 +50,8 @@
               jdbcExecute();
            } catch (Exception e)
            {
  -            log.debug("Table "+metaInfo.getTableName()+" could not be removed");
  +            log.debug("Could not drop table " +
  +                      metaInfo.getTableName() + ": " + e.getMessage());
            }
         }
      }
  
  
  
  1.2       +9 -2      
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCFinderCommand.java
  
  Index: JDBCFinderCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCFinderCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCFinderCommand.java    2000/08/06 02:03:51     1.1
  +++ JDBCFinderCommand.java    2000/08/21 01:23:58     1.2
  @@ -33,7 +33,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public abstract class JDBCFinderCommand 
      extends JDBCQueryCommand
  @@ -93,7 +93,9 @@
                  {
                     PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
                     Field pkField = pkFieldInfo.getPkField();
  -                  pkField.set(pk, rs.getObject(i++));
  +                  pkField.set(pk, getResultObject(rs, 
  +                                                  i++, 
  +                                                  pkFieldInfo.getJDBCType()));
                  }
                  result.add(pk);
               }
  @@ -104,9 +106,14 @@
         } else
         {
            // Primitive key
  +         
  +         Iterator it = metaInfo.getPkFieldInfos();
  +         PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  +         int jdbcType = pkFieldInfo.getJDBCType();
  +         
            while (rs.next())
            {
  -            result.add(rs.getObject(i));
  +            result.add(getResultObject(rs, i, jdbcType));
            }
         }
      }
  
  
  
  1.2       +3 -2      
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java
  
  Index: JDBCInitCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCInitCommand.java      2000/08/06 02:03:51     1.1
  +++ JDBCInitCommand.java      2000/08/21 01:23:58     1.2
  @@ -25,7 +25,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCInitCommand
      extends JDBCUpdateCommand
  @@ -85,7 +85,8 @@
               jdbcExecute();
            } catch (Exception e)
            {
  -            log.debug("Table " + metaInfo.getTableName() + " exists");
  +            log.debug("Could not create table " + 
  +                      metaInfo.getTableName() + ": " + e.getMessage());
            }
         }
      }
  
  
  
  1.2       +9 -28     
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCLoadEntityCommand.java
  
  Index: JDBCLoadEntityCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCLoadEntityCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCLoadEntityCommand.java        2000/08/06 02:03:51     1.1
  +++ JDBCLoadEntityCommand.java        2000/08/21 01:23:58     1.2
  @@ -23,7 +23,6 @@
   import org.jboss.ejb.plugins.jaws.JAWSPersistenceManager;
   import org.jboss.ejb.plugins.jaws.JPMLoadEntityCommand;
   import org.jboss.ejb.plugins.jaws.CMPFieldInfo;
  -import org.jboss.ejb.plugins.jaws.PkFieldInfo;
   import org.jboss.ejb.plugins.jaws.deployment.JawsEntity;
   import org.jboss.ejb.plugins.jaws.deployment.JawsCMPField;
   
  @@ -35,7 +34,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCLoadEntityCommand
      extends JDBCQueryCommand
  @@ -110,28 +109,7 @@
      
      protected void setParameters(PreparedStatement stmt) throws Exception
      {
  -      // Primary key in WHERE-clause
  -      Iterator it = metaInfo.getPkFieldInfos();
  -      int i = 1;   // parameter index
  -      
  -      if (metaInfo.hasCompositeKey())
  -      {
  -         // Compound key
  -         while (it.hasNext())
  -         {
  -            PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  -            int jdbcType = pkFieldInfo.getJDBCType();
  -            Object value = getPkFieldValue(ctxArgument.getId(), pkFieldInfo);
  -            setParameter(stmt, i++, jdbcType, value);
  -         }
  -      } else
  -      {
  -         // Primitive key
  -         PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  -         int jdbcType = pkFieldInfo.getJDBCType();
  -         Object value = ctxArgument.getId();
  -         setParameter(stmt, i, jdbcType, value);
  -      }
  +      setPrimaryKeyParameters(stmt, 1, ctxArgument.getId());
      }
      
      protected void handleResult(ResultSet rs) throws Exception
  @@ -146,6 +124,7 @@
         while (iter.hasNext())
         {
            CMPFieldInfo fieldInfo = (CMPFieldInfo)iter.next();
  +         int jdbcType = fieldInfo.getJDBCType();
            
            if (fieldInfo.isEJBReference())
            {
  @@ -160,10 +139,10 @@
                  Field[] fields = pk.getClass().getFields();
                  for(int j = 0; j < fields.length; j++)
                  {
  -                  Object val = rs.getObject(idx++);
  +                  Object val = getResultObject(rs, idx++, jdbcType);
                     fields[j].set(pk, val);
                     
  -                  if (factory.debug)
  +                  if (debug)
                     {
                        log.debug("Referenced pk field:" + val);
                     }
  @@ -171,9 +150,9 @@
               } else
               {
                  // Primitive key
  -               pk = rs.getObject(idx++);
  +               pk = getResultObject(rs, idx++, jdbcType);
                  
  -               if (factory.debug)
  +               if (debug)
                  {
                     log.debug("Referenced pk:" + pk);
                  }
  @@ -217,7 +196,9 @@
               // Load primitive
               
               // TODO: this probably needs to be fixed for BLOB's etc.
  -            setCMPFieldValue(ctxArgument.getInstance(), fieldInfo, 
rs.getObject(idx++));
  +            setCMPFieldValue(ctxArgument.getInstance(), 
  +                             fieldInfo, 
  +                             getResultObject(rs, idx++, jdbcType));
            }
         }
         
  
  
  
  1.2       +2 -26     
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCRemoveEntityCommand.java
  
  Index: JDBCRemoveEntityCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCRemoveEntityCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCRemoveEntityCommand.java      2000/08/06 02:03:51     1.1
  +++ JDBCRemoveEntityCommand.java      2000/08/21 01:23:58     1.2
  @@ -7,8 +7,6 @@
   
   package org.jboss.ejb.plugins.jaws.jdbc;
   
  -import java.util.Iterator;
  -
   import java.rmi.RemoteException;
   
   import java.sql.PreparedStatement;
  @@ -17,7 +15,6 @@
   
   import org.jboss.ejb.EntityEnterpriseContext;
   import org.jboss.ejb.plugins.jaws.JPMRemoveEntityCommand;
  -import org.jboss.ejb.plugins.jaws.PkFieldInfo;
   
   /**
    * JAWSPersistenceManager JDBCRemoveEntityCommand
  @@ -27,7 +24,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JDBCRemoveEntityCommand
      extends JDBCUpdateCommand
  @@ -72,28 +69,7 @@
      
      protected void setParameters(PreparedStatement stmt) throws Exception
      {
  -      Iterator it = metaInfo.getPkFieldInfos();
  -      int i = 1;   // parameter index
  -      
  -      // Primary key in WHERE-clause
  -      if (metaInfo.hasCompositeKey())
  -      {
  -         // Compound key
  -         while (it.hasNext())
  -         {
  -            PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  -            int jdbcType = pkFieldInfo.getJDBCType();
  -            Object value = getPkFieldValue(ctxArgument.getId(), pkFieldInfo);
  -            setParameter(stmt, i++, jdbcType, value);
  -         }
  -      } else
  -      {
  -         // Primitive key
  -         PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  -         int jdbcType = pkFieldInfo.getJDBCType();
  -         Object value = ctxArgument.getId();
  -         setParameter(stmt, i, jdbcType, value);
  -      }
  +      setPrimaryKeyParameters(stmt, 1, ctxArgument.getId());
      }
      
      protected void handleResult(int rowsAffected) throws Exception
  
  
  
  1.3       +2 -16     
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCStoreEntityCommand.java
  
  Index: JDBCStoreEntityCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCStoreEntityCommand.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JDBCStoreEntityCommand.java       2000/08/15 16:51:20     1.2
  +++ JDBCStoreEntityCommand.java       2000/08/21 01:23:58     1.3
  @@ -32,7 +32,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.2 $
  + * @version $Revision: 1.3 $
    */
   public class JDBCStoreEntityCommand
      extends JDBCUpdateCommand
  @@ -142,21 +142,7 @@
            i++;
         }
         
  -      // Primary key in WHERE-clause
  -      Iterator it = metaInfo.getPkFieldInfos();
  -      while (it.hasNext())
  -      {
  -         PkFieldInfo pkFieldInfo = (PkFieldInfo)it.next();
  -         int jdbcType = pkFieldInfo.getJDBCType();
  -         Field field = pkFieldInfo.getCMPField();
  -         Object value = field.get(ctxArgument.getInstance());
  -         
  -         // SA had introduced the change below, but it fails
  -         // for non-composite primary keys.
  -         // Object value = getPkFieldValue(ctxArgument.getId(), pkFieldInfo);
  -         
  -         setParameter(stmt, idx++, jdbcType, value);
  -      }
  +      setPrimaryKeyParameters(stmt, idx, ctxArgument.getId());
      }
      
      protected void handleResult(int rowsAffected) throws Exception
  
  
  
  1.2       +1 -1      
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCUpdateCommand.java
  
  Index: JDBCUpdateCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCUpdateCommand.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCUpdateCommand.java    2000/08/06 02:03:52     1.1
  +++ JDBCUpdateCommand.java    2000/08/21 01:23:58     1.2
  @@ -16,7 +16,7 @@
    * Provides a Template Method implementation for
    * <code>executeStatementAndHandleResult</code>.
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public abstract class JDBCUpdateCommand extends JDBCCommand
   {
  @@ -41,7 +41,7 @@
      {
         int rowsAffected = stmt.executeUpdate();
         
  -      if (factory.debug)
  +      if (debug)
         {
            log.debug("Rows affected = " + rowsAffected);
         }
  
  
  

Reply via email to