You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2003/12/30 19:15:21 UTC

DO NOT REPLY [Bug 25827] New: - how to access data source when managing DB in a servlet?

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25827>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25827

how to access data source when managing DB in a servlet?

           Summary: how to access data source when managing DB in a servlet?
           Product: Struts
           Version: 1.1 Final
          Platform: Other
               URL: http://jakarta.apache.org/struts/faqs/database.html#mult
                    i_dsrc
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Documentation
        AssignedTo: struts-dev@jakarta.apache.org
        ReportedBy: hauser@acm.org


This is a documentation RFE.

Right now, the documentation describes how the datasources configured in
struts-config.xml can be accesses within each Action's execute method.

An alternative pattern is to handle all db-related matters in an own
public class Database extends ActionServlet { ...

In the Actions, I then obtain that db servlet object from the application scope
where I put it during init() with "servlet.getServletContext().getAttribute(
						Constants.DATABASE_KEY);"

What I would like to have documented is how to access the datasource (that is
not defined in server.xml as <Resource ... type="javax.sql.DataSource"/> but
only int the struts-config) during this init() where there is neither an Action
Object nor a "request" parameter yet.
As long as I have just one of them, I can "cheat" with
		BasicDataSource dataSource =
			(org.apache.commons.dbcp.BasicDataSource)
getServletContext().getAttribute(org.apache.struts.Globals.DATA_SOURCE_KEY);

But how would I do that if I have multiple datasources defined as per the above URL?

This will become especially important if one wants to use a read-write cluster
as per Bug 25511

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