Re: entity beans within an Action

2001-04-04 Thread G.L. Grobe

So would I have to do a setAttribute to store every session? Is there
someway to uniquely identify each session by it's attribute name, or how is
that often handled, since I think I'm going to have to give it a unique name
for each setAttribute.?

Thnxs for the responses.

- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 03, 2001 8:54 AM
Subject: RE: entity beans within an Action


> Hi Gary,
>
> To keep track of a stateful session bean (or any other object for that
> matter) across multiple requests, you will need to store its reference in
> the session using setAttribute(). You will also need to perform a check in
> the Action each time a request is processed to see if that object already
> exists- use getAttribute() and see if it returns null, and if so then
create
> it. I suppose there are other ways to do this, but this is probably the
most
> direct way to do it.  Keep in mind that stateful session EJBs might be
> overkill for what you are trying to accomplish.  You could just gather
input
> and populate your same ActionForm using multiple input forms- then when
the
> last form is submitted write the changes to the entity EJB. You will still
> need a session EJB to do this properly, with methods like saveUser() and
> getUser(), but there is no need to make it stateful. You should consider
> stateful if you need to write the changes after each input form is
> completed- if you can't wait until the last page is submitted.
>
> Regarding the field-to-field copies from an ActionForm to an Entity bean.
> This is the way I am doing things and it is working out nicely.  Just make
> sure you name your fields the same and use the Struts
> PropertyUtils.copyProperties() method to do this work for you if possible.
> It would work even better if copyProperties could make simple type
> conversions :) Some may oppose this design- having the session EJB be
aware
> of the ActionForm- since it somewhat couples the presentation to business,
> so if this bugs you then you could use an interface instead- let the
session
> EJB be aware of the interface instead of a specific ActionForm (more
details
> on this were posted by someone else a while back- last week I think). One
> thing you should not do is perform the copy operations from within the
> Action. Make sure you pass the entire data structure (i.e. the ActionForm)
> to a session EJB and let the session EJB invoke all the setters/getters on
> the entity EJB- either directly or via the Struts copy util.
>
> One short note on stateful session EJBs too... Some avoid using them for
> performance reasons. If you are building a high demand site then you may
> want to avoid using them. They can't be shared and pooled the same way
> stateless beans can- just make sure you really understand the lifecycle
> before you use them. I can't speak from personal experience on this,
perhaps
> someone else can, but this is just what I hear through the grapevine. I am
> sure a lot depends on what EJB container you use as well.
>
> -Bob
>
>
>
> -----Original Message-
> From: G.L. Grobe [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 03, 2001 1:43 AM
> To: [EMAIL PROTECTED]
> Subject: Re: entity beans within an Action
>
>
> Comments and questions below.
>
> - Original Message -
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, April 02, 2001 10:23 PM
> Subject: RE: entity beans within an Action
>
> > Creation of EJBs is really the job of the EJB container. The container
> > manages the creation, passivation, destruction, etc... of the EJBs. When
> you
> > "create" an EJB from your Action for example, you are just asking the
> > container for a reference. Of course there is some overhead with looking
> up
> > the bean's home interface and creating the stubs- but this should be
> > negligible (compared with instantiation of the actual entity bean).
> However,
> > If you know that many requests within the same session will need access
to
> > the same entity bean(s), you could create a stateful session bean and
keep
> > track of its reference in the session.
>
> I have an Action that spans multiple pages. I have only one ActionForm
class
> to go w/ this Action for the multiple pages, so the user makes multiple
> submits on the same ActionForm.
>
> This part I don't get. If I've done a lookup and gotten the reference of
> this stateful session bean, how is that returned reference kept for the
next
> time the Action is called, afterall, the Action was destroyed. Must I do
> another lookup everytime the Action is called to get the reference to the
> session bean? I can 

RE: entity beans within an Action

2001-04-03 Thread rhayden

Hi Gary,

To keep track of a stateful session bean (or any other object for that
matter) across multiple requests, you will need to store its reference in
the session using setAttribute(). You will also need to perform a check in
the Action each time a request is processed to see if that object already
exists- use getAttribute() and see if it returns null, and if so then create
it. I suppose there are other ways to do this, but this is probably the most
direct way to do it.  Keep in mind that stateful session EJBs might be
overkill for what you are trying to accomplish.  You could just gather input
and populate your same ActionForm using multiple input forms- then when the
last form is submitted write the changes to the entity EJB. You will still
need a session EJB to do this properly, with methods like saveUser() and
getUser(), but there is no need to make it stateful. You should consider
stateful if you need to write the changes after each input form is
completed- if you can't wait until the last page is submitted.

Regarding the field-to-field copies from an ActionForm to an Entity bean.
This is the way I am doing things and it is working out nicely.  Just make
sure you name your fields the same and use the Struts
PropertyUtils.copyProperties() method to do this work for you if possible.
It would work even better if copyProperties could make simple type
conversions :) Some may oppose this design- having the session EJB be aware
of the ActionForm- since it somewhat couples the presentation to business,
so if this bugs you then you could use an interface instead- let the session
EJB be aware of the interface instead of a specific ActionForm (more details
on this were posted by someone else a while back- last week I think). One
thing you should not do is perform the copy operations from within the
Action. Make sure you pass the entire data structure (i.e. the ActionForm)
to a session EJB and let the session EJB invoke all the setters/getters on
the entity EJB- either directly or via the Struts copy util.

One short note on stateful session EJBs too... Some avoid using them for
performance reasons. If you are building a high demand site then you may
want to avoid using them. They can't be shared and pooled the same way
stateless beans can- just make sure you really understand the lifecycle
before you use them. I can't speak from personal experience on this, perhaps
someone else can, but this is just what I hear through the grapevine. I am
sure a lot depends on what EJB container you use as well.

-Bob



-Original Message-
From: G.L. Grobe [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 03, 2001 1:43 AM
To: [EMAIL PROTECTED]
Subject: Re: entity beans within an Action


Comments and questions below.

- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 02, 2001 10:23 PM
Subject: RE: entity beans within an Action

> Creation of EJBs is really the job of the EJB container. The container
> manages the creation, passivation, destruction, etc... of the EJBs. When
you
> "create" an EJB from your Action for example, you are just asking the
> container for a reference. Of course there is some overhead with looking
up
> the bean's home interface and creating the stubs- but this should be
> negligible (compared with instantiation of the actual entity bean).
However,
> If you know that many requests within the same session will need access to
> the same entity bean(s), you could create a stateful session bean and keep
> track of its reference in the session.

I have an Action that spans multiple pages. I have only one ActionForm class
to go w/ this Action for the multiple pages, so the user makes multiple
submits on the same ActionForm.

This part I don't get. If I've done a lookup and gotten the reference of
this stateful session bean, how is that returned reference kept for the next
time the Action is called, afterall, the Action was destroyed. Must I do
another lookup everytime the Action is called to get the reference to the
session bean? I can understand how the session bean itself can hold a
reference to the entity bean, since the stateful session bean itself
persists.

Also, I guess as the last step in my conversation it's ok to do regular
field-to-field copies of the ActionForm data into the entity bean.

After writing all this out trying to explain it to you guys, I think I've
just answered my question and am looking for a "yes, you're on the right
track" or "no, it's usually done like this" kind of answer. I only need to
lookup and create the entity bean at the very end of the session, all in one
method, so after the session ends, my entity beans info will still be around
for use for the backend servers part of my application. Now I'm just
wondering where I'd put the business logic to handle those beans once they
get status c

Re: entity beans within an Action

2001-04-02 Thread G.L. Grobe

Comments and questions below.

- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, April 02, 2001 10:23 PM
Subject: RE: entity beans within an Action

> Creation of EJBs is really the job of the EJB container. The container
> manages the creation, passivation, destruction, etc... of the EJBs. When
you
> "create" an EJB from your Action for example, you are just asking the
> container for a reference. Of course there is some overhead with looking
up
> the bean's home interface and creating the stubs- but this should be
> negligible (compared with instantiation of the actual entity bean).
However,
> If you know that many requests within the same session will need access to
> the same entity bean(s), you could create a stateful session bean and keep
> track of its reference in the session.

I have an Action that spans multiple pages. I have only one ActionForm class
to go w/ this Action for the multiple pages, so the user makes multiple
submits on the same ActionForm.

This part I don't get. If I've done a lookup and gotten the reference of
this stateful session bean, how is that returned reference kept for the next
time the Action is called, afterall, the Action was destroyed. Must I do
another lookup everytime the Action is called to get the reference to the
session bean? I can understand how the session bean itself can hold a
reference to the entity bean, since the stateful session bean itself
persists.

Also, I guess as the last step in my conversation it's ok to do regular
field-to-field copies of the ActionForm data into the entity bean.

After writing all this out trying to explain it to you guys, I think I've
just answered my question and am looking for a "yes, you're on the right
track" or "no, it's usually done like this" kind of answer. I only need to
lookup and create the entity bean at the very end of the session, all in one
method, so after the session ends, my entity beans info will still be around
for use for the backend servers part of my application. Now I'm just
wondering where I'd put the business logic to handle those beans once they
get status changes from backend servers since I no longer have user Actions?

It seems like there would be so many exampes of what I'm trying to do, but
I've seen no full examples of *both* session beans implementing entity beans
within an Action. (i.e. A user goes shopping (session) and puts is stuff in
a cart (entity)).

> From within the stateful session bean
> you can create once and keep track of the entity beans and won't need to
do
> JNDI lookups, etc... for each request... At least that is the way I would
do
> it :)
>
> -Bob
>
>
>
> -Original Message-
> From: G.L. Grobe [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 02, 2001 7:12 PM
> To: [EMAIL PROTECTED]
> Subject: entity beans within an Action
>
>
> If the life-span of an Action is only when that Action is being exec'd
> (which is also where I implemented my session bean since it's life-span is
> also not neccesary to hang around), where should entity beans be
initialized
> and populated by data held in the ActionForm bean? Seems if I init'd them
> within the Action, I'd be creating a new Bean everytime it ran through
that
> Action, same w/ the session. Am I going about this wrong?
>
> Any help much appreciated.
>




RE: entity beans within an Action

2001-04-02 Thread rhayden


Creation of EJBs is really the job of the EJB container. The container
manages the creation, passivation, destruction, etc... of the EJBs. When you
"create" an EJB from your Action for example, you are just asking the
container for a reference. Of course there is some overhead with looking up
the bean's home interface and creating the stubs- but this should be
negligible (compared with instantiation of the actual entity bean). However,
If you know that many requests within the same session will need access to
the same entity bean(s), you could create a stateful session bean and keep
track of its reference in the session. From within the stateful session bean
you can create once and keep track of the entity beans and won't need to do
JNDI lookups, etc... for each request... At least that is the way I would do
it :)

-Bob

 

-Original Message-
From: G.L. Grobe [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 02, 2001 7:12 PM
To: [EMAIL PROTECTED]
Subject: entity beans within an Action


If the life-span of an Action is only when that Action is being exec'd
(which is also where I implemented my session bean since it's life-span is
also not neccesary to hang around), where should entity beans be initialized
and populated by data held in the ActionForm bean? Seems if I init'd them
within the Action, I'd be creating a new Bean everytime it ran through that
Action, same w/ the session. Am I going about this wrong?

Any help much appreciated.



entity beans within an Action

2001-04-02 Thread G.L. Grobe

If the life-span of an Action is only when that Action is being exec'd
(which is also where I implemented my session bean since it's life-span is
also not neccesary to hang around), where should entity beans be initialized
and populated by data held in the ActionForm bean? Seems if I init'd them
within the Action, I'd be creating a new Bean everytime it ran through that
Action, same w/ the session. Am I going about this wrong?

Any help much appreciated.