Hi Kurt,
I understand your Collection analogy but I think this is really a legitmate
demand. For eg. in a system there could be Persons, Managers and Techleads.
Now, it is quite reasonable to retrieve all the Persons in one go and then
depending on the person perform activities. So there have to be different
entities because operations like manage() cannot be provided in Person bean.

But as I write this, I got another idea.
Support all the methods in Person (actually have just one kind of entity
bean which has superset of all the attributes) and also have a tag field
telling whether it is a Person or Manager etc. Now depending on this tag,
call the appropriate methods. If you call manage() on a bean that has the
tag value of Person, throw some runtime exception!

Please give your comments on this. I am sure many of the projects involving
EJBs must have ran into this kind of situation.

Please help,
-Tom.


>From: "Christensen, Kurt" <[EMAIL PROTECTED]>
>Reply-To: A mailing list for Enterprise JavaBeans development
><[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: A design question...
>Date: Mon, 7 Aug 2000 21:30:40 -0500
>
>Oops! I just realized that I didn't actually answer your question. What
>you're looking for is actually sort of tricky. "findXXX" is (sort of)
>analogous to "get(Object o)" in the Collection interface. Now, if I had:
>
>public class MyCollection implements Collection
>{
>     // ...
>}
>
>and
>
>public class MySuperCoolCollection extends MyCollection
>{
>     // ...
>}
>
>...you wouldn't expect a get() on a MyCollection to return everything in
>MySuperCoolCollection as well. But this is what you're asking for when you
>ask for a generic findXXX() method in the base class. Luckily, since
>EJBHome
>objects are basically singleton objects, we can probably accomplish
>something along the lines of what you're looking for....
>
>
>public class CarProxy
>{
>     private EJBHome _myEJBHome;
>     private Method  _myFinderMethod;
>     private static Hashtable _myChildFindByNames = new Hashtable(89);
>
>     public CarProxy()
>     {
>         this( "CarHome" );
>     }
>
>     public CarProxy( String jndiHomeName )
>     {
>         // Get JNDI context (app-server specific code here)
>         Context context = new InitialContext();
>
>         // Get EJBHome object
>         Object o = context.lookup( "CarHome" );
>
>         // Perform CORBA narrowing voodoo
>         _myEJBHome = (EJBHome)PortableRemoteObject.narrow( o,
>EJBHome.class
>);
>
>         // Get the metadata for this EJB (we need to do all this
>         //   because EJBHome doesn't define findByPrimaryKey() )
>         EJBMetaData ejbMetaData = ejbHome.getEJBMetaData();
>
>         // Get the Home class for the EJB from the metadata
>         Class ejbHomeClass = ejbMetaData.getHomeInterfaceClass();
>
>         // Get the findByName method
>         Class[] argTypes = { String.class };
>         _myFinderMethod = ejbHomeClass.getMethod( "findByName", argTypes
>);
>
>         // Save the finder method in our collection of finder methods
>         _myChildFindByNames.put( _myEJBHome, _myFinderMethod );
>     }
>
>     public Car findByPrimaryKey( CarPK carPK )
>     {
>         Object[] args = { carPK };
>         return _myFinderMethod.invoke( _myEJBHome, args );
>     }
>
>     public Collection findByName( String name )
>     {
>         ArrayList resultSet = new ArrayList();
>
>         Enumeration keys = _myChildFindByNames.keys();
>         while( keys.hasMoreElements() )
>         {
>             EJBHome ejbHome = (EJBHome)keys.nextElement();
>             Method finderMethod = (Method)_myChildFindByNames.get( ejbHome
>);
>             Collection results = (Collection)finderMethod.invoke( ejbHome,
>name );
>             resultSet.addAll( results );
>         }
>
>         return resultSet;
>     }
>}
>
>public class SportsCarProxy
>{
>     public SportsCarProxy()
>     {
>         super( "SportsCarHome" );
>     }
>}
>
>
>This probably isn't exactly right, but I think it's a good avenue for what
>you're trying to accomplish. If anyone out there has any bright ideas of
>what to do here, join in the fun...
>
>KurtC
>
>===========================================================================
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff EJB-INTEREST".  For general help, send email to
>[EMAIL PROTECTED] and include in the body of the message "help".
>

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to