User: fleury  
  Date: 00/10/17 10:52:24

  Modified:    src/main/org/jboss/ejb CacheKey.java
  Log:
  Lets' make it fool proof for now, we can always do the more complicated incremented 
key down the road
  
  Revision  Changes    Path
  1.8       +29 -5     jboss/src/main/org/jboss/ejb/CacheKey.java
  
  Index: CacheKey.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/CacheKey.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- CacheKey.java     2000/09/30 00:59:39     1.7
  +++ CacheKey.java     2000/10/17 17:52:24     1.8
  @@ -8,6 +8,8 @@
   */
   package org.jboss.ejb;
   
  +import java.rmi.MarshalledObject;
  +
   /**
   *   CacheKey
   * 
  @@ -19,7 +21,7 @@
   *
   *   @see org.jboss.ejb.plugins.NoPassivationInstanceCache.java
   *   @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
  -*   @version $Revision: 1.7 $
  +*   @version $Revision: 1.8 $
   */
   public class CacheKey
       implements java.io.Externalizable
  @@ -31,7 +33,11 @@
       // The database primaryKey
       public Object id;
        
  -    private int hashCode;
  +     // The Marshalled Object representing the key
  +     public MarshalledObject mo;
  +     
  +     // The Marshalled Object's hashcode
  +    public int hashCode;
       
       // Static --------------------------------------------------------  
       
  @@ -47,7 +53,12 @@
          this.id = id;
           
                try {
  -             hashCode = (new java.rmi.MarshalledObject(id)).hashCode();
  +                     
  +                     // Equals rely on the MarshalledObject itself
  +                     mo =  new MarshalledObject(id);
  +                     
  +                     // Precompute the hashCode (speed)
  +             hashCode = mo.hashCode();
        }
                catch (Exception e) {e.printStackTrace();}
        }
  @@ -64,6 +75,7 @@
         throws java.io.IOException
      {
           out.writeObject(id);
  +             out.writeObject(mo);
                out.writeInt(hashCode);
      
      }
  @@ -72,7 +84,8 @@
         throws java.io.IOException, ClassNotFoundException
      {
           id = in.readObject();
  -       hashCode = in.readInt();
  +             mo = (MarshalledObject) in.readObject();
  +        hashCode = in.readInt();
      }
   
       // HashCode and Equals over write --------------------------------
  @@ -88,11 +101,22 @@
       }
       
       
  +     /*
  +     * equals()
  +     *
  +     * We base the equals on the equality of the underlying key
  +     * in this fashion we make sure that we cannot have duplicate 
  +     * hashes in the maps. 
  +     * The fast way (and right way) to do this implementation 
  +     * is with a incremented cachekey.  It is more complex but worth
  +    * the effort this is a FIXME (MF)
  +     * The following implementation is fool-proof
  +     */
       public boolean equals(Object object) {
           
           if (object instanceof CacheKey) {
               
  -            return (hashCode ==(((CacheKey) object).hashCode));
  +            return (mo.equals(((CacheKey) object).mo));
           }
           return false;
       }
  
  
  

Reply via email to