User: dsundstrom
  Date: 01/11/01 14:36:30

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge
                        JDBCAbstractCMPFieldBridge.java
                        JDBCCMP2xFieldBridge.java JDBCCMRFieldBridge.java
                        JDBCEntityBridge.java
  Log:
  Cleaned up code.
  
  Revision  Changes    Path
  1.7       +80 -28    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCAbstractCMPFieldBridge.java
  
  Index: JDBCAbstractCMPFieldBridge.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCAbstractCMPFieldBridge.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JDBCAbstractCMPFieldBridge.java   2001/09/11 18:35:00     1.6
  +++ JDBCAbstractCMPFieldBridge.java   2001/11/01 22:36:30     1.7
  @@ -41,7 +41,7 @@
    *      One for each entity bean cmp field.       
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */                            
   public abstract class JDBCAbstractCMPFieldBridge implements JDBCCMPFieldBridge {
      protected JDBCStoreManager manager;
  @@ -49,11 +49,20 @@
      protected JDBCType jdbcType;
      protected Logger log;
      
  -   public JDBCAbstractCMPFieldBridge(JDBCStoreManager manager, JDBCCMPFieldMetaData 
metadata) throws DeploymentException {      
  -      this(manager, metadata, 
manager.getJDBCTypeFactory().getFieldJDBCType(metadata));
  +   public JDBCAbstractCMPFieldBridge(
  +         JDBCStoreManager manager, 
  +         JDBCCMPFieldMetaData metadata) throws DeploymentException {      
  +
  +      this(manager, 
  +            metadata, 
  +            manager.getJDBCTypeFactory().getJDBCType(metadata));
      }
      
  -   public JDBCAbstractCMPFieldBridge(JDBCStoreManager manager, JDBCCMPFieldMetaData 
metadata, JDBCType jdbcType) throws DeploymentException {
  +   public JDBCAbstractCMPFieldBridge(
  +         JDBCStoreManager manager,
  +         JDBCCMPFieldMetaData metadata,
  +         JDBCType jdbcType) throws DeploymentException {
  +
         this.manager = manager;
         this.metadata = metadata;
         this.jdbcType = jdbcType;
  @@ -81,8 +90,10 @@
      public boolean isPrimaryKeyMember() {
         return metadata.isPrimaryKeyMember();
      }
  +
  +   public Object getPrimaryKeyValue(Object primaryKey) 
  +         throws IllegalArgumentException {
   
  -   public Object getPrimaryKeyValue(Object primaryKey) throws 
IllegalArgumentException {
         try {
            if(metadata.getPrimaryKeyField() != null) {
               if(primaryKey == null) {
  @@ -97,11 +108,14 @@
            }
         } catch(Exception e) {
            // Non recoverable internal exception
  -         throw new EJBException("Internal error getting primary key field member " 
+ getFieldName() + ": " + e);
  +         throw new EJBException("Internal error getting primary key " +
  +               "field member " + getFieldName() + ": " + e);
         }
      }
  +
  +   public Object setPrimaryKeyValue(Object primaryKey, Object value)
  +         throws IllegalArgumentException {
   
  -   public Object setPrimaryKeyValue(Object primaryKey, Object value) throws 
IllegalArgumentException {
         try {
            if(metadata.getPrimaryKeyField() != null) {
               // if we are tring to set a null value 
  @@ -112,7 +126,8 @@
               
               // if we don't have a pk object yet create one
               if(primaryKey == null) {
  -               primaryKey = manager.getEntityBridge().createPrimaryKeyInstance();
  +               primaryKey =
  +                     manager.getEntityBridge().createPrimaryKeyInstance();
               }
               
               // Set this field's value into the primary key object.
  @@ -124,15 +139,16 @@
            }
         } catch(Exception e) {
            // Non recoverable internal exception
  -         throw new EJBException("Internal error setting instance field " + 
getFieldName() + ": " + e);
  +         throw new EJBException("Internal error setting instance field " +
  +               getFieldName() + ": " + e);
         }
      }
   
      public abstract void resetPersistenceContext(EntityEnterpriseContext ctx);
      
      /**
  -   * Set CMPFieldValue to Java default value (i.e., 0 or null).
  -   */
  +    * Set CMPFieldValue to Java default value (i.e., 0 or null).
  +    */
      public void initInstance(EntityEnterpriseContext ctx) {
         if(!isReadOnly()) {
            Object value;
  @@ -164,31 +180,49 @@
         return jdbcType;
      }
   
  -   public int setInstanceParameters(PreparedStatement ps, int parameterIndex, 
EntityEnterpriseContext ctx) {
  +   public int setInstanceParameters(
  +         PreparedStatement ps,
  +         int parameterIndex, 
  +         EntityEnterpriseContext ctx) {
  +
         Object instanceValue = getInstanceValue(ctx);
         return setArgumentParameters(ps, parameterIndex, instanceValue);
      }   
  +
  +   public int setPrimaryKeyParameters(
  +         PreparedStatement ps, 
  +         int parameterIndex, 
  +         Object primaryKey) throws IllegalArgumentException {
   
  -   public int setPrimaryKeyParameters(PreparedStatement ps, int parameterIndex, 
Object primaryKey) throws IllegalArgumentException {
         Object primaryKeyValue = getPrimaryKeyValue(primaryKey);
         return setArgumentParameters(ps, parameterIndex, primaryKeyValue);
      }
      
  -   public int setArgumentParameters(PreparedStatement ps, int parameterIndex, 
Object arg) {
  +   public int setArgumentParameters(
  +         PreparedStatement ps, 
  +         int parameterIndex, 
  +         Object arg) {
  +
         try {
            int[] jdbcTypes = getJDBCType().getJDBCTypes();
            for(int i=0; i<jdbcTypes.length; i++) {
               Object columnValue = getJDBCType().getColumnValue(i, arg);
  -            JDBCUtil.setParameter(log, ps, parameterIndex++, jdbcTypes[i], 
columnValue);
  +            JDBCUtil.setParameter(log, ps, parameterIndex++, jdbcTypes[i], 
  +                  columnValue);
            }
            return parameterIndex;
         } catch(SQLException e) {
            // Non recoverable internal exception
  -         throw new EJBException("Internal error setting parameters for field " + 
getFieldName() + ": " + e);
  +         throw new EJBException("Internal error setting parameters for field " +
  +               getFieldName() + ": " + e);
         }
      }   
  +
  +   public int loadInstanceResults(
  +         ResultSet rs, 
  +         int parameterIndex, 
  +         EntityEnterpriseContext ctx) {
   
  -   public int loadInstanceResults(ResultSet rs, int parameterIndex, 
EntityEnterpriseContext ctx) {
         try {
            // value of this field,  will be filled in below
            Object[] argumentRef = new Object[1];
  @@ -205,11 +239,16 @@
         } catch(Exception e) {
            // Non recoverable internal exception
            e.printStackTrace();
  -         throw new EJBException("Internal error getting results for field " + 
getFieldName() + ": " + e);
  +         throw new EJBException("Internal error getting results for field " +
  +               getFieldName() + ": " + e);
         }
      }      
      
  -   public int loadPrimaryKeyResults(ResultSet rs, int parameterIndex, Object[] 
pkRef) throws IllegalArgumentException {
  +   public int loadPrimaryKeyResults(
  +         ResultSet rs,
  +         int parameterIndex,
  +         Object[] pkRef) throws IllegalArgumentException {
  +
         // value of this field,  will be filled in below
         Object[] argumentRef = new Object[1];
         
  @@ -223,7 +262,11 @@
         return parameterIndex;
      }      
   
  -   public int loadArgumentResults(ResultSet rs, int parameterIndex, Object[] 
argumentRef) throws IllegalArgumentException {
  +   public int loadArgumentResults(
  +         ResultSet rs,
  +         int parameterIndex, 
  +         Object[] argumentRef) throws IllegalArgumentException {
  +
         try {
            // value of this field,  will be filled in below
            // set the value of this field into the pk
  @@ -232,25 +275,34 @@
            // update the value from the result set
            Class[] javaTypes = getJDBCType().getJavaTypes();
            for(int i=0; i<javaTypes.length; i++) {
  -            Object columnValue = JDBCUtil.getResult(log, rs, parameterIndex++, 
javaTypes[i]);
  -            argumentRef[0] = getJDBCType().setColumnValue(i, argumentRef[0], 
columnValue);
  +            Object columnValue = 
  +                  JDBCUtil.getResult(log, rs, parameterIndex++, javaTypes[i]);
  +            argumentRef[0] = 
  +                  getJDBCType().setColumnValue(i, argumentRef[0], columnValue);
            }
                     
            // retrun the updated parameterIndex
            return parameterIndex;
         } catch(SQLException e) {
            // Non recoverable internal exception
  -         throw new EJBException("Internal error getting results for field member " 
+ getFieldName() + ": " + e);
  +         throw new EJBException("Internal error getting results " +
  +               "for field member " + getFieldName() + ": " + e);
         }
      }
      
      protected final boolean changed(Object current, Object old) {
         return   
  -         (current == null && old != null) ||   // TRUE if I am null and I wasn't 
before   
  -         (current != null &&                   // TRUE if I was null and now I'm not
  -            ( old == null || (!current.equals(old)) ) // TRUE if i'm not equal to 
my oldstate 
  -         );                                           //   tied to last check to 
assure that current is not null
  +         // TRUE if I am null and I wasn't before   
  +         (current == null && old != null) ||   
  +         
  +         // TRUE if I was null and now I'm not
  +         (current != null &&
  +            ( old == null || 
  +               // TRUE if i'm not equal to my oldstate tied to last 
  +               // check to assure that current is not null 
  +              (!current.equals(old)) )
  +         );                                           
               
      }
   }
  -                                         
  \ No newline at end of file
  +                                         
  
  
  
  1.7       +23 -11    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMP2xFieldBridge.java
  
  Index: JDBCCMP2xFieldBridge.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMP2xFieldBridge.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JDBCCMP2xFieldBridge.java 2001/09/11 18:35:00     1.6
  +++ JDBCCMP2xFieldBridge.java 2001/11/01 22:36:30     1.7
  @@ -22,7 +22,7 @@
   /**
    * JDBCCMP2xFieldBridge is a concrete implementation of JDBCCMPFieldBridge for 
    * CMP version 2.x. Instance data is stored in the entity persistence context.
  - * When every a field is changed it is compared to the current value and sets
  + * Whenever a field is changed it is compared to the current value and sets
    * a dirty flag if the value has changed.
    *
    * Life-cycle:
  @@ -32,14 +32,21 @@
    *      One for each entity bean cmp field.       
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */                            
   public class JDBCCMP2xFieldBridge extends JDBCAbstractCMPFieldBridge {
  -   public JDBCCMP2xFieldBridge(JDBCStoreManager manager, JDBCCMPFieldMetaData 
metadata) throws DeploymentException {
  +   public JDBCCMP2xFieldBridge(
  +         JDBCStoreManager manager,
  +         JDBCCMPFieldMetaData metadata) throws DeploymentException {
  +
         super(manager, metadata);
      }
  +
  +   public JDBCCMP2xFieldBridge(
  +         JDBCStoreManager manager,
  +         JDBCCMPFieldMetaData metadata,
  +         JDBCType jdbcType) throws DeploymentException {
   
  -   public JDBCCMP2xFieldBridge(JDBCStoreManager manager, JDBCCMPFieldMetaData 
metadata, JDBCType jdbcType) throws DeploymentException {
         super(manager, metadata, jdbcType);
      }
   
  @@ -48,7 +55,8 @@
         if(!fieldState.isLoaded) {
            manager.loadField(this, ctx);
            if(!fieldState.isLoaded) {
  -            throw new EJBException("Could not load field value: " + getFieldName());
  +            throw new EJBException("Could not load field value: " + 
  +                  getFieldName());
            }
         }
         return fieldState.value;
  @@ -58,8 +66,10 @@
         FieldState fieldState = getFieldState(ctx);
   
         // short-circuit to avoid repetive comparisons
  -      // if it is not currently loaded or it is already dirty or if it has changed
  -      fieldState.isDirty = !fieldState.isLoaded || fieldState.isDirty || 
changed(fieldState.value, value);
  +      // if it is not currently loaded or it is already dirty or 
  +      // if it has changed
  +      fieldState.isDirty = !fieldState.isLoaded || fieldState.isDirty || 
  +            changed(fieldState.value, value);
         
         // we are loading the field right now so it isLoaded 
         fieldState.isLoaded = true;
  @@ -81,8 +91,8 @@
      }
      
      /**
  -   * Mark this field as clean.
  -   * Saves the current state in context, so it can be compared when isDirty is 
called.
  +   * Mark this field as clean. Saves the current state in context, so it 
  +   * can be compared when isDirty is called.
      */
      public void setClean(EntityEnterpriseContext ctx) {
         FieldState fieldState = getFieldState(ctx);
  @@ -103,7 +113,8 @@
      
      public boolean isReadTimedOut(EntityEnterpriseContext ctx) {
         if(isReadOnly()) {
  -         long readInterval = System.currentTimeMillis() - 
getFieldState(ctx).lastRead; 
  +         long readInterval = System.currentTimeMillis() - 
  +               getFieldState(ctx).lastRead; 
            return readInterval > metadata.getReadTimeOut();
         }
         
  @@ -111,7 +122,8 @@
         return true;
      }
   
  -   private CMPStoreManager.PersistenceContext 
getPersistenceContext(EntityEnterpriseContext ctx) {
  +   private CMPStoreManager.PersistenceContext getPersistenceContext(
  +         EntityEnterpriseContext ctx) {
         return (CMPStoreManager.PersistenceContext)ctx.getPersistenceContext();
      }
         
  
  
  
  1.9       +6 -2      
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java
  
  Index: JDBCCMRFieldBridge.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JDBCCMRFieldBridge.java   2001/10/20 16:14:57     1.8
  +++ JDBCCMRFieldBridge.java   2001/11/01 22:36:30     1.9
  @@ -44,7 +44,7 @@
    *      One for each role that entity has.       
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */                            
   public class JDBCCMRFieldBridge implements CMRFieldBridge {
      // ------ Invocation messages ------
  @@ -211,7 +211,11 @@
            Set keys = new HashSet();
            for(Iterator i=foreignKeys.iterator(); i.hasNext(); ) {
               JDBCCMPFieldMetaData cmpFieldMetaData = (JDBCCMPFieldMetaData)i.next();
  -            keys.add(new JDBCCMP2xFieldBridge(manager, cmpFieldMetaData, 
manager.getJDBCTypeFactory().getFieldJDBCType(cmpFieldMetaData)));
  +            keys.add(new JDBCCMP2xFieldBridge(
  +                     manager,
  +                     cmpFieldMetaData,
  +                     manager.getJDBCTypeFactory().getJDBCType(
  +                        cmpFieldMetaData)));
            }
            foreignKeyFields = new JDBCCMPFieldBridge[foreignKeys.size()];
            foreignKeyFields = (JDBCCMPFieldBridge[])keys.toArray(foreignKeyFields);
  
  
  
  1.10      +110 -41   
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCEntityBridge.java
  
  Index: JDBCEntityBridge.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCEntityBridge.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JDBCEntityBridge.java     2001/09/11 18:35:00     1.9
  +++ JDBCEntityBridge.java     2001/11/01 22:36:30     1.10
  @@ -52,7 +52,7 @@
    *      One per cmp entity bean type.       
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */                            
   public class JDBCEntityBridge implements EntityBridge {
      protected JDBCEntityMetaData metadata;
  @@ -73,7 +73,11 @@
      
      protected Logger log;
   
  -   public JDBCEntityBridge(JDBCEntityMetaData metadata, Logger log, 
JDBCStoreManager manager) throws DeploymentException {
  +   public JDBCEntityBridge(
  +         JDBCEntityMetaData metadata, 
  +         Logger log,
  +         JDBCStoreManager manager) throws DeploymentException {
  +
         this.metadata = metadata;                  
         this.log = log;
         this.manager = manager;
  @@ -85,8 +89,10 @@
         loadCMRFields(metadata);
         loadSelectors(metadata);
      }
  +
  +   protected void loadCMPFields(JDBCEntityMetaData metadata)
  +         throws DeploymentException {
   
  -   protected void loadCMPFields(JDBCEntityMetaData metadata) throws 
DeploymentException {
         // map between field names and field objects
         cmpFieldsByName = new HashMap(metadata.getCMPFields().size());
         // non primary key cmp fields
  @@ -97,8 +103,10 @@
         // create each field    
         Iterator iter = metadata.getCMPFields().iterator();
         while(iter.hasNext()) {
  -         JDBCCMPFieldMetaData cmpFieldMetaData = (JDBCCMPFieldMetaData)iter.next();
  -         JDBCCMPFieldBridge cmpField = createCMPField(metadata, cmpFieldMetaData);
  +         JDBCCMPFieldMetaData cmpFieldMetaData = 
  +               (JDBCCMPFieldMetaData)iter.next();
  +         JDBCCMPFieldBridge cmpField = 
  +               createCMPField(metadata, cmpFieldMetaData);
            cmpFieldsByName.put(cmpField.getFieldName(), cmpField);
            
            if(cmpField.isPrimaryKeyMember()) {
  @@ -111,7 +119,8 @@
         
         // save the pk fields in the pk field array
         primaryKeyFields = new JDBCCMPFieldBridge[pkFieldList.size()];
  -      primaryKeyFields = 
(JDBCCMPFieldBridge[])pkFieldList.toArray(primaryKeyFields);      
  +      primaryKeyFields =
  +            (JDBCCMPFieldBridge[])pkFieldList.toArray(primaryKeyFields);      
         
         // add the pk fields to the front of the cmp list, per guarantee above
         cmpFieldList.addAll(0, pkFieldList);
  @@ -121,7 +130,9 @@
         cmpFields = (JDBCCMPFieldBridge[])cmpFieldList.toArray(cmpFields);
      }
   
  -   protected void loadEagerLoadFields(JDBCEntityMetaData metadata) throws 
DeploymentException {
  +   protected void loadEagerLoadFields(JDBCEntityMetaData metadata)
  +         throws DeploymentException {
  +
         ArrayList fields = new ArrayList(metadata.getCMPFields().size());
         Iterator iter = metadata.getEagerLoadFields().iterator();
         while(iter.hasNext()) {
  @@ -131,8 +142,10 @@
         eagerLoadFields = new JDBCCMPFieldBridge[fields.size()];
         eagerLoadFields = (JDBCCMPFieldBridge[])fields.toArray(eagerLoadFields);
      }
  +
  +   protected void loadLazyLoadGroups(JDBCEntityMetaData metadata)
  +         throws DeploymentException {
   
  -   protected void loadLazyLoadGroups(JDBCEntityMetaData metadata) throws 
DeploymentException {
         lazyLoadGroups = new ArrayList();
         
         Iterator groups = metadata.getLazyLoadGroups().iterator();
  @@ -148,8 +161,10 @@
         }
      }
   
  -   protected JDBCCMPFieldBridge createCMPField(JDBCEntityMetaData metadata, 
JDBCCMPFieldMetaData cmpFieldMetaData) 
  -         throws DeploymentException {
  +   protected JDBCCMPFieldBridge createCMPField(
  +         JDBCEntityMetaData metadata,
  +         JDBCCMPFieldMetaData cmpFieldMetaData) throws DeploymentException {
  +
         if(metadata.isCMP1x()) {
            return new JDBCCMP1xFieldBridge(manager, cmpFieldMetaData);
         } else {
  @@ -157,15 +172,20 @@
         }
      }
      
  -   protected void loadCMRFields(JDBCEntityMetaData metadata) throws 
DeploymentException {
  +   protected void loadCMRFields(JDBCEntityMetaData metadata)
  +         throws DeploymentException {
  +
         cmrFieldsByName = new HashMap(metadata.getRelationshipRoles().size());
  -      ArrayList cmrFieldList = new 
ArrayList(metadata.getRelationshipRoles().size());
  +      ArrayList cmrFieldList =
  +            new ArrayList(metadata.getRelationshipRoles().size());
   
         // create each field    
         Iterator iter = metadata.getRelationshipRoles().iterator();
         while(iter.hasNext()) {
  -         JDBCRelationshipRoleMetaData relationshipRole = 
(JDBCRelationshipRoleMetaData)iter.next();
  -         JDBCCMRFieldBridge cmrField = new JDBCCMRFieldBridge(this, manager, 
relationshipRole); 
  +         JDBCRelationshipRoleMetaData relationshipRole =
  +               (JDBCRelationshipRoleMetaData)iter.next();
  +         JDBCCMRFieldBridge cmrField =
  +               new JDBCCMRFieldBridge(this, manager, relationshipRole); 
            cmrFieldList.add(cmrField);
            cmrFieldsByName.put(cmrField.getFieldName(), cmrField);
         }
  @@ -179,22 +199,26 @@
         }
      }
   
  -   protected void loadSelectors(JDBCEntityMetaData metadata) throws 
DeploymentException {
  -      // Don't know if this is the best way to do this.  Another way would be to 
  -      // deligate seletors to the JDBCFindEntitiesCommand, but this is easier now.
  -      
  +   protected void loadSelectors(JDBCEntityMetaData metadata)
  +         throws DeploymentException {
  +            
  +      // Don't know if this is the best way to do this.  Another way would be 
  +      // to deligate seletors to the JDBCFindEntitiesCommand, but this is
  +      // easier now.
         selectorsByMethod = new HashMap(metadata.getQueries().size());
         Iterator definedFinders = manager.getMetaData().getQueries().iterator();
         while(definedFinders.hasNext()) {
            JDBCQueryMetaData q = (JDBCQueryMetaData)definedFinders.next();
   
  -         if(q instanceof JDBCQlQueryMetaData) {
  -            selectorsByMethod.put(q.getMethod(), new JDBCSelectorBridge(manager, 
(JDBCQlQueryMetaData)q));
  +         if(q.getMethod().getName().startsWith("ejbSelect")) {
  +            selectorsByMethod.put(q.getMethod(), 
  +                  new JDBCSelectorBridge(manager, q));
            }
         }
   
         selectors = new JDBCSelectorBridge[selectorsByMethod.values().size()];
  -      selectors = 
(JDBCSelectorBridge[])selectorsByMethod.values().toArray(selectors);
  +      selectors = 
  +            (JDBCSelectorBridge[])selectorsByMethod.values().toArray(selectors);
      }
      
      public String getEntityName() {
  @@ -248,7 +272,9 @@
         return (JDBCCMPFieldBridge)cmpFieldsByName.get(name);
      }
      
  -   protected JDBCCMPFieldBridge getExistingCMPFieldByName(String name) throws 
DeploymentException {
  +   protected JDBCCMPFieldBridge getExistingCMPFieldByName(String name)
  +         throws DeploymentException {
  +
         JDBCCMPFieldBridge cmpField = getCMPFieldByName(name);
         if(cmpField == null) {
            throw new DeploymentException("cmpField not found: " + name);
  @@ -304,7 +330,8 @@
         // get dirty cmr foreign key fields
         for(int i=0; i<cmrFields.length; i++) {
            if(cmrFields[i].hasForeignKey()) {
  -            JDBCCMPFieldBridge[] foreignKeyFields = 
cmrFields[i].getForeignKeyFields();
  +            JDBCCMPFieldBridge[] foreignKeyFields =
  +                  cmrFields[i].getForeignKeyFields();
               for(int j=0; j<foreignKeyFields.length; j++) {
                  if(foreignKeyFields[j].isDirty(ctx)) {
                     dirtyFields.add(foreignKeyFields[j]);
  @@ -313,7 +340,8 @@
            }
         }
         
  -      JDBCCMPFieldBridge[] dirtyFieldArray = new 
JDBCCMPFieldBridge[dirtyFields.size()];
  +      JDBCCMPFieldBridge[] dirtyFieldArray =
  +            new JDBCCMPFieldBridge[dirtyFields.size()];
         return (JDBCCMPFieldBridge[])dirtyFields.toArray(dirtyFieldArray);
      }
      
  @@ -322,7 +350,8 @@
         // notify the handler of the assigned context.
         Object instance = ctx.getInstance();
         if(instance instanceof Proxies.ProxyTarget) {
  -         InvocationHandler handler = 
((Proxies.ProxyTarget)instance).getInvocationHandler();
  +         InvocationHandler handler = 
  +               ((Proxies.ProxyTarget)instance).getInvocationHandler();
            if(handler instanceof EntityBridgeInvocationHandler) {
               ((EntityBridgeInvocationHandler)handler).setContext(ctx);
            }
  @@ -350,7 +379,8 @@
         // notify the handler of the assigned context.
         Object instance = ctx.getInstance();
         if(instance instanceof Proxies.ProxyTarget) {
  -         InvocationHandler handler = 
((Proxies.ProxyTarget)instance).getInvocationHandler();
  +         InvocationHandler handler =
  +               ((Proxies.ProxyTarget)instance).getInvocationHandler();
            if(handler instanceof EntityBridgeInvocationHandler) {
               ((EntityBridgeInvocationHandler)handler).setContext(null);
            }
  @@ -358,49 +388,83 @@
   
         ctx.setPersistenceContext(null);
      }
  +
  +   public CMPStoreManager.PersistenceContext getPersistenceContext(
  +         EntityEnterpriseContext ctx) {
   
  -   public CMPStoreManager.PersistenceContext 
getPersistenceContext(EntityEnterpriseContext ctx) {
         return (CMPStoreManager.PersistenceContext)ctx.getPersistenceContext();
      }
   
      // JDBC Specific Information
      
  -   public int setInstanceParameters(PreparedStatement ps, int parameterIndex, 
EntityEnterpriseContext ctx)  {
  +   public int setInstanceParameters(
  +         PreparedStatement ps,
  +         int parameterIndex,
  +         EntityEnterpriseContext ctx)  {
  +
         return setInstanceParameters(ps, parameterIndex, ctx, cmpFields);
      }
   
  -   public int setInstanceParameters(PreparedStatement ps, int parameterIndex, 
EntityEnterpriseContext ctx, JDBCCMPFieldBridge[] fields) {
  +   public int setInstanceParameters(
  +         PreparedStatement ps,
  +         int parameterIndex,
  +         EntityEnterpriseContext ctx, 
  +         JDBCCMPFieldBridge[] fields) {
  +
         for(int i=0; i<fields.length; i++) {
  -         parameterIndex = fields[i].setInstanceParameters(ps, parameterIndex, ctx);
  +         parameterIndex =
  +               fields[i].setInstanceParameters(ps, parameterIndex, ctx);
         }
         return parameterIndex;
      }
  +
  +   public int setPrimaryKeyParameters(
  +         PreparedStatement ps,
  +         int parameterIndex,
  +         Object primaryKey) {      
   
  -   public int setPrimaryKeyParameters(PreparedStatement ps, int parameterIndex, 
Object primaryKey) {      
         for(int i=0; i<primaryKeyFields.length; i++) {
  -         parameterIndex = primaryKeyFields[i].setPrimaryKeyParameters(ps, 
parameterIndex, primaryKey);
  +         parameterIndex = primaryKeyFields[i].setPrimaryKeyParameters(
  +               ps,
  +               parameterIndex,
  +               primaryKey);
         }
         return parameterIndex;
      }
  +
  +   public int loadInstanceResults(
  +         ResultSet rs,
  +         int parameterIndex,
  +         EntityEnterpriseContext ctx) {
   
  -   public int loadInstanceResults(ResultSet rs, int parameterIndex, 
EntityEnterpriseContext ctx) {
         for(int i=0; i<cmpFields.length; i++) {
  -         parameterIndex = cmpFields[i].loadInstanceResults(rs, parameterIndex, ctx);
  +         parameterIndex =
  +               cmpFields[i].loadInstanceResults(rs, parameterIndex, ctx);
         }
         return parameterIndex;
      }
            
  -   public int loadNonPrimaryKeyResults(ResultSet rs, int parameterIndex, 
EntityEnterpriseContext ctx) {
  +   public int loadNonPrimaryKeyResults(
  +         ResultSet rs,
  +         int parameterIndex,
  +         EntityEnterpriseContext ctx) {
  +
         for(int i=primaryKeyFields.length; i<cmpFields.length; i++) {
  -         parameterIndex = cmpFields[i].loadInstanceResults(rs, parameterIndex, ctx);
  +         parameterIndex = 
  +               cmpFields[i].loadInstanceResults(rs, parameterIndex, ctx);
         }
         return parameterIndex;
      }
            
  -   public int loadPrimaryKeyResults(ResultSet rs, int parameterIndex, Object[] 
pkRef) {
  +   public int loadPrimaryKeyResults(
  +         ResultSet rs, 
  +         int parameterIndex, 
  +         Object[] pkRef) {
  +
         pkRef[0] = createPrimaryKeyInstance();
         for(int i=0; i<primaryKeyFields.length; i++) {
  -         parameterIndex = primaryKeyFields[i].loadPrimaryKeyResults(rs, 
parameterIndex, pkRef);
  +         parameterIndex = primaryKeyFields[i].loadPrimaryKeyResults(
  +               rs, parameterIndex, pkRef);
         }
         return parameterIndex;
      }
  @@ -412,7 +476,8 @@
               Object fieldValue = primaryKeyFields[i].getInstanceValue(ctx);
               
               // updated pk object with return form set primary key value to
  -            // handle single valued non-composit pks and more complicated behivors.
  +            // handle single valued non-composit pks and more complicated
  +            // behivors.
               pk = primaryKeyFields[i].setPrimaryKeyValue(pk, fieldValue);
            }
            return pk;
  @@ -421,11 +486,15 @@
            throw e;
         } catch(Exception e) {
            // Non recoverable internal exception
  -         throw new EJBException("Internal error extracting primary key from 
instance: " + e);
  +         throw new EJBException("Internal error extracting primary key from " +
  +               "instance: " + e);
         }
      }
  +
  +   public void injectPrimaryKeyIntoInstance(
  +         EntityEnterpriseContext ctx,
  +         Object pk) {
   
  -   public void injectPrimaryKeyIntoInstance(EntityEnterpriseContext ctx, Object pk) 
{
         for(int i=0; i<primaryKeyFields.length; i++) {
            Object fieldValue = primaryKeyFields[i].getPrimaryKeyValue(pk);
            primaryKeyFields[i].setInstanceValue(ctx, fieldValue);
  
  
  

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

Reply via email to