[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jboss-cvs-commits
Subject:    [jboss-cvs] jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge JDBCCMP2xFieldBridge.java
From:       Alexey Loubyansky <loubyansky () users ! sourceforge ! net>
Date:       2003-01-31 8:58:44
[Download RAW message or body]

  User: loubyansky
  Date: 03/01/31 00:58:43

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge
                        JDBCCMP2xFieldBridge.java
  Log:
  fix for [675932]: added boolean field to indicate whether this field is FK mapped \
to a PK field  
  Revision  Changes    Path
  1.17      +37 -29    \
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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JDBCCMP2xFieldBridge.java	27 Dec 2002 07:58:26 -0000	1.16
  +++ JDBCCMP2xFieldBridge.java	31 Jan 2003 08:58:43 -0000	1.17
  @@ -4,7 +4,7 @@
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
    */
  - 
  +
   package org.jboss.ejb.plugins.cmp.jdbc.bridge;
   
   import java.lang.reflect.Field;
  @@ -21,7 +21,7 @@
   import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCCMPFieldMetaData;
   
   /**
  - * JDBCCMP2xFieldBridge is a concrete implementation of JDBCCMPFieldBridge for 
  + * JDBCCMP2xFieldBridge is a concrete implementation of JDBCCMPFieldBridge for
    * CMP version 2.x. Instance data is stored in the entity persistence context.
    * Whenever a field is changed it is compared to the current value and sets
    * a dirty flag if the value has changed.
  @@ -29,19 +29,23 @@
    * Life-cycle:
    *      Tied to the EntityBridge.
    *
  - * Multiplicity:   
  - *      One for each entity bean cmp field.       
  + * Multiplicity:
  + *      One for each entity bean cmp field.
    *
    * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
  - * @version $Revision: 1.16 $
  - */                            
  + * @version $Revision: 1.17 $
  + */
   public class JDBCCMP2xFieldBridge extends JDBCAbstractCMPFieldBridge {
   
  +   /** indicates whether this field is FK field mapped to a PK field */
  +   private final boolean fkFieldMappedToPkField;
  +
      public JDBCCMP2xFieldBridge(
            JDBCStoreManager manager,
            JDBCCMPFieldMetaData metadata) throws DeploymentException {
   
         super(manager, metadata);
  +      fkFieldMappedToPkField = false;
      }
   
      public JDBCCMP2xFieldBridge(
  @@ -50,6 +54,7 @@
            JDBCType jdbcType) throws DeploymentException {
   
         super(manager, metadata, jdbcType);
  +      fkFieldMappedToPkField = false;
      }
   
      /**
  @@ -80,8 +85,13 @@
            primaryKeyField,
            isUnknownPk
         );
  -   }
  -
  +      fkFieldMappedToPkField = true;
  +   }
  +
  +   public boolean isFkFieldMappedToPkField() {
  +      return fkFieldMappedToPkField;
  +   }
  +
      public Object getInstanceValue(EntityEnterpriseContext ctx) {
         FieldState fieldState = getFieldState(ctx);
         if(!fieldState.isLoaded) {
  @@ -97,18 +107,20 @@
   
         return fieldState.value;
      }
  -   
  +
      public void setInstanceValue(EntityEnterpriseContext ctx, Object value) {
         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
  -      // but keep version field clean to avoid race conditions and appearing
  -      // twice in UPDATE SET clause when entity is shared between transactions
  +
  +      // short-circuit to avoid repetive comparisons
  +      // The field is considered dirty if it is
  +      // not loaded yet
  +      // OR it is already dirty
  +      // OR it is changed
  +      // The above doesn't touch version field (to avoid races in UPDATE sql)
  +      // and FK field mapped to a PK field
         fieldState.isDirty =
            (!fieldState.isLoaded || fieldState.isDirty || changed(fieldState.value, \
                value))
  -         && (getManager().getEntityBridge().getVersionField() != this);
  +         && (getManager().getEntityBridge().getVersionField() != this) && \
!fkFieldMappedToPkField;  
         // notify optimistic lock, but only if the bean is created
         if(ctx.getId() != null && fieldState.isLoaded())
  @@ -124,20 +136,20 @@
      public boolean isLoaded(EntityEnterpriseContext ctx) {
         return getFieldState(ctx).isLoaded;
      }
  -   
  +
      /**
       * Has the value of this field changes since the last time clean was called.
       */
      public boolean isDirty(EntityEnterpriseContext ctx) {
         // read only and primary key fields are never dirty
         if(isReadOnly() || isPrimaryKeyMember()) {
  -         return false; 
  +         return false;
         }
         return getFieldState(ctx).isDirty;
      }
  -   
  +
      /**
  -    * Mark this field as clean. Saves the current state in context, so it 
  +    * 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) {
  @@ -149,18 +161,14 @@
            fieldState.lastRead = System.currentTimeMillis();
         }
      }
  -   
  +
      public void resetPersistenceContext(EntityEnterpriseContext ctx) {
         if(isReadTimedOut(ctx)) {
            JDBCContext jdbcCtx = (JDBCContext)ctx.getPersistenceContext();
            jdbcCtx.put(this, new FieldState());
  -
  -         // notify optimistic lock
  -         // not used
  -         //getManager().fieldStateEventCallback(ctx, CMPMessage.RESETTED, this, \
null);  }
      }
  -   
  +
      public boolean isReadTimedOut(EntityEnterpriseContext ctx) {
         // if we are read/write then we are always timed out
         if(!isReadOnly()) {
  @@ -172,8 +180,8 @@
            return false;
         }
   
  -      long readInterval = System.currentTimeMillis() - 
  -            getFieldState(ctx).lastRead; 
  +      long readInterval = System.currentTimeMillis() -
  +            getFieldState(ctx).lastRead;
         return readInterval >= getReadTimeOut();
      }
   
  @@ -192,7 +200,7 @@
         private boolean isLoaded = false;
         private boolean isDirty = false;
         private long lastRead = -1;
  -      
  +
         public Object getValue() {
            return value;
         }
  
  
  


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
jboss-cvs-commits mailing list
jboss-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-cvs-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic