LT-828

Externalise Database connections

Original implementation - Hostname to Environment

# Production
la-app*.aws.open.edu.au=prd

# Test
cruncher.dev.open.edu.au=test
cruncher=test

# Max
mac-0142.open.edu.au=max,dev
mac-0142=max,dev

# dev
*=dev

env.properties

<dependency>
  <groupId>au.edu.open</groupId>
  <artifactId>comp-envprofile</artifactId>
  <version>1.0.11</version>
</dependency>                

pom.xml

JAVA

<bean id="laWebCommonProperties"
 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 <property name="ignoreResourceNotFound" value="true" />
 <property name="placeholderPrefix" value="${la|"/>
 <property name="placeholderSuffix" value="}"/>
 <property name="locations">
  <list>
   <value>classpath:la.properties</value>
   <value>classpath:la_${env.mainProfile}.properties</value>
  </list>
 </property>
</bean>

spring.xml

Original implementation - Environment to properties

DataWarehouse=DataWarehouse_test
Database=Database_test

..._test.properties

# dev
DataWarehouse_dev=c3p0, db/db-dw-dev.properties, db/db-c3p0.properties
Database_dev=c3p0, db/db-db-dev.properties, db/db-c3p0.properties

# test 
DataWarehouse_test=c3p0, db/db-dw-dev.properties, db/db-c3p0.properties
Database_test=c3p0, db/db-db-test.properties, db/db-c3p0.properties

# prd
DataWarehouse_prd=c3p0, db/db-dw-prd.properties, db/db-c3p0.properties
Database_prd=c3p0, db/db-db-prd.properties, db/db-c3p0.properties

# max
DataWarehouse_max=c3p0, db/db-dw-dev.properties, db/db-c3p0.properties
Database_max=c3p0, db/db-db-max.properties, db/db-c3p0.properties

db-connections.properties

Original implementation - database connection

<dependency>
      <groupId>net.sf.jabb</groupId>
      <artifactId>jabb-core</artifactId>
      <version>1.0.53</version>
</dependency>

pom.xml

JAVA

.properties

url=jdbc:oracle:@db1.open.edu.au:1521/lasrv
user=dev6
password=Dev123

db-db-test.properties

<bean id="dsDatabase" class="net.sf.jabb.util.db.ConnectionUtility"
	factory-method="createDataSource">
	<constructor-arg value="${la|Database}" />
</bean>

<bean id="sfDatabase"
	class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
	<property name="dataSource" ref="dsDatabase" />
...
</bean>

spring.xml

Simple implementation 

<bean id="dataBaseProperties"
 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
 <property name="ignoreResourceNotFound" value="true" />
 <property name="placeholderPrefix" value="${database|"/>
 <property name="placeholderSuffix" value="}"/>
 <property name="locations">
   <list>
     <value>file:///${CATALINA_HOME}/la_conf/database.properties</value>
   </list>
 </property>
</bean>

<bean id="dsDatabase" class="org.apache.tomcat.jdbc.pool.DataSource"
 destroy-method="close">
 <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
 <property name="url" value="${database|url}" />
 <property name="username" value="${database|user}" />
 <property name="password" value="${database|password}" />
</bean>
url=jdbc:oracle:@db1.open.edu.au:1521/lasrv
user=dev6
password=Dev123

${CATALINA_HOME}/la_conf/database.properties

spring.xml

url=jdbc:oracle:@db1.open.edu.au:1521/lasrv
user=dev6
password=Dev123

Dev friendly implementation 

mvn clean tomcat7:run-war -Denv=tst

<bean id="dataBaseProperties"
 ...
 <property name="locations">
   <list>
     <value>classpath:/db/database_dev.properties</value>
     <value>classpath:/db/database_${env}.properties</value>
     <value>file:///${CATALINA_HOME}/la_conf/database.properties</value>
   </list>
 </property>
</bean>

<bean id="dsDatabase" 
...
</bean>

spring.xml

lt828

By aerondir

lt828

  • 874