Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handleing multiple rows from an EJB

 
richard marais
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
anup vachali
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...
Bean bean = (Bean)e.nextElement();
...
The bean should be a remote object. is that what it is?
Anup.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic