commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/dbcp/xdocs/guide jndi-howto.xml
Date Wed, 16 Jun 2004 18:29:20 GMT
dirkv       2004/06/16 11:29:20

  Added:       dbcp/xdocs/guide jndi-howto.xml
  Log:
  instructions howto setup DBCP datasource inside a custom JNDI tree
  
  Revision  Changes    Path
  1.1                  jakarta-commons/dbcp/xdocs/guide/jndi-howto.xml
  
  Index: jndi-howto.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
   <!--
     Copyright 2002-2004 The Apache Software Foundation
  
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
         http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
    -->
  <document>
  
   <properties>
    <title>Developers Guide</title>
    <author email="commons-dev@jakarta.apache.org">Commons Documentation Team</author>
   </properties>
  
   <body>
  
  <section name="JNDI Howto">
  <p>
    The <a href="http://java.sun.com/products/jndi/">Java Naming and Directory Interface</a>

    (JNDI) is part of the Java platform, 
    providing applications based on Java technology with a unified interface to 
    multiple naming and directory services. You can build powerful and portable 
    directory-enabled applications using this industry standard.
  </p>
  <p>
    When you deploy your application inside an application server, the container will setup
    the JNDI tree for you. But if you are writing a framework or just a standalone application,
    then the following examples will show you how to construct and bind references to DBCP

    datasources.
  </p>
  <p>
    Another source of information is 
    <a href="http://incubator.apache.org/directory/subprojects/naming/index.html">Naming</a>.
    Naming includes an in-memory JNDI service provider that was extracted from the 
    <a href="http://jakarta.apache.org/tomcat/">Jakarta Tomcat</a> JNDI implementation.
    It also contains a easy way to construct a JNDI tree from an XML file and some ResourceFactories.
  </p>
  <p>
    The following examples are using the sun filesystem JNDI service provider.
    You can download it from the 
    <a href="http://java.sun.com/products/jndi/downloads/index.html">JNDI software download</a>
page.
  </p>
  <p>
    You can of course use the apache JNDI service provider by downloading the Naming core
jar.
    The initial context factory property should be changed to:
    org.apache.naming.java.javaURLContextFactory
  </p>
  </section>
  
  <section name="BasicDataSource">
  <source><![CDATA[
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
      "com.sun.jndi.fscontext.RefFSContextFactory");
    System.setProperty(Context.PROVIDER_URL, "file:///tmp");
    InitialContext ic = new InitialContext();
  
    // Construct BasicDataSource reference
    Reference ref = new Reference("javax.sql.DataSource",
      "org.apache.commons.dbcp.BasicDataSourceFactory", null);
    ref.add(new StringRefAddr("driverClassName", "org.apache.commons.dbcp.TesterDriver"));
    ref.add(new StringRefAddr("url", "jdbc:apache:commons:testdriver"));
    ref.add(new StringRefAddr("username", "username"));
    ref.add(new StringRefAddr("password", "password"));
    ic.rebind("jdbc/basic", ref);
     
    // Use
    InitialContext ic2 = new InitialContext();
    DataSource ds = (DataSource) ic2.lookup("jdbc/basic");
    assertNotNull(ds);
    Connection conn = ds.getConnection();
    assertNotNull(conn);
    conn.close();
  ]]></source>
  </section>
  
  <section name="PerUserPoolDataSource">
  <source><![CDATA[
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
      "com.sun.jndi.fscontext.RefFSContextFactory");
    System.setProperty(Context.PROVIDER_URL, "file:///tmp");
    InitialContext ic = new InitialContext();
  
    // Construct DriverAdapterCPDS reference
    Reference cpdsRef = new Reference("org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS",
      "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS", null);
    cpdsRef.add(new StringRefAddr("driver", "org.apache.commons.dbcp.TesterDriver"));
    cpdsRef.add(new StringRefAddr("url", "jdbc:apache:commons:testdriver"));
    cpdsRef.add(new StringRefAddr("user", "foo"));
    cpdsRef.add(new StringRefAddr("password", "bar"));
    ic.rebind("jdbc/cpds", cpdsRef);
       
    // Construct PerUserPoolDataSource reference
    Reference ref = new Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource",
      "org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory", null);
    ref.add(new StringRefAddr("dataSourceName", "jdbc/cpds"));
    ref.add(new StringRefAddr("defaultMaxActive", "100"));
    ref.add(new StringRefAddr("defaultMaxIdle", "30"));
    ref.add(new StringRefAddr("defaultMaxWait", "10000"));
    ic.rebind("jdbc/peruser", ref);
       
    // Use
    InitialContext ic2 = new InitialContext();
    DataSource ds = (DataSource) ic2.lookup("jdbc/peruser");
    assertNotNull(ds);
    Connection conn = ds.getConnection("foo","bar");
    assertNotNull(conn);
    conn.close();
  ]]></source>
  </section>
  
  </body>
  </document>
  
  
  

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


Mime
View raw message