• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Handleing multiple rows from an EJB

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...
Bean bean = (Bean)e.nextElement();
...
The bean should be a remote object. is that what it is?
Anup.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic