• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

SFSB Doubt

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Assume i login into a Shopping Cart appl and add an item to my cart.

In the code when home.create(String userId) would be called, the SFSB bean and the EJBObject would be created. (For SFSB, the create() can take args !!!). The ejbCreate(String userId) in the bean would be called. It might have some code like - this.userId = userId. This associates the bean with the user, right ???
My item would be added to an arraylist in the bean class.

When I add another item to my cart, then would the home.create(String userId)be called again ? Then it would check for the userId attribute in the existing Bean classes, and find out that the bean is already created, and use the existing bean.

Is this how it works ???

Or, is it sth like, when the user logs in (or at some later point of time), a SFSB is associated for him. And we use that bean for all the items that he adds to the cart.

Please clarify.
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Ganesh.P Ram,

With SFSB, you will call home.create() only once.
It will give you a reference to your EJBObject, and you don't need more than one, you will only want one shopingcart during one session.

Your EJBObject probably will have a methode like:
addItemToShoppingCart(...);
and your bean will have to implement that method.

Herman
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ganesh,
I do not think calling the home.create() twice would check for an existing bean with the same userId. It would simply create another stateful bean and hand that to you. You should create the bean only once and then keep a reference to it in your session object. So the second time you want to add an item you call a method using the reference to the ejbobject that you stored in your session.

Arun N
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it better to keep a reference of the EJBObject itself or handle to the EJBObject ?
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think reference to EJBOject is better than handle as handle had to be deserialized(or something like that) to get EJBOject.

if you need to pass the stub then handle is sure useful.
but for just using beans in the sense for accesing them i think ejboject is useful and better than handle.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic