Data Source
Container managed connection pool is used to connect to the Postgres database.
Tomcat JDBC pool is used as the connection pool. The connection pool is defined the configuration file context.xml
which and is initialized as a container managed resource. The connection pool must be packaged in the META_INF folder of a war file or jar file and is read and initialized before the spring context. Its managed by the container(tomcat) and not spring.
The connection pool is then registered as the datasource in spring application by using JNDI in the persistence_postgres.xml
as shown below
<bean id="openSRPDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/openSRPDB" />
</bean>
Note: the JNDI value java:comp/env/jdbc/openSRPDB
bean must match the Resource name jdbc/openSRPDB
.java:comp/env
is the node in the JNDI tree(in-memory global hashtable) where you can find properties for the current Java EE. JDNI resources must be prefixed with "java:comp/env
" when doing JNDI lookups by name
<Context> <Resource name="jdbc/openSRPDB" auth="Container" type="javax.sql.DataSource" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" initialSize="5" maxActive="55" maxIdle="21" minIdle="13" timeBetweenEvictionRunsMillis="34000" minEvictableIdleTimeMillis="55000" validationQuery="SELECT 1" validationInterval="34" testOnBorrow="true" removeAbandoned="true" removeAbandonedTimeout="233" username="opensrp_admin" password="admin" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/opensrp" /> </Context>
The parameters control how the connection pool and can be be tweeked further depending on environment and load. Use the documentation below to expore further advanced parameters
Tomcat JDBC Pool Documentation
This site is no longer maintained. Please visit docs.opensrp.io for current documentation.