You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alen Ribic <al...@mweb.co.za> on 2003/06/20 15:53:26 UTC

How much should Struts be aware of my persistence system

Hi all

Where do you think is the best place to initialise your persistence, ORM,
system in Struts?
Action classes, etc.?
I would like to make the Struts framework least aware of my Persistence
system.

I'm using OJB with PB API and Struts 1.1.

Apparently, best practice, when using OJB PB API is to create an instance of
Broker before executing business command and then close the Broker after
execution.


Any ideas as to what particular design I should implement here to get most
out of role separation?

--Alen



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How much should Struts be aware of my persistence system

Posted by Erik Price <ep...@ptc.com>.

Alen Ribic wrote:
> Hi all
> 
> Where do you think is the best place to initialise your persistence, ORM,
> system in Struts?
> Action classes, etc.?
> I would like to make the Struts framework least aware of my Persistence
> system.

One place (easy to set up) is to just create a static initializer block 
in one of your classes that does this when the class is loaded.  This is 
fine for a simple singleton but you might want more fine-grained control 
over it -- in which case you might want to implement 
ServletContextListener interface for context notifications.

> I'm using OJB with PB API and Struts 1.1.
> 
> Apparently, best practice, when using OJB PB API is to create an instance of
> Broker before executing business command and then close the Broker after
> execution.
> 
> 
> Any ideas as to what particular design I should implement here to get most
> out of role separation?

You can wrap this activity into a facade.  I don't use OJB, but my 
approach has been to create an object to represent a business object in 
my application.  The constructor of this object uses a DAO factory to 
create a DAO, to which it delegates all of the work.  The DAO uses JDBC, 
but I could easily create a new DAO that uses OJB or JDO or Hibernate or 
even EJB.  This way my Actions can simply refer to this facade object 
and the facade object handles the details -- yet I can always substitute 
a different DAO or even remove DAOs from the picture altogether without 
making changes to my Action code.

This seems to be a pretty common design, I have seen it described in 
many places and on this list.



Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How much should Struts be aware of my persistence system

Posted by Alen Ribic <al...@mweb.co.za>.
sounds good.
I was thinking something along those lines of indirection.
--Alen



----- Original Message -----
From: "Michael Thompson" <Mi...@Sun.COM>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, June 20, 2003 4:24 PM
Subject: Re: How much should Struts be aware of my persistence system


> Ahhhh, didn't quite catch that.  I don't know that I'd be putting that
> kind of knowledge(OJB) in my struts actions.  I'd probably wrap that up
> behind some interface.
>
> public interface FooManager
> {
> public Collection getFoos()
> throws SomeKindOfPersistenceExcpetion;
> }
>
> Struts Action would grab and instance of FooManager (JNDI, Factory,
> singletons, whatever) and call getFoos().
>
> getFoos implementation would do all OJB specific stuff.
>
> Right/Wrong whatever... just my $0.02...
>
> --m
>
>
> Alen Ribic wrote:
> > Hi Michael
> >
> > Thanks for your response.
> >
> > Do you mean a global object reference that will be shared by all user
> > invocations?
> > If so, that will not work in my case because I need a new instance for
each
> > separate action method invocation.
> > That's suppose to be best practice for when using OJB persistence
system.
> >
> > OJB-user list question from me...
> > <snippet>
> >
> >>Where do you suggest for the instantiation of Persistence
> >>Broker to reside?
> >
> > For maximum scalability try to keep instantiation and closing of a
broker
> > instance as close together as possible. best thing is to open a broker
at
> > the beginning of a command and to close it at the end (in a finally
block to
> > make sure it really is called!)
> > </snippet>
> >
> > --Alen
> >
> >
> >
> > ----- Original Message -----
> > From: "Michael Thompson" <Mi...@Sun.COM>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Friday, June 20, 2003 3:59 PM
> > Subject: Re: How much should Struts be aware of my persistence system
> >
> >
> >
> >>I've done stuff like this in a javax.servlet.ServletContextListener.
> >>
> >>the contextInitialized method gets called when the app is ready to
> >>recieve reqs, so initialization of "global" objects can be done there.
> >>
> >>There may be a way to do it in a more struts like fashion...
> >>--m
> >>
> >>
> >>Alen Ribic wrote:
> >>
> >>>Hi all
> >>>
> >>>Where do you think is the best place to initialise your persistence,
> >>
> > ORM,
> >
> >>>system in Struts?
> >>>Action classes, etc.?
> >>>I would like to make the Struts framework least aware of my Persistence
> >>>system.
> >>>
> >>>I'm using OJB with PB API and Struts 1.1.
> >>>
> >>>Apparently, best practice, when using OJB PB API is to create an
> >>
> > instance of
> >
> >>>Broker before executing business command and then close the Broker
after
> >>>execution.
> >>>
> >>>
> >>>Any ideas as to what particular design I should implement here to get
> >>
> > most
> >
> >>>out of role separation?
> >>>
> >>>--Alen
> >>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How much should Struts be aware of my persistence system

Posted by Laurent PETIT <lp...@sqli.com>.
Hello,

Take a look at Mapper, a new project in the Commons-Sandbox  at apache :

http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/mapper/

--
Laurent

----- Original Message -----
From: "Michael Thompson" <Mi...@Sun.COM>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, June 20, 2003 3:24 PM
Subject: Re: How much should Struts be aware of my persistence system


> Ahhhh, didn't quite catch that.  I don't know that I'd be putting that
> kind of knowledge(OJB) in my struts actions.  I'd probably wrap that up
> behind some interface.
>
> public interface FooManager
> {
> public Collection getFoos()
> throws SomeKindOfPersistenceExcpetion;
> }
>
> Struts Action would grab and instance of FooManager (JNDI, Factory,
> singletons, whatever) and call getFoos().
>
> getFoos implementation would do all OJB specific stuff.
>
> Right/Wrong whatever... just my $0.02...
>
> --m
>
>
> Alen Ribic wrote:
> > Hi Michael
> >
> > Thanks for your response.
> >
> > Do you mean a global object reference that will be shared by all user
> > invocations?
> > If so, that will not work in my case because I need a new instance for
each
> > separate action method invocation.
> > That's suppose to be best practice for when using OJB persistence
system.
> >
> > OJB-user list question from me...
> > <snippet>
> >
> >>Where do you suggest for the instantiation of Persistence
> >>Broker to reside?
> >
> > For maximum scalability try to keep instantiation and closing of a
broker
> > instance as close together as possible. best thing is to open a broker
at
> > the beginning of a command and to close it at the end (in a finally
block to
> > make sure it really is called!)
> > </snippet>
> >
> > --Alen
> >
> >
> >
> > ----- Original Message -----
> > From: "Michael Thompson" <Mi...@Sun.COM>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Friday, June 20, 2003 3:59 PM
> > Subject: Re: How much should Struts be aware of my persistence system
> >
> >
> >
> >>I've done stuff like this in a javax.servlet.ServletContextListener.
> >>
> >>the contextInitialized method gets called when the app is ready to
> >>recieve reqs, so initialization of "global" objects can be done there.
> >>
> >>There may be a way to do it in a more struts like fashion...
> >>--m
> >>
> >>
> >>Alen Ribic wrote:
> >>
> >>>Hi all
> >>>
> >>>Where do you think is the best place to initialise your persistence,
> >>
> > ORM,
> >
> >>>system in Struts?
> >>>Action classes, etc.?
> >>>I would like to make the Struts framework least aware of my Persistence
> >>>system.
> >>>
> >>>I'm using OJB with PB API and Struts 1.1.
> >>>
> >>>Apparently, best practice, when using OJB PB API is to create an
> >>
> > instance of
> >
> >>>Broker before executing business command and then close the Broker
after
> >>>execution.
> >>>
> >>>
> >>>Any ideas as to what particular design I should implement here to get
> >>
> > most
> >
> >>>out of role separation?
> >>>
> >>>--Alen
> >>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How much should Struts be aware of my persistence system

Posted by Michael Thompson <Mi...@Sun.COM>.
Ahhhh, didn't quite catch that.  I don't know that I'd be putting that 
kind of knowledge(OJB) in my struts actions.  I'd probably wrap that up 
behind some interface.

public interface FooManager
{
	public Collection getFoos()
		throws SomeKindOfPersistenceExcpetion;
}

Struts Action would grab and instance of FooManager (JNDI, Factory, 
singletons, whatever) and call getFoos().

getFoos implementation would do all OJB specific stuff.

Right/Wrong whatever... just my $0.02...

	--m


Alen Ribic wrote:
> Hi Michael
> 
> Thanks for your response.
> 
> Do you mean a global object reference that will be shared by all user
> invocations?
> If so, that will not work in my case because I need a new instance for each
> separate action method invocation.
> That's suppose to be best practice for when using OJB persistence system.
> 
> OJB-user list question from me...
> <snippet>
> 
>>Where do you suggest for the instantiation of Persistence
>>Broker to reside?
> 
> For maximum scalability try to keep instantiation and closing of a broker
> instance as close together as possible. best thing is to open a broker at
> the beginning of a command and to close it at the end (in a finally block to
> make sure it really is called!)
> </snippet>
> 
> --Alen
> 
> 
> 
> ----- Original Message -----
> From: "Michael Thompson" <Mi...@Sun.COM>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Friday, June 20, 2003 3:59 PM
> Subject: Re: How much should Struts be aware of my persistence system
> 
> 
> 
>>I've done stuff like this in a javax.servlet.ServletContextListener.
>>
>>the contextInitialized method gets called when the app is ready to
>>recieve reqs, so initialization of "global" objects can be done there.
>>
>>There may be a way to do it in a more struts like fashion...
>>--m
>>
>>
>>Alen Ribic wrote:
>>
>>>Hi all
>>>
>>>Where do you think is the best place to initialise your persistence,
>>
> ORM,
> 
>>>system in Struts?
>>>Action classes, etc.?
>>>I would like to make the Struts framework least aware of my Persistence
>>>system.
>>>
>>>I'm using OJB with PB API and Struts 1.1.
>>>
>>>Apparently, best practice, when using OJB PB API is to create an
>>
> instance of
> 
>>>Broker before executing business command and then close the Broker after
>>>execution.
>>>
>>>
>>>Any ideas as to what particular design I should implement here to get
>>
> most
> 
>>>out of role separation?
>>>
>>>--Alen
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How much should Struts be aware of my persistence system

Posted by Alen Ribic <al...@mweb.co.za>.
Hi Michael

Thanks for your response.

Do you mean a global object reference that will be shared by all user
invocations?
If so, that will not work in my case because I need a new instance for each
separate action method invocation.
That's suppose to be best practice for when using OJB persistence system.

OJB-user list question from me...
<snippet>
> Where do you suggest for the instantiation of Persistence
> Broker to reside?
For maximum scalability try to keep instantiation and closing of a broker
instance as close together as possible. best thing is to open a broker at
the beginning of a command and to close it at the end (in a finally block to
make sure it really is called!)
</snippet>

--Alen



----- Original Message -----
From: "Michael Thompson" <Mi...@Sun.COM>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, June 20, 2003 3:59 PM
Subject: Re: How much should Struts be aware of my persistence system


> I've done stuff like this in a javax.servlet.ServletContextListener.
>
> the contextInitialized method gets called when the app is ready to
> recieve reqs, so initialization of "global" objects can be done there.
>
> There may be a way to do it in a more struts like fashion...
> --m
>
>
> Alen Ribic wrote:
> > Hi all
> >
> > Where do you think is the best place to initialise your persistence,
ORM,
> > system in Struts?
> > Action classes, etc.?
> > I would like to make the Struts framework least aware of my Persistence
> > system.
> >
> > I'm using OJB with PB API and Struts 1.1.
> >
> > Apparently, best practice, when using OJB PB API is to create an
instance of
> > Broker before executing business command and then close the Broker after
> > execution.
> >
> >
> > Any ideas as to what particular design I should implement here to get
most
> > out of role separation?
> >
> > --Alen
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How much should Struts be aware of my persistence system

Posted by Michael Thompson <Mi...@Sun.COM>.
I've done stuff like this in a javax.servlet.ServletContextListener.

the contextInitialized method gets called when the app is ready to 
recieve reqs, so initialization of "global" objects can be done there.

There may be a way to do it in a more struts like fashion...
	--m


Alen Ribic wrote:
> Hi all
> 
> Where do you think is the best place to initialise your persistence, ORM,
> system in Struts?
> Action classes, etc.?
> I would like to make the Struts framework least aware of my Persistence
> system.
> 
> I'm using OJB with PB API and Struts 1.1.
> 
> Apparently, best practice, when using OJB PB API is to create an instance of
> Broker before executing business command and then close the Broker after
> execution.
> 
> 
> Any ideas as to what particular design I should implement here to get most
> out of role separation?
> 
> --Alen
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How much should Struts be aware of my persistence system

Posted by Alen Ribic <al...@mweb.co.za>.
thanks. reading throught...

----- Original Message -----
From: "Mike Jasnowski" <mj...@bea.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, June 20, 2003 3:57 PM
Subject: RE: How much should Struts be aware of my persistence system


> Have you looked at the Business Delegate pattern I think it's called? that
> might be what you're looking for.
>
> -----Original Message-----
> From: Alen Ribic [mailto:alenr@bea.com]
> Sent: Friday, June 20, 2003 9:53 AM
> To: Struts Users Mailing List
> Subject: How much should Struts be aware of my persistence system
>
>
> Hi all
>
> Where do you think is the best place to initialise your persistence, ORM,
> system in Struts?
> Action classes, etc.?
> I would like to make the Struts framework least aware of my Persistence
> system.
>
> I'm using OJB with PB API and Struts 1.1.
>
> Apparently, best practice, when using OJB PB API is to create an instance
of
> Broker before executing business command and then close the Broker after
> execution.
>
>
> Any ideas as to what particular design I should implement here to get most
> out of role separation?
>
> --Alen
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: How much should Struts be aware of my persistence system

Posted by Mike Jasnowski <mj...@bea.com>.
Have you looked at the Business Delegate pattern I think it's called? that
might be what you're looking for.

-----Original Message-----
From: Alen Ribic [mailto:alenr@bea.com]
Sent: Friday, June 20, 2003 9:53 AM
To: Struts Users Mailing List
Subject: How much should Struts be aware of my persistence system


Hi all

Where do you think is the best place to initialise your persistence, ORM,
system in Struts?
Action classes, etc.?
I would like to make the Struts framework least aware of my Persistence
system.

I'm using OJB with PB API and Struts 1.1.

Apparently, best practice, when using OJB PB API is to create an instance of
Broker before executing business command and then close the Broker after
execution.


Any ideas as to what particular design I should implement here to get most
out of role separation?

--Alen



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org