You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andreas Leitner <al...@macron.at> on 2001/07/25 11:59:50 UTC

DataSource and Factories

Hi again,

I would like to seperate my buisness logic from the data layer. Say I
have an object Person, that has the fields id, firstName and lastName.
The only constructor I provide is one which takes two arguments (id,
firstName and lastName). The person objects will be stored in a certain
Database, but this may change in the future, this is why I use a
factory. The factory takes an id, connects to the DB, retrieves the
data, creates the Person object and returns it. 

This pattern also comes in handy, when you have classes that inherit
from Person. If the DB access would happen in the constructor, one could
only create Person objects, with a factory, you can create an object of
the real type instead.

Anyway, what I want is to get a DataSource without knowing about a
servlet. Is this somehow possible? Is there some static access to the
DataSource Repository?

Tia,
Andreas


AW: DataSource and Factories

Posted by Andreas Leitner <al...@macron.at>.

> Take a look to the Castor project -
> http://castor.exolab.org

That does indeed look awesome! Do you have experience with it? Is it
ready for production use? Many thanks for that great hint!


Andreas


Re: DataSource and Factories

Posted by Oleg V Alexeev <oa...@apache.org>.
Hello Andreas,

Wednesday, July 25, 2001, 1:59:50 PM, you wrote:


AL> Hi again,

AL> I would like to seperate my buisness logic from the data layer. Say I
AL> have an object Person, that has the fields id, firstName and lastName.
AL> The only constructor I provide is one which takes two arguments (id,
AL> firstName and lastName). The person objects will be stored in a certain
AL> Database, but this may change in the future, this is why I use a
AL> factory. The factory takes an id, connects to the DB, retrieves the
AL> data, creates the Person object and returns it. 

AL> This pattern also comes in handy, when you have classes that inherit
AL> from Person. If the DB access would happen in the constructor, one could
AL> only create Person objects, with a factory, you can create an object of
AL> the real type instead.

AL> Anyway, what I want is to get a DataSource without knowing about a
AL> servlet. Is this somehow possible? Is there some static access to the
AL> DataSource Repository?

Take a look to the Castor project -
http://castor.exolab.org

-- 
Best regards,
 Oleg                            mailto:oalexeev@apache.org



AW: Accessing nested attributes using

Posted by Andreas Leitner <al...@macron.at>.

> -----Ursprüngliche Nachricht-----
> Von: David Winterfeldt [mailto:dwinterfeldt@yahoo.com] 
> Gesendet: Mittwoch, 25. Juli 2001 22:57
> An: struts-user@jakarta.apache.org
> Betreff: Re: Accessing nested attributes using <bean:write>
> 
> 
> This is the same as getFather().getName().  You can
> also use nested properties for html:text and all the
> other Struts tags.
> 
> <bean:write name="bean" property="father.name"/>
> 
> Arrays are supported to.
> <bean:write name="bean" property="name[0]"/>

Silly me, I tried that of course as it seemed obvious. But I got an
error, now I discovered that the error was related to another class.
Unfortunatly the error told me "No Such Method" - given that it was late
already yesterday, I must have confused things.

Thanks for your help,
Andreas
PS: Also thanks to the other ppl. that responded.


Re: Accessing nested attributes using

Posted by David Winterfeldt <dw...@yahoo.com>.
This is the same as getFather().getName().  You can
also use nested properties for html:text and all the
other Struts tags.

<bean:write name="bean" property="father.name"/>

Arrays are supported to.
<bean:write name="bean" property="name[0]"/>

David

--- Andreas Leitner <al...@macron.at> wrote:
> 
> Now, this may be a really stupid question and may
> not even fit this
> list. If that's the case please give me a hint where
> I could look for an
> answere.
> 
> I can render a property of a bean using
> <bean:write>, but what if I want
> to render to a property, but a property of a
> property?
> 
> Imagine the class:
> Person
> 	String name;
> 	Person father;
> 
> If I have a given person instance in a bean named
> "foo", I can render
> it's name via
> <bean:write name="bean" property="name"/>
> But how can I render the name of foo's father?
> 
> Many thanks in advance,
> Andreas
> 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

Accessing nested attributes using

Posted by Andreas Leitner <al...@macron.at>.
Now, this may be a really stupid question and may not even fit this
list. If that's the case please give me a hint where I could look for an
answere.

I can render a property of a bean using <bean:write>, but what if I want
to render to a property, but a property of a property?

Imagine the class:
Person
	String name;
	Person father;

If I have a given person instance in a bean named "foo", I can render
it's name via
<bean:write name="bean" property="name"/>
But how can I render the name of foo's father?

Many thanks in advance,
Andreas


Re: DataSource and Factories

Posted by suhas <su...@techmas.hcltech.com>.
DataSource can be obtained either Deployment descriptor as
"java:comp/jdbc/MyDataSource"
(associate a Jndi name to the Datasource
)


----- Original Message -----
From: Andreas Leitner <al...@macron.at>
To: <st...@jakarta.apache.org>; 'Aapo Laakkonen'
<aa...@projectcast.com>
Sent: Wednesday, July 25, 2001 3:29 PM
Subject: DataSource and Factories


>
> Hi again,
>
> I would like to seperate my buisness logic from the data layer. Say I
> have an object Person, that has the fields id, firstName and lastName.
> The only constructor I provide is one which takes two arguments (id,
> firstName and lastName). The person objects will be stored in a certain
> Database, but this may change in the future, this is why I use a
> factory. The factory takes an id, connects to the DB, retrieves the
> data, creates the Person object and returns it.
>
> This pattern also comes in handy, when you have classes that inherit
> from Person. If the DB access would happen in the constructor, one could
> only create Person objects, with a factory, you can create an object of
> the real type instead.
>
> Anyway, what I want is to get a DataSource without knowing about a
> servlet. Is this somehow possible? Is there some static access to the
> DataSource Repository?
>
> Tia,
> Andreas
>