Thanks! I think it's ok to pass the connection to the DAO instead of making
it "discover" the connection information.
Otavio
----- Original Message -----
From: "Tom Lister" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Wednesday, November 28, 2001 9:38 AM
Subject: RE: Accessing DATA_SOURCE_KEY on a DAO
> Hi
> My choice in the same situation was to get the datasource in the actions,
> actually implemented as a method in a base action I extend for everything
> else
> protected DataSource getDataSource() {
> javax.sql.DataSource dataSource =
>
(DataSource)servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY)
> ;
> return dataSource;
> }
> I then pass the datasource to my DAO,
> Code in action is like
> EntryDAO ed = (EntryDAO)DAOFactory.getDAO(DAOFactory.ENTRYDAO);
> try {
> ListForm ff = (ListForm)form;
> ff.setEntries(ed.getQueryObjects(ed.readDatabase(null,
> getDataSource(), QueryEngine.SELECTALL)));
> System.out.println("ListAction");
>
> I figure it's OK to tell the DAO about standard objects such as datasource
> but not how they were obtained.There is quite a bit of support in the
> BaseDAO I created for handling queries. The specific DAO only know how to
> provide a query string and convert a result set to set of associated
> ActionForm object. My DAO's inplement a QueryEngine interface.
>
> :-)
> Regards
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> Advanced Banking Solutions Limited
> +44 (0)20 7448 9146
>
> -----Original Message-----
> From: Otavio C. Decio [SMTP:[EMAIL PROTECTED]]
> Sent: 28 November 2001 14:05
> To: Struts Users Mailing List
> Subject: Accessing DATA_SOURCE_KEY on a DAO
>
> Hi,
>
> I was trying to find the best way to access the data source
> configured in
> web.xml from a Data Access Object, but I'm confused because it
> requires the
> DAO to know about servlets, since one has use the
> getServlet().getServletContext function to get the connection
> information.
>
> Do you know of a better alternative?
>
> Thanks!
>
> Otavio
>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>