User: fleury  
  Date: 00/08/08 15:12:25

  Modified:    src/main/org/jboss/ejb/plugins/jrmp/interfaces
                        HomeProxy.java
  Log:
  Implementation of the removeByPrimaryKey we trick the container in thinking this is 
an object call
  
  Revision  Changes    Path
  1.10      +44 -18    
jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java
  
  Index: HomeProxy.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jrmp/interfaces/HomeProxy.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- HomeProxy.java    2000/08/08 21:21:10     1.9
  +++ HomeProxy.java    2000/08/08 22:12:25     1.10
  @@ -23,7 +23,7 @@
    *      @see <related>
    *      @author Rickard �berg ([EMAIL PROTECTED])
    *           @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  - *      @version $Revision: 1.9 $
  + *      @version $Revision: 1.10 $
    */
   public class HomeProxy
      extends GenericProxy
  @@ -37,6 +37,7 @@
      static Method getHomeHandle;
      static Method removeByHandle;
      static Method removeByPrimaryKey;
  +   static Method removeObject;
      static Method toStr;
      static Method eq;
      static Method hash;
  @@ -50,6 +51,8 @@
            getHomeHandle = EJBHome.class.getMethod("getHomeHandle", new Class[0]);
            removeByHandle = EJBHome.class.getMethod("remove", new Class[] 
{Handle.class});
                 removeByPrimaryKey = EJBHome.class.getMethod("remove", new Class[] 
{Object.class});
  +              // Get the "remove" method from the EJBObject
  +              removeObject = EJBObject.class.getMethod("remove", new Class[] 
{Object.class});
                 
                 // Object methods
             toStr = Object.class.getMethod("toString", new Class[0]);
  @@ -124,25 +127,48 @@
                  return Void.TYPE;
          }
          
  -       // MF FIXME I suspect we can have a much more efficient call on the server
  +       // The trick is simple we trick the container in believe it is a remove() on 
the instance
          else if (m.equals(removeByPrimaryKey))
         {
  -               throw new Exception("NYI");
  -               /*
  -               try {
  -               
  -               // Get the metadata
  -               EJBMetaData metaData = invoke(proxy, getEJBMetaData, new Object[0]);
  -               
  -               // Retrieve the find by primary key method
  -               Method findByPrimaryKey = 
(metaData.getHomeInterfaceClass().getMethod(findByPrimaryKey, new Class[] 
{Object.class});
  -               
  -               // Find the Object we are talking about
  -               EJBObject object = invoke(proxy, findByPrimaryKey, args);
  -               
  -               // Remove it from here
  -               return object.remove();
  -               */
  +               if (optimize && isLocal())
  +           {
  +              return container.invoke(
  +                                                                     // The first 
argument is the id
  +                                                                     args[0], 
  +                                                                     // Pass the 
"removeMethod"
  +                                                                     removeObject, 
  +                                                                     // this is a 
remove() on the object
  +                                                                     new Object[0],
  +                                                                     // Tx stuff
  +                                                                     tm != null ? 
tm.getTransaction() : null,
  +                                                                     // Security 
attributes
  +                                                                     
getPrincipal(), getCredential());
  +           } else
  +           {
  +
  +                     // Build a method invocation that carries the identity of the 
target object
  +                     RemoteMethodInvocation rmi = new RemoteMethodInvocation(
  +                                                                                    
                                         // The first argument is the id
  +                                                                                    
                                         args[0], 
  +                                                                                    
                                         // Pass the "removeMethod"
  +                                                                                    
                                         removeObject, 
  +                                                                                    
                                         // this is a remove() on the object
  +                                                                                    
                                         new Object[0]);
  +
  +                      // 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.invokeHome(new MarshalledObject(rmi));
  +           }
         }
         
          // If not taken care of, go on and call the container
  
  
  

Reply via email to