|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.mguennewig.pobjects.jdbc.ContainerPool
de.mguennewig.pobjects.jdbc.JndiContainerPool
public class JndiContainerPool
Provides a pool of JdbcContainer that uses JNDI to get connections.
To use this JNDI Container pool with Tomcat you have to define up to 3
things in the servlets Context block within Tomcat's
server.xml file. Which then have to be referenced from the
servlets web.xml file.
/sourceDataSource to use to get database connections./containerJdbcContainer instance that works together
with the configured database.
/schemaAn example servlet.xml configuration could look similar to
this:
<Resource name="jdbc/pobjtest/source" auth="Container"
type="javax.sql.DataSource" />
<ResourceParams name="jdbc/pobjtest/source">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/pobjtest?autoReconnect=true</value>
</parameter>
<parameter>
<name>username</name>
<value>pobjtest</value>
</parameter>
<parameter>
<name>password</name>
<value />
</parameter>
</ResourceParams>
<Environment name="jdbc/pobjtest/container" type="java.lang.String"
value="de.mguennewig.pobjects.jdbc.MySQLContainer" />
The corresponding web.xml file sections would look like
this:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/pobjtest/source</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<env-entry>
<description>DB Container</description>
<env-entry-name>jdbc/pobjtest/container</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
To use the above configured database, get an instance of this pool within your servlet in the following way:
ContainerPool pool =
new JndiContainerPool(dictionary, "java:/comp/env/jdbc/pobjtest");
| Constructor Summary | |
|---|---|
JndiContainerPool(PObjDictionary dict,
java.lang.String jndiName)
Creates a new JNDI base container pool. |
|
| Method Summary |
|---|
| Methods inherited from class de.mguennewig.pobjects.jdbc.ContainerPool |
|---|
freeConnection, freeContainer, getConnection, getContainer, getDictionary, getSchema |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JndiContainerPool(PObjDictionary dict,
java.lang.String jndiName)
throws javax.naming.NamingException
The data source resource must be named
<jndiName>/source, the schema name resource
<jndiName>/schema and the container class name resource
<jndiName>/container.
javax.naming.NamingException - if any JNDI error occurs.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||