You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Lowe <ma...@libero.it> on 2002/12/17 09:03:33 UTC

dataSources outside of actionservlet

hello

you'll all have to forgive my stupidity but i've been having real problems
trying to reference the datasource specified in config.xml in my business
logic classes.

I've been very good and seperated everything as one should. but i really
need a straight answer to this (i.e. an example that works).

"For maximum code re-use, business logic beans should be designed and
implemented so that they do not know they are being executed in a web
application environment"

now i've only seen examples referencing the datasource inside an action
servlet, this appears to go against the design pattern. So how do i do this?
have i neglected to find the correct example? why are all the examples of
how to reference the datasource breaking the aforementioned priciple? please
i'm very confused ..

many thanks in advance

mark




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: dataSources outside of actionservlet

Posted by Mark <ma...@libero.it>.
Thanks keith that looks like a really good elegant way of doing this, but as
i conceded before I particularly stupid, and i don't get it. To be honest
I've always had the db pooling stuff taken care for me before which was only
of the attractions of using struts..

Is there no means to referencing to setting in config.xml. Like  an example
that explains the following

Stuff_to_get_to_the_stuff_configxml.getDatasource(mykey);

Or am i trying to make my life too simple and really should give up
development and become a dustman or something?

Many thanks again mark


On 17-12-2002 15:12, "keithBacon" <ke...@yahoo.com> wrote:

> Using the command design pattern you can ensure the DB code needs to be coded
> only once.
> See the example below
> 
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg24579.html
> 
> 
> --- Matthias Bauer <Ma...@livinglogic.de> wrote:
>> The normal thing to is the following: You aquire a database connection
>> in the action class and pass it on as a parameter to the bean's database
>> methods.
>> 
>> --- Matthias
>> 
>> Mark wrote:
>> 
>>> Sorry to repost this question, but the more i think about it the more i
>>> think it a reasonable one (please tell me if i'm wrong).
>>> 
>>> 
>>> ------ Forwarded Message
>>> From: "Mark Lowe" <ma...@libero.it>
>>> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>>> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>>> Subject: dataSources outside of actionservlet
>>> 
>>> hello
>>> 
>>> you'll all have to forgive my stupidity but i've been having real problems
>>> trying to reference the datasource specified in config.xml in my business
>>> logic classes.
>>> 
>>> I've been very good and seperated everything as one should. but i really
>>> need a straight answer to this (i.e. an example that works).
>>> 
>>> "For maximum code re-use, business logic beans should be designed and
>>> implemented so that they do not know they are being executed in a web
>>> application environment"
>>> 
>>> now i've only seen examples referencing the datasource inside an action
>>> servlet, this appears to go against the design pattern. So how do i do this?
>>> have i neglected to find the correct example? why are all the examples of
>>> how to reference the datasource breaking the aforementioned priciple? please
>>> i'm very confused ..
>>> 
>>> many thanks in advance
>>> 
>>> mark
>>> 
>>> 
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>>> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail:
>>> <ma...@jakarta.apache.org>
>>> 
>>> 
>>> 
>>> ------ End of Forwarded Message
>>> 
>>> 
>>> --
>>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>> 
>>>  
>>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>> For additional commands, e-mail: <ma...@jakarta.apache.org>
>> 
> 
> 
> =====
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Search the archive:-
> http://www.mail-archive.com/struts-user%40jakarta.apache.org/
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Keith Bacon - Looking for struts work - South-East UK.
> phone UK 07960 011275
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FW: dataSources outside of actionservlet

Posted by keithBacon <ke...@yahoo.com>.
Using the command design pattern you can ensure the DB code needs to be coded
only once.
See the example below 

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg24579.html


--- Matthias Bauer <Ma...@livinglogic.de> wrote:
> The normal thing to is the following: You aquire a database connection 
> in the action class and pass it on as a parameter to the bean's database 
> methods.
> 
> --- Matthias
> 
> Mark wrote:
> 
> >Sorry to repost this question, but the more i think about it the more i
> >think it a reasonable one (please tell me if i'm wrong).
> >
> >
> >------ Forwarded Message
> >From: "Mark Lowe" <ma...@libero.it>
> >Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> >Date: Tue, 17 Dec 2002 09:03:33 +0100
> >To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> >Subject: dataSources outside of actionservlet
> >
> >hello
> >
> >you'll all have to forgive my stupidity but i've been having real problems
> >trying to reference the datasource specified in config.xml in my business
> >logic classes.
> >
> >I've been very good and seperated everything as one should. but i really
> >need a straight answer to this (i.e. an example that works).
> >
> >"For maximum code re-use, business logic beans should be designed and
> >implemented so that they do not know they are being executed in a web
> >application environment"
> >
> >now i've only seen examples referencing the datasource inside an action
> >servlet, this appears to go against the design pattern. So how do i do this?
> >have i neglected to find the correct example? why are all the examples of
> >how to reference the datasource breaking the aforementioned priciple? please
> >i'm very confused ..
> >
> >many thanks in advance
> >
> >mark
> >
> >
> >
> >
> >--
> >To unsubscribe, e-mail:
> ><ma...@jakarta.apache.org>
> >For additional commands, e-mail:
> ><ma...@jakarta.apache.org>
> >
> >
> >
> >------ End of Forwarded Message
> >
> >
> >--
> >To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> >For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >  
> >
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search the archive:-
http://www.mail-archive.com/struts-user%40jakarta.apache.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Bacon - Looking for struts work - South-East UK.
phone UK 07960 011275

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: dataSources outside of actionservlet

Posted by Mark <ma...@libero.it>.
Woohoo!!! 

But you'll have to forgive my ignorance, but any chance of a more ostensive
answer, like an example for example..

So something like 

DataSource ds = getDatasource("mykey");

(MyBEan).doSomething(ds, and other args);

Is this along the right lines?

Many thanks

mark

On 17-12-2002 15:05, "Matthias Bauer" <Ma...@livinglogic.de> wrote:

> The normal thing to is the following: You aquire a database connection
> in the action class and pass it on as a parameter to the bean's database
> methods.
> 
> --- Matthias
> 
> Mark wrote:
> 
>> Sorry to repost this question, but the more i think about it the more i
>> think it a reasonable one (please tell me if i'm wrong).
>> 
>> 
>> ------ Forwarded Message
>> From: "Mark Lowe" <ma...@libero.it>
>> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>> Date: Tue, 17 Dec 2002 09:03:33 +0100
>> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>> Subject: dataSources outside of actionservlet
>> 
>> hello
>> 
>> you'll all have to forgive my stupidity but i've been having real problems
>> trying to reference the datasource specified in config.xml in my business
>> logic classes.
>> 
>> I've been very good and seperated everything as one should. but i really
>> need a straight answer to this (i.e. an example that works).
>> 
>> "For maximum code re-use, business logic beans should be designed and
>> implemented so that they do not know they are being executed in a web
>> application environment"
>> 
>> now i've only seen examples referencing the datasource inside an action
>> servlet, this appears to go against the design pattern. So how do i do this?
>> have i neglected to find the correct example? why are all the examples of
>> how to reference the datasource breaking the aforementioned priciple? please
>> i'm very confused ..
>> 
>> many thanks in advance
>> 
>> mark
>> 
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>> 
>> 
>> 
>> ------ End of Forwarded Message
>> 
>> 
>> --
>> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>> For additional commands, e-mail: <ma...@jakarta.apache.org>
>> 
>>  
>> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FW: dataSources outside of actionservlet

Posted by Matthias Bauer <Ma...@livinglogic.de>.
The normal thing to is the following: You aquire a database connection 
in the action class and pass it on as a parameter to the bean's database 
methods.

--- Matthias

Mark wrote:

>Sorry to repost this question, but the more i think about it the more i
>think it a reasonable one (please tell me if i'm wrong).
>
>
>------ Forwarded Message
>From: "Mark Lowe" <ma...@libero.it>
>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>Date: Tue, 17 Dec 2002 09:03:33 +0100
>To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>Subject: dataSources outside of actionservlet
>
>hello
>
>you'll all have to forgive my stupidity but i've been having real problems
>trying to reference the datasource specified in config.xml in my business
>logic classes.
>
>I've been very good and seperated everything as one should. but i really
>need a straight answer to this (i.e. an example that works).
>
>"For maximum code re-use, business logic beans should be designed and
>implemented so that they do not know they are being executed in a web
>application environment"
>
>now i've only seen examples referencing the datasource inside an action
>servlet, this appears to go against the design pattern. So how do i do this?
>have i neglected to find the correct example? why are all the examples of
>how to reference the datasource breaking the aforementioned priciple? please
>i'm very confused ..
>
>many thanks in advance
>
>mark
>
>
>
>
>--
>To unsubscribe, e-mail:
><ma...@jakarta.apache.org>
>For additional commands, e-mail:
><ma...@jakarta.apache.org>
>
>
>
>------ End of Forwarded Message
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>  
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: FW: dataSources outside of actionservlet

Posted by keithBacon <ke...@yahoo.com>.
Hi mark,
It is a good question! 
I've not used them so far but i think the new java Properties class is designed
to supply config. info to a system.
If you have a command processor class that gets the connection maybe you should
make it's name a property so you can have a different class in the web env.
from other env?
hth - I'n not n expert on this stuff - just in case no=one else replies!
K.


--- Mark <ma...@libero.it> wrote:
> I'm really sorry to post this mail again,, but is there something i'm not
> understanding ? Or does everyone do all their queries in action servlets?
> 
> I can see how what i'm trying could be wrong in that, if i want to reuse my
> non servlet classes using the datasource in config.xml might render this
> webappliction-specific.
> 
> But then again it is also true that using the settings in the config file
> has a certain appeal especially if one is looking at supporting more than
> one db vendor. 
> 
> I understand that perhaps i need to have a pool of connections, but i want
> to leave this stuff as an optimisation rather than a means of getting to the
> settings in config.xml.
> 
> -- here's my original message--
> hello
> 
> you'll all have to forgive my stupidity but i've been having real problems
> trying to reference the datasource specified in config.xml in my business
> logic classes.
> 
> I've been very good and seperated everything as one should. but i really
> need a straight answer to this (i.e. an example that works).
> 
> "For maximum code re-use, business logic beans should be designed and
> implemented so that they do not know they are being executed in a web
> application environment"
> 
> now i've only seen examples referencing the datasource inside an action
> servlet, this appears to go against the design pattern. So how do i do this?
> have i neglected to find the correct example? why are all the examples of
> how to reference the datasource breaking the aforementioned priciple? please
> i'm very confused ..
> --
> 
> many thanks in advance
> 
> mark
> 
> 
> 
> Many thanks in advance
> 
> mark
> 
> 
> ------ Forwarded Message
> From: Mark <ma...@libero.it>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Tue, 17 Dec 2002 11:18:25 +0100
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: FW: dataSources outside of actionservlet
> 
> Sorry to repost this question, but the more i think about it the more i
> think it a reasonable one (please tell me if i'm wrong).
> 
> 
> ------ Forwarded Message
> From: "Mark Lowe" <ma...@libero.it>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Tue, 17 Dec 2002 09:03:33 +0100
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Subject: dataSources outside of actionservlet
> 
> hello
> 
> you'll all have to forgive my stupidity but i've been having real problems
> trying to reference the datasource specified in config.xml in my business
> logic classes.
> 
> I've been very good and seperated everything as one should. but i really
> need a straight answer to this (i.e. an example that works).
> 
> "For maximum code re-use, business logic beans should be designed and
> implemented so that they do not know they are being executed in a web
> application environment"
> 
> now i've only seen examples referencing the datasource inside an action
> servlet, this appears to go against the design pattern. So how do i do this?
> have i neglected to find the correct example? why are all the examples of
> how to reference the datasource breaking the aforementioned priciple? please
> i'm very confused ..
> 
> many thanks in advance
> 
> mark
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> ------ End of Forwarded Message
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> ------ End of Forwarded Message
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Search the archive:-
http://www.mail-archive.com/struts-user%40jakarta.apache.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keith Bacon - Looking for struts work - South-East UK.
phone UK 07960 011275

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


FW: dataSources outside of actionservlet

Posted by Mark <ma...@libero.it>.
I'm really sorry to post this mail again,, but is there something i'm not
understanding ? Or does everyone do all their queries in action servlets?

I can see how what i'm trying could be wrong in that, if i want to reuse my
non servlet classes using the datasource in config.xml might render this
webappliction-specific.

But then again it is also true that using the settings in the config file
has a certain appeal especially if one is looking at supporting more than
one db vendor. 

I understand that perhaps i need to have a pool of connections, but i want
to leave this stuff as an optimisation rather than a means of getting to the
settings in config.xml.

-- here's my original message--
hello

you'll all have to forgive my stupidity but i've been having real problems
trying to reference the datasource specified in config.xml in my business
logic classes.

I've been very good and seperated everything as one should. but i really
need a straight answer to this (i.e. an example that works).

"For maximum code re-use, business logic beans should be designed and
implemented so that they do not know they are being executed in a web
application environment"

now i've only seen examples referencing the datasource inside an action
servlet, this appears to go against the design pattern. So how do i do this?
have i neglected to find the correct example? why are all the examples of
how to reference the datasource breaking the aforementioned priciple? please
i'm very confused ..
--

many thanks in advance

mark



Many thanks in advance

mark


------ Forwarded Message
From: Mark <ma...@libero.it>
Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Date: Tue, 17 Dec 2002 11:18:25 +0100
To: Struts Users Mailing List <st...@jakarta.apache.org>
Subject: FW: dataSources outside of actionservlet

Sorry to repost this question, but the more i think about it the more i
think it a reasonable one (please tell me if i'm wrong).


------ Forwarded Message
From: "Mark Lowe" <ma...@libero.it>
Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Date: Tue, 17 Dec 2002 09:03:33 +0100
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Subject: dataSources outside of actionservlet

hello

you'll all have to forgive my stupidity but i've been having real problems
trying to reference the datasource specified in config.xml in my business
logic classes.

I've been very good and seperated everything as one should. but i really
need a straight answer to this (i.e. an example that works).

"For maximum code re-use, business logic beans should be designed and
implemented so that they do not know they are being executed in a web
application environment"

now i've only seen examples referencing the datasource inside an action
servlet, this appears to go against the design pattern. So how do i do this?
have i neglected to find the correct example? why are all the examples of
how to reference the datasource breaking the aforementioned priciple? please
i'm very confused ..

many thanks in advance

mark




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



------ End of Forwarded Message


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



------ End of Forwarded Message


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


FW: dataSources outside of actionservlet

Posted by Mark <ma...@libero.it>.
Sorry to repost this question, but the more i think about it the more i
think it a reasonable one (please tell me if i'm wrong).


------ Forwarded Message
From: "Mark Lowe" <ma...@libero.it>
Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Date: Tue, 17 Dec 2002 09:03:33 +0100
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Subject: dataSources outside of actionservlet

hello

you'll all have to forgive my stupidity but i've been having real problems
trying to reference the datasource specified in config.xml in my business
logic classes.

I've been very good and seperated everything as one should. but i really
need a straight answer to this (i.e. an example that works).

"For maximum code re-use, business logic beans should be designed and
implemented so that they do not know they are being executed in a web
application environment"

now i've only seen examples referencing the datasource inside an action
servlet, this appears to go against the design pattern. So how do i do this?
have i neglected to find the correct example? why are all the examples of
how to reference the datasource breaking the aforementioned priciple? please
i'm very confused ..

many thanks in advance

mark




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



------ End of Forwarded Message


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>