You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2002/12/29 02:19:48 UTC

cvs commit: jakarta-struts/doc/userGuide configuration.xml building_model.xml

husted      2002/12/28 17:19:48

  Modified:    doc/userGuide configuration.xml building_model.xml
  Log:
  Combine pieces from Model and Configuration to create Accessing a Database HowTo.
  
  Revision  Changes    Path
  1.9       +5 -88     jakarta-struts/doc/userGuide/configuration.xml
  
  Index: configuration.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/doc/userGuide/configuration.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- configuration.xml	29 Dec 2002 00:02:06 -0000	1.8
  +++ configuration.xml	29 Dec 2002 01:19:48 -0000	1.9
  @@ -401,96 +401,13 @@
       whatever DataSource implementation works best with your container or 
       database. 
       </p>
  -      
  -    <p>
  -    This is how you would specify a default data source for your application
  -    inside of struts-config.xml:
  -    </p>
  -
  -<pre><code><![CDATA[
  -<data-sources>
  -<!-- configuration for GenericDataSource wrapper -->
  -<data-source>
  -  <set-property
  -    property="autoCommit"
  -    value="false"/>
  -  <set-property
  -    property="description"
  -    value="Example Data Source Configuration"/>
  -  <set-property
  -    property="driverClass"
  -    value="org.postgresql.Driver"/>
  -  <set-property
  -    property="maxCount"
  -    value="4"/>
  -  <set-property
  -    property="minCount"
  -    value="2"/>
  -  <set-property
  -    property="password"
  -    value="mypassword"/>
  -  <set-property
  -    property="url"
  -    value="jdbc:postgresql://localhost/mydatabase"/>
  -  <set-property
  -    property="user"
  -    value="myusername"/>
  -</data-source>
  -</data-sources>
  -]]></code></pre>
  -
  -    <p>
  -    This is how you would specify a DBCP BasicDataSource for your application:
  -    </p>
  -
  -<pre><code><![CDATA[
  -<data-sources>
  -<!-- configuration for commons BasicDataSource -->
  -<data-source type="org.apache.commons.dbcp.BasicDataSource">
  -    <set-property
  -      property="driverClassName"
  -      value="org.postgresql.Driver" />
  -    <set-property
  -      property="url"
  -      value="jdbc:postgresql://localhost/mydatabase" />
  -    <set-property
  -      property="maxActive"
  -      value="10" />
  -    <set-property
  -      property="maxWait"
  -      value="5000" />
  -    <set-property
  -      property="defaultAutoCommit"
  -      value="false" />
  -    <set-property
  -      property="defaultReadOnly"
  -      value="false" />
  -
  -</data-source>
  -</data-sources>
  -]]></code></pre>
  -
  -    <p>
  -    For information on how to retrieve the data source, see the
  -    <a href="building_model.html#databases">Accessing Relational Databases</a>
  -    section.
  -    </p>
  -
  -    <p>
  -    <i>Note: Since Struts is now using commons-dbcp for all it's data-source
  -    needs, the query you provide for the pingQuery attribute must return at
  -    least one row.</i>
  -    </p>
  -
  +    
       <p>
  -    <b>Example:</b> <code>SELECT COUNT(*) FROM VALIDTABLE</code>
  +    For examples of specifying a data-sources element and using the 
  +    DataSource with an Action, see the 
  +    <a href="../faqs/database.html">Accessing a Database HowTo</a>.
       </p>
  -
  -    <p>
  -    Just be sure you to replace "VALIDTABLE" with the name of a valid table
  -    in your database.
  -    </p>
  -
  +      
   </section>
   
   <section 
  
  
  
  1.16      +2 -75     jakarta-struts/doc/userGuide/building_model.xml
  
  Index: building_model.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/doc/userGuide/building_model.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- building_model.xml	28 Dec 2002 22:33:09 -0000	1.15
  +++ building_model.xml	29 Dec 2002 01:19:48 -0000	1.16
  @@ -11,7 +11,6 @@
       <author>Mike Schachter</author>
       <author>Ted Husted</author>
       <author>Martin Cooper</author>
  -    <author>Ed Burns</author>
       <title>The Struts User's Guide - Building Model Components</title>
   </properties>
   
  @@ -265,82 +264,10 @@
       For larger applications, these beans will often be stateful or stateless 
       Enterprise JavaBeans (EJBs) instead.
       </p>
  -
  -</section>
  -
  -<section name="2.6 Accessing Relational Databases" href="databases">
  -
  -    <p>
  -    Ideally, the business logic beans should encapsulate the data access
  -    details, including acquiring a database connection. 
  -    However, some application designs expect that the caller able to provide a
  -    with a database connection or datasource instance. 
  -    When this is the case, the Struts datasource manager can make it easy for 
  -    your Action to produce these resources on demand.
  -    </p>
  -    
  -    <p>
  -    The Struts datasource manager is configured as an element in the
  -    <a href="configuration.html#data-source_config">
  -    Struts configuration file</a> (struts-config.xml). 
  -    The manager can used to deploy any connection pool that implements the
  -    <code>javax.sql.DataSource</code> interface and is configurable totally
  -    from JavaBean properties. 
  -    If your DBMS or container provides a connection pool that meets these 
  -    requirements, then that component might your first choice.
  -    </p>
  -
  -    <p>
  -    The Jakarta Commons dbcp's BasicDataSource 
  -    [<code>org.apache.commons.dbcp.BasicDataSource</code>] also works well 
  -    with the datasource manager, if a native component is not available. 
  -    The Struts distribution includes a Generic DataSource class in its util
  -    package, but this is now only a wrapper around the BasicDataSource. 
  -    The GenericDataSource class is deprecated as of Struts 1.1 and replaced 
  -    by direct use of the BasicDataSource.
  -    </p>
       
       <p>
  -    After the datasource is defined, here is an example of using the
  -    manger to establishing a connection from within an Action's 
  -    <code>execute</code> method.
  -    </p>
  -
  -<pre><code>
  -public ActionForward
  -       execute(ActionMapping mapping,
  -               ActionForm form,
  -               HttpServletRequest request,
  -               HttpServletResponse response) throws Exception
  -{
  - javax.sql.DataSource dataSource;
  - java.sql.Connection myConnection;
  -
  - try {
  -   dataSource = getDataSource(request);
  -   myConnection = dataSource.getConnection();
  -
  -   //do what you wish with myConnection
  - } catch (SQLException sqle) {
  -   getServlet().log("Connection.process", sqle);
  - } finally {
  -
  -   //enclose this in a finally block to make
  -   //sure the connection is closed
  -   try {
  -     myConnection.close();
  -   } catch (SQLException e) {
  -     getServlet().log("Connection.close", e);
  -   }
  - }
  -}
  -</code></pre>
  -
  -    <p>
  -    Note that you can define as many datasource objects as your application 
  -    requires and refer to each using a logical name. 
  -    This can be useful in providing better security or scalability, or even 
  -    to test datasource implementations against each other.
  +    For more about using a database with your application, see the 
  +    <a href="../faqs/database.html">Accessing a Database HowTo</a>.
       </p>
   
       <p align="center">
  
  
  

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