User: fleury  
  Date: 00/08/24 19:06:31

  Modified:    src/main/org/jboss/ejb/plugins/jrmp/interfaces
                        EntityProxy.java
  Log:
  No more fast key , cachekey only
  
  Revision  Changes    Path
  1.16      +176 -160  
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java
  
  Index: EntityProxy.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/EntityProxy.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- EntityProxy.java  2000/08/17 20:13:15     1.15
  +++ EntityProxy.java  2000/08/25 02:06:30     1.16
  @@ -1,9 +1,9 @@
   /*
  - * jBoss, the OpenSource EJB server
  - *
  - * Distributable under GPL license.
  - * See terms of license at gnu.org.
  - */
  +* jBoss, the OpenSource EJB server
  +*
  +* Distributable under GPL license.
  +* See terms of license at gnu.org.
  +*/
   package org.jboss.ejb.plugins.jrmp.interfaces;
   
   import java.io.IOException;
  @@ -13,164 +13,180 @@
   import javax.ejb.EJBObject;
   
   import org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker;
  -import org.jboss.util.FastKey;
  +import org.jboss.ejb.CacheKey;
   
   /**
  - *      <description> 
  - *      
  - *      @see <related>
  - *      @author Rickard �berg ([EMAIL PROTECTED])
  - *           @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  - *      @version $Revision: 1.15 $
  - */
  +*      <description> 
  +*      
  +*   @see <related>
  +*   @author Rickard �berg ([EMAIL PROTECTED])
  +*    @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  +*   @version $Revision: 1.16 $
  +*/
   public class EntityProxy
  -   extends GenericProxy
  +extends GenericProxy
   {
  -   // Constants -----------------------------------------------------
  -    
  -   // Attributes ----------------------------------------------------
  -   protected FastKey fastKey;  
  -   
  -   // Static --------------------------------------------------------
  - 
  -   static Method getPrimaryKey;
  -   static Method getHandle;
  -   static Method isIdentical;
  -   static Method toStr;
  -   static Method eq;
  -   static Method hash;
  -   
  -   static
  -   {
  -      try
  -      {
  -        // EJB methods
  -         getPrimaryKey = EJBObject.class.getMethod("getPrimaryKey", new Class[0]);
  -         getHandle = EJBObject.class.getMethod("getHandle", new Class[0]);
  -         isIdentical = EJBObject.class.getMethod("isIdentical", new Class[] { 
EJBObject.class });
  -         
  -        // Object methods
  -        toStr = Object.class.getMethod("toString", new Class[0]);
  -         eq = Object.class.getMethod("equals", new Class[] { Object.class });
  -         hash = Object.class.getMethod("hashCode", new Class[0]);
  -      } catch (Exception e)
  -      {
  -         e.printStackTrace();
  -      }
  -   }
  -
  -   // Constructors --------------------------------------------------
  -   public EntityProxy()
  -   {
  -      // For externalization to work
  -   }
  -   
  -   public EntityProxy(String name, ContainerRemote container, FastKey fastKey, 
boolean optimize)
  -   {
  -       super(name, container, optimize);
  -
  -       if (fastKey == null)
  -         throw new NullPointerException("Id may not be null");
  -         
  -        this.fastKey = fastKey;
  -   }
  -   
  -   // Public --------------------------------------------------------
  -
  -   // InvocationHandler implementation ------------------------------
  -   public final Object invoke(Object proxy, Method m, Object[] args)
  -      throws Throwable
  -   {
  -      // Normalize args to always be an array
  -      // Isn't this a bug in the proxy call??
  -      if (args == null)
  -         args = new Object[0];
  -      
  -      // Implement local methods
  -      if (m.equals(toStr))
  -      { 
  -        return name+":"+fastKey.id.toString();
  -       
  -      }
  -      else if (m.equals(eq))
  -      {
  -         return invoke(proxy, isIdentical, args);
  -      }
  -      
  -      else if (m.equals(hash))
  -      {
  -         return new Integer(fastKey.id.hashCode());
  -      }
  -      
  -      // Implement local EJB calls
  -       else if (m.equals(getHandle))
  -      {
  -         return new EntityHandleImpl(name, fastKey.id);
  -      }
  -     
  -      else if (m.equals(getPrimaryKey))
  -      { 
  -        return fastKey.id;
  -      }
  -      else if (m.equals(isIdentical))
  -      {
  -        return new Boolean(((EJBObject)args[0]).getPrimaryKey().equals(fastKey.id));
  -      }
  -      
  -      // If not taken care of, go on and call the container
  -      else
  -      {
  -          // Delegate to container
  -          // Optimize if calling another bean in same EJB-application
  -          if (optimize && isLocal())
  -          {
  -             return container.invoke( // The entity id, method and arguments for 
the invocation
  -                             fastKey, m, args,
  -                          // Transaction attributes
  -                          tm != null ? tm.getTransaction() : null,
  -                          // Security attributes
  -                          getPrincipal(), getCredential());
  -          } else
  -          {
  -          // Create a new MethodInvocation for distribution
  -             RemoteMethodInvocation rmi = new RemoteMethodInvocation(fastKey, m, 
args);
  -             
  -          // Set the transaction context
  -          rmi.setTransaction(tm != null? tm.getTransaction() : null);
  -             
  -          // Set the security stuff
  -          // MF fixme this will need to use "thread local" and therefore same 
construct as above
  -          // rmi.setPrincipal(sm != null? sm.getPrincipal() : null);
  -             // rmi.setCredential(sm != null? sm.getCredential() : null);
  -             // is the credential thread local? (don't think so... but...)
  -          rmi.setPrincipal( getPrincipal() );
  -             rmi.setCredential( getCredential() );
  -          
  -          // Invoke on the remote server, enforce marshalling
  -             return container.invoke(new MarshalledObject(rmi)).get();
  -          }
  -      }
  -   }
  -
  -   // Package protected ---------------------------------------------
  -    
  -   // Protected -----------------------------------------------------
  -   public void writeExternal(java.io.ObjectOutput out)
  -      throws IOException
  -   {
  -       super.writeExternal(out);
  -        out.writeObject(fastKey);
  -   }
  -   
  -   public void readExternal(java.io.ObjectInput in)
  -      throws IOException, ClassNotFoundException
  -   {
  -        super.readExternal(in);
  -        fastKey = (FastKey) in.readObject();
  -   }
  -    
  -   // Private -------------------------------------------------------
  -
  -   // Inner classes -------------------------------------------------
  +     // Constants -----------------------------------------------------
  +     
  +     // Attributes ----------------------------------------------------
  +     protected CacheKey cacheKey;
  +     
  +     
  +     // Static --------------------------------------------------------
  +     
  +     static Method getPrimaryKey;
  +     static Method getHandle;
  +     static Method isIdentical;
  +     static Method toStr;
  +     static Method eq;
  +     static Method hash;
  +     
  +     static
  +     {
  +             try
  +             {
  +                     // EJB methods
  +                     getPrimaryKey = EJBObject.class.getMethod("getPrimaryKey", new 
Class[0]);
  +                     getHandle = EJBObject.class.getMethod("getHandle", new 
Class[0]);
  +                     isIdentical = EJBObject.class.getMethod("isIdentical", new 
Class[] { EJBObject.class });
  +                     
  +                     // Object methods
  +                     toStr = Object.class.getMethod("toString", new Class[0]);
  +                     eq = Object.class.getMethod("equals", new Class[] { 
Object.class });
  +                     hash = Object.class.getMethod("hashCode", new Class[0]);
  +             } catch (Exception e)
  +             {
  +                     e.printStackTrace();
  +             }
  +     }
  +     
  +     // Constructors --------------------------------------------------
  +     public EntityProxy()
  +     {
  +             // For externalization to work
  +     }
  +     
  +     public EntityProxy(String name, ContainerRemote container, Object id, boolean 
optimize)
  +     {
  +             super(name, container, optimize);
  +             
  +             if (id == null)
  +                     throw new NullPointerException("Id may not be null");
  +             
  +             if (id instanceof CacheKey) {
  +                     this.cacheKey = (CacheKey) id;
  +             }
  +             else
  +             {
  +                     // In case we pass the Object or anything else we encapsulate
  +                     cacheKey = new CacheKey(id);
  +                     
  +                     // Tell it it's fake 
  +                     cacheKey.isVirtual = true;
  +                     
  +                     // MF note: although I suspect just passing the "fake" cache 
key would
  +                     // work since the container has never mapped it in cache so no 
context 
  +                     // would be found. We explicitely set it here
  +             }
  +     }
  +     
  +     // Public --------------------------------------------------------
  +     
  +     // InvocationHandler implementation ------------------------------
  +     public final Object invoke(Object proxy, Method m, Object[] args)
  +     throws Throwable
  +     {
  +             // Normalize args to always be an array
  +             // Isn't this a bug in the proxy call??
  +             if (args == null)
  +                     args = new Object[0];
  +             
  +             // Implement local methods
  +             if (m.equals(toStr))
  +             { 
  +                     
  +                     return name+":"+cacheKey.id.toString();
  +             
  +             }
  +             else if (m.equals(eq))
  +             {
  +                     return invoke(proxy, isIdentical, args);
  +             }
  +             
  +             else if (m.equals(hash))
  +             {
  +                     return new Integer(cacheKey.id.hashCode());
  +             }
  +             
  +             // Implement local EJB calls
  +             else if (m.equals(getHandle))
  +             {
  +                     return new EntityHandleImpl(name, cacheKey.id);
  +             }
  +             
  +             else if (m.equals(getPrimaryKey))
  +             { 
  +                     return cacheKey.id;
  +             }
  +             else if (m.equals(isIdentical))
  +             {
  +                     return new 
Boolean(((EJBObject)args[0]).getPrimaryKey().equals(cacheKey.id));
  +             }
  +             
  +             // If not taken care of, go on and call the container
  +             else
  +             {
  +                     // Delegate to container
  +                     // Optimize if calling another bean in same EJB-application
  +                     if (optimize && isLocal())
  +                     {
  +                             return container.invoke( // The entity id, method and 
arguments for the invocation
  +                                     cacheKey, m, args,
  +                                     // Transaction attributes
  +                                     tm != null ? tm.getTransaction() : null,
  +                                     // Security attributes
  +                                     getPrincipal(), getCredential());
  +                     } else
  +                     {
  +                             // Create a new MethodInvocation for distribution
  +                             RemoteMethodInvocation rmi = new 
RemoteMethodInvocation(cacheKey, m, args);
  +                             
  +                             // Set the transaction context
  +                             rmi.setTransaction(tm != null? tm.getTransaction() : 
null);
  +                             
  +                             // Set the security stuff
  +                             // MF fixme this will need to use "thread local" and 
therefore same construct as above
  +                             // rmi.setPrincipal(sm != null? sm.getPrincipal() : 
null);
  +                             // rmi.setCredential(sm != null? sm.getCredential() : 
null);
  +                             // is the credential thread local? (don't think so... 
but...)
  +                             rmi.setPrincipal( getPrincipal() );
  +                             rmi.setCredential( getCredential() );
  +                             
  +                             // Invoke on the remote server, enforce marshalling
  +                             return container.invoke(new 
MarshalledObject(rmi)).get();
  +                     }
  +             }
  +     }
  +     
  +     // Package protected ---------------------------------------------
  +     
  +     // Protected -----------------------------------------------------
  +     public void writeExternal(java.io.ObjectOutput out)
  +     throws IOException
  +     {
  +             super.writeExternal(out);
  +             out.writeObject(cacheKey);
  +     }
  +     
  +     public void readExternal(java.io.ObjectInput in)
  +     throws IOException, ClassNotFoundException
  +     {
  +             super.readExternal(in);
  +             cacheKey = (CacheKey) in.readObject();
  +     }
  +     
  +     // Private -------------------------------------------------------
  +     
  +     // Inner classes -------------------------------------------------
   }
   
  
  
  

Reply via email to