Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Work in Progress

This page is a work in progress. This info box will be removed once complete.

Postgres is configured by importing the configuration file persistence_postgres.xml in the OpenSRP spring configuration.


The file enables component scan for OpenSRP base package "org.opensrp" while excluding the CouchDb specific beans. This means that the CouchDb beans are not loaded in the spring container and are not candidate for dependency injection leaving only Postgres beans as the active beans.

The form submission model was not migrated to use Postgres.  Anyone using form submission model must first implement the Postgres repository beans before migrating to Postgres.

Technologies used

  • Mybatis library is used as the persistence framework.
  • Spring container managed transactions are used for transaction management
  • Tomcat JDBC pool is used as the pooled datasource

The documentation for each technology above is below respectively

persistence_postgres.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

	<context:component-scan base-package="org.opensrp">
		<context:exclude-filter type="regex"
			expression="org.opensrp.repository.couch.*" />
		<context:exclude-filter type="regex"
			expression="org.opensrp.repository.lucene.*" />
		<context:exclude-filter type="regex"
			expression="org.opensrp.scheduler.repository.couch.*" />
		<context:exclude-filter type="regex"
			expression="org.opensrp.service.formSubmission.FormSubmission..*" />
		<context:exclude-filter type="regex"
			expression="org.opensrp.service.formSubmission.ziggy.*" />
		<context:exclude-filter type="regex"
			expression="org.opensrp.service.FormSubmissionDataMigrationService" />
	</context:component-scan>

	<bean id="openSRPDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName" value="java:comp/env/jdbc/openSRPDB" />
	</bean>


	<tx:annotation-driven transaction-manager="openSRPTransactionManager" />
	<bean id="openSRPTransactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="openSRPDataSource" />
	</bean>

	<bean id="OpenSRPSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="openSRPDataSource" />
		<property name="typeAliasesPackage" value="org.opensrp.domain.postgres" />
		<property name="mapperLocations"
			value="classpath*:org/opensrp/repository/postgres/mapper/**/*.xml" />
	</bean>

	<bean id="OpenSRPSqlSession" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="OpenSRPSqlSessionFactory" />
	</bean>

	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage"
			value="org.opensrp.repository.postgres.mapper;org.opensrp.repository.postgres.mapper.custom" />
	</bean>
</beans>
  • No labels