File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Handleing multiple rows from an EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Handleing multiple rows from an EJB" Watch "Handleing multiple rows from an EJB" New topic
Author

Handleing multiple rows from an EJB

richard marais
Ranch Hand

Joined: Aug 20, 2001
Posts: 30
I have defined a WhereClause in the BeanFinderHelper Interface:
public static final String findGreaterThanWhereClause = "sort_order > ?";
And a findGreaterThan(int) method in the home interface:
public java.util.Enumeration findGreaterThan(int threshold) throws java.rmi.RemoteException, javax.ejb.FinderException;
I can access the home interface successfully through the "home" object:
Eg. Bean bean = home.create(1);
But I don't understand how I should handle an Enumeration. How do I loop through the Enumeration from the findGreaterThan(int) to access the remote interface getter & setter methods?
I tried the following, but I do not have a remote object:
java.util.Enumeration e = home.findGreaterThan(0); // returns enumeration
while (e.hasMoreElements())
{
System.out.println(e.nextElement());
}
Usually I would create a bean object and call the remote interface methods on this object, but with an enumeration I do not have a bean object.
Eg. Bean bean = home.findByPrimaryKey(key); // returns bean object
bean.getMethod();
1) How do I see the fields from each row of the enumeration?
2) How do I access the remote interface methods from the enumeration?
Thanks in advance
richard marais
Ranch Hand

Joined: Aug 20, 2001
Posts: 30
When I try the following I get a ClassCastException.
java.util.Enumeration e = home.findGreaterThan(0);
while (e.hasMoreElements())
{
Bean bean = (Bean)e.nextElement();
System.out.println(bean.getMethod());
}
Anyone?
anup vachali
Ranch Hand

Joined: Oct 17, 2000
Posts: 54
...
Bean bean = (Bean)e.nextElement();
...
The bean should be a remote object. is that what it is?
Anup.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Your client logic looks fine. Is this a BMP bean? It should be creating an enumeration and adding bean primary keys (NOT the beans themselves - their primary keys!!!). Under EJB 1.1, you must ALWAYS create and return this enumeration, even if it's empty. Under 1.0 you returned "null" if you had no data.


Customer surveys are for companies who didn't pay proper attention to begin with.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
If you are using the CMP beans in WebSphere/Visual Age for JAVA (which I assume that you are, based on the use of a FinderHelper class), then the Enumeration will contain instances of the remote class. You should use the PortableRemoteObject.narrow method to do your casting from an Enumeration. Your code would then look as such:

This example was taken straight from my own code. Emp is the Remote class, and the findByAll() method is a method in the Home interface that returns all the records in the table. (WhereClause is "1=1");
Hope that this helps.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handleing multiple rows from an EJB
 
Similar Threads
EJB and servlet question....
findbyprimarykey doubt
Enumeration
Running SQL in an EJB
Is it possible to create a class like this