Hello, Well, if you want to change Ur datasource parameters without redeploying ur application, I guess you Either go for JMX, or (but I m not sure if this will work nicely), or avoid getting ur datasource from struts config. For example, write a struts plugin that initializes ur 'Datasource component' and stores it into the ServletContext (application scope)
Write your HTML front end that under the hood will change ur component stored into the ServletContext.. Any of ur components that need to access the datasource will need to get it >From your 'datasource component' This are my 0.02$, cannot go further since I don't know ur application Hope this helps Regards Marco You could expose the component that is in charge of 'creating' or 'accessing' the -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 21 September 2004 11:22 To: [EMAIL PROTECTED] Subject: Smart DataSource management (WAS: Assigning a DataSource to a Business Delegate on startup) In fact I need to do something more. Suppose that I want to distribute my application, and the destination has a different DBMS (well at least he/she has a different username and password...). I think that configuring the context.xml file for a non-technical person is a bit difficult, and I wish to give an HTML front-end. Within one of my applications, I successfully managed to modify the "struts-config.xml" in the "data-sources" part, but to see the changes, I have to reload the application (ugly thing). If I use the "context.xml" (correct me if I am wrong) I have to redeploy the application (well at least I have to reload it). Another problem that I encountered is that when I have not the JDBC driver class specified in a "data-source" entry (neither in the "lib" directory, nor in the Java "ext" directory") the Struts application, in its entirety, fails to load. Now, how can I do to re-configure data sources without app reload? I am thinking about grabbing part of Struts code to make a "data source manager" and a simple web front-end. But, is there anything already done? (hopefully open source...) Maybe I got a bit off-topic ;-) Ciao Antonio Petrelli > JNDI is not tied to Tomcat, but you have to set the datasource inside > the container (for example Tomcat). > In Tomcat, in order to set a datasource inside the application you have > to deploy with your application the following "context.xml" file inside > the "meta-inf" directory: > > <Context path="/ApplicationContextPath"> > <Resource name="jdbc/DatabaseSource" auth="Container" > type="javax.sql.DataSource"/> > <ResourceParams name="jdbc/DatabaseSource"> > <parameter> > <name>maxWait</name> > <value>5000</value> > </parameter> > <parameter> > <name>maxActive</name> > <value>100</value> > </parameter> > <parameter> > <name>password</name> > <value>manager</value> > </parameter> > <parameter> > <name>url</name> > <value>jdbc:oracle:thin:@127.0.0.1:1521:OracleDB</value> > </parameter> > <parameter> > <name>driverClassName</name> > <value>oracle.jdbc.driver.OracleDriver</value> > </parameter> > <parameter> > <name>maxIdle</name> > <value>20</value> > </parameter> > <parameter> > <name>username</name> > <value>system</value> > </parameter> > </ResourceParams> > > </Context> > If you use an Oracle DB. > > Note that: > - this datasource is available only for the application and not for all > Tomcat applications. > If you want to use a global datasource you can use the Tomcat web > amministration tool. > > - You have to know the url of the DB server. But you can set it using > the Tomcat web amministration tool. > > BR > /Amleto > > > > -----Messaggio originale----- > Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Inviato: marted́ 21 settembre 2004 11.32 > A: [EMAIL PROTECTED] > Oggetto: Re: Assigning a DataSource to a Business Delegate on startup > > > > you can use JNDI to get a DataSource (if you use tomcat see tomcat > > documentation in order to set the datasource). Here an example code to > > > use inside the singleton object: > > > > //Get DB from JNDI > > try { > > Context initCtx = new InitialContext(); > > Context envCtx = (Context) initCtx.lookup("java:comp/env"); > > DataSource dataSource = (DataSource) > > envCtx.lookup("jdbc/DatabaseSource"); > > > > } catch ( NamingException e ) { > > //Handle Source Code Exception > > } > > > > This is a nice solution, but I would like to use the DataSource > configuration in struts-config.xml. I noticed that there is the > "ConfigHelper.getDataSource()" method to get the default data source, > but I want to use a DataSource that I mapped with a key. By the way, the > solution above is not too tied to Tomcat? What if I want to distribute > my application? Do I have to configure Tomcat on the other machine? Ciao > Antonio Petrelli > > > > > > > > > -----Messaggio originale----- > > Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > Inviato: marted́ 21 settembre 2004 11.11 > > A: [EMAIL PROTECTED] > > Oggetto: Assigning a DataSource to a Business Delegate on startup > > > > > > Hello there, > > is there a way I can assign a DataSource to a singleton object (i.e. a > > > Business Delegate) on startup? I know there is the "getDataSource" > > protected method in Action, but I have to pass the DataSource itself > > on each call of the delegate, or I have to check whether it has been > > already passed or not. Maybe it could be done with a plugin. In this > > case, is there already a package that I could use? And if not, how can > > > I access to a DataSource outside the Action class? Thanks in advance > > Ciao Antonio Petrelli > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]