1. What is Connection Pool? A connection pool contains a group of JDBC connections that are created when the connection pool is registered—when starting up WebLogic Server or when deploying the connection pool to a target server or cluster. Connection pools use a JDBC driver to create physical database connections. Your application borrows a connection from the pool, uses it, then returns it to the pool by closing it. 2. Create a Connection Pool on Geronimo a) Login to Geronimo Console (E.g.: http://192.168.70.17/console). b) In Navigator, click ‘Datasources’, then click the link ‘Using the Geronimo database pool wizard‘. c) Select

  • Name
  • Database: Choose PostgreSQL XA
  • Click Next.

Capture d) Select Driver, JAR, Parameters.

  • Reference to jdbc.properties file.
  • Then, click Deploy

Untitled

  • Here is result:

Untitled e) Test connection pool with simple query. Capture 3. Configure project a) In web.xml

  • In web.xml insert a resource-ref section declaring the database pool.
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!-- servlets and mappings and normal web.xml stuff here
-->
<resource-ref>
<res-ref-name>jdbc/MyDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

b) In geronimo-web.xml

  • In WEB-INF/geronimo-web.xml 
  • The geronimo-web.xml plan should have a dependency element pointing to the database pool module, and a resource-ref block corresponding to the web.xml resource-ref above, which maps the resource reference to a specific database pool.
  • In that block, the ref-name must match the res-ref-name from the web.xml (above) and the resource-link must point to the database pool by name.
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1">
<environment>
<moduleId>
<artifactId>MyWebApp</artifactId>
</moduleId>
<dependencies>
<dependency>
<groupId>console.dbpool</groupId>
<artifactId>test-system-aavn</artifactId>
</dependency>
</dependencies>
</environment>
<context-root>/TestSystem</context-root>
<resource-ref>
<ref-name>jdbc/MyDataSource</ref-name>
<resource-link>test-system-aavn</resource-link>
</resource-ref>
</web-app>

c) In hibernate-context.xml

  • In application configuration, here we need to declare a new datasource that reference to the connection pool.
<jee:jndi-lookup id="dataSource" jndiname="
java:comp/env/jdbc/MyDataSource" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>

Reference: