dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18366
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7717: Replaced statement manager with jdbc template in patient module.
------------------------------------------------------------
revno: 7717
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-07-26 15:53:44 +0700
message:
Replaced statement manager with jdbc template in patient module.
modified:
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/jdbc/JdbcActivityPlanStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/jdbc/JdbcActivityPlanStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/jdbc/JdbcActivityPlanStore.java 2012-06-20 08:57:27 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/activityplan/jdbc/JdbcActivityPlanStore.java 2012-07-26 08:53:44 +0000
@@ -28,17 +28,16 @@
package org.hisp.dhis.activityplan.jdbc;
import java.sql.ResultSet;
-import java.sql.Statement;
+import java.sql.SQLException;
import java.util.Collection;
-import java.util.HashSet;
-import org.amplecode.quick.StatementHolder;
-import org.amplecode.quick.StatementManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.activityplan.ActivityPlanStore;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.patient.startup.TableAlteror;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
/**
* @author Chau Thu Tran
@@ -54,7 +53,7 @@
// Dependency
// -------------------------------------------------------------------------
- private StatementManager statementManager;
+ private JdbcTemplate jdbcTemplate;
private StatementBuilder statementBuilder;
@@ -62,9 +61,9 @@
// Setters
// -------------------------------------------------------------------------
- public void setStatementManager( StatementManager statementManager )
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
{
- this.statementManager = statementManager;
+ this.jdbcTemplate = jdbcTemplate;
}
public void setStatementBuilder( StatementBuilder statementBuilder )
@@ -79,33 +78,30 @@
@Override
public Collection<Integer> getActivitiesByProvider( Integer orgunitId, int min, int max )
{
- StatementHolder holder = statementManager.getHolder();
-
- Collection<Integer> programStageInstanceIds = new HashSet<Integer>();
try
{
- Statement statement = holder.getStatement();
-
String sql = "SELECT distinct psi.programstageinstanceid " + "FROM programstageinstance psi "
+ "INNER JOIN programinstance pi " + "ON pi.programinstanceid = psi.programinstanceid "
+ "INNER JOIN programstage ps " + "ON ps.programstageid=psi.programstageid "
+ "INNER JOIN program_organisationunits po " + "ON po.programid=pi.programid "
+ "INNER JOIN program pg " + "ON po.programid=pg.programid " + "WHERE pi.completed = FALSE "
- + "AND pg.type=1 " + "AND po.organisationunitid = " + orgunitId
- + " AND psi.completed = FALSE " + "AND ps.stageinprogram in ( SELECT min(ps1.stageinprogram) "
- + "FROM programstageinstance psi1 " + "INNER JOIN programinstance pi1 "
- + "ON pi1.programinstanceid = psi1.programinstanceid " + "INNER JOIN programstage ps1 "
- + "ON ps1.programstageid=psi1.programstageid " + "INNER JOIN program_organisationunits po1 "
- + "ON po1.programid=pi1.programid " + "WHERE pi1.completed = FALSE " + "AND po1.organisationunitid = "
- + orgunitId + " AND psi1.completed = FALSE ) " + "ORDER BY ps.stageinprogram "
+ + "AND pg.type=1 " + "AND po.organisationunitid = " + orgunitId + " AND psi.completed = FALSE "
+ + "AND ps.stageinprogram in ( SELECT min(ps1.stageinprogram) " + "FROM programstageinstance psi1 "
+ + "INNER JOIN programinstance pi1 " + "ON pi1.programinstanceid = psi1.programinstanceid "
+ + "INNER JOIN programstage ps1 " + "ON ps1.programstageid=psi1.programstageid "
+ + "INNER JOIN program_organisationunits po1 " + "ON po1.programid=pi1.programid "
+ + "WHERE pi1.completed = FALSE " + "AND po1.organisationunitid = " + orgunitId
+ + " AND psi1.completed = FALSE ) " + "ORDER BY ps.stageinprogram "
+ statementBuilder.limitRecord( min, max );
- ResultSet resultSet = statement.executeQuery( sql );
-
- while ( resultSet.next() )
+ Collection<Integer> programStageInstanceIds = jdbcTemplate.query( sql, new RowMapper<Integer>()
{
- programStageInstanceIds.add( resultSet.getInt( 1 ) );
- }
+ public Integer mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ return rs.getInt( 1 );
+ }
+ } );
return programStageInstanceIds;
@@ -113,54 +109,35 @@
catch ( Exception ex )
{
log.debug( ex );
-
return null;
}
- finally
- {
- holder.close();
- }
}
@Override
public int countActivitiesByProvider( Integer orgunitId )
{
- StatementHolder holder = statementManager.getHolder();
-
try
{
- Statement statement = holder.getStatement();
-
String sql = "SELECT count(distinct psi.programstageinstanceid) " + "FROM programstageinstance psi "
+ "INNER JOIN programinstance pi " + "ON pi.programinstanceid = psi.programinstanceid "
+ "INNER JOIN programstage ps " + "ON ps.programstageid=psi.programstageid "
+ "INNER JOIN program_organisationunits po " + "ON po.programid=pi.programid "
+ "INNER JOIN program pg " + "ON po.programid=pg.programid " + "WHERE pi.completed = FALSE "
- + "AND pg.type=1 " + "AND po.organisationunitid = " + orgunitId
- + " AND psi.completed = FALSE " + "AND ps.stageinprogram in ( SELECT min(ps1.stageinprogram) "
- + "FROM programstageinstance psi1 " + "INNER JOIN programinstance pi1 "
- + "ON pi1.programinstanceid = psi1.programinstanceid " + "INNER JOIN programstage ps1 "
- + "ON ps1.programstageid=psi1.programstageid " + "INNER JOIN program_organisationunits po1 "
- + "ON po1.programid=pi1.programid " + "WHERE pi1.completed = FALSE " + "AND po1.organisationunitid = "
- + orgunitId + " AND psi1.completed = FALSE ) ";
-
- ResultSet resultSet = statement.executeQuery( sql );
- if ( resultSet.next() )
- {
- return resultSet.getInt( 1 );
- }
-
- return 0;
+ + "AND pg.type=1 " + "AND po.organisationunitid = " + orgunitId + " AND psi.completed = FALSE "
+ + "AND ps.stageinprogram in ( SELECT min(ps1.stageinprogram) " + "FROM programstageinstance psi1 "
+ + "INNER JOIN programinstance pi1 " + "ON pi1.programinstanceid = psi1.programinstanceid "
+ + "INNER JOIN programstage ps1 " + "ON ps1.programstageid=psi1.programstageid "
+ + "INNER JOIN program_organisationunits po1 " + "ON po1.programid=pi1.programid "
+ + "WHERE pi1.completed = FALSE " + "AND po1.organisationunitid = " + orgunitId
+ + " AND psi1.completed = FALSE ) ";
+
+ return jdbcTemplate.queryForInt( sql );
}
catch ( Exception ex )
{
ex.printStackTrace();
return 0;
}
- finally
- {
- holder.close();
- }
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java 2012-03-16 07:50:14 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/jdbc/JdbcCaseAggregationConditionStore.java 2012-07-26 08:53:44 +0000
@@ -28,19 +28,18 @@
package org.hisp.dhis.caseaggregation.jdbc;
import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
+import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
-import org.amplecode.quick.StatementHolder;
-import org.amplecode.quick.StatementManager;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
import org.hisp.dhis.caseaggregation.CaseAggregationConditionStore;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.hibernate.HibernateGenericStore;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
/**
* @author Chau Thu Tran
@@ -55,15 +54,15 @@
// Dependency
// -------------------------------------------------------------------------
- private StatementManager statementManager;
+ private JdbcTemplate jdbcTemplate;
// -------------------------------------------------------------------------
// Setters
// -------------------------------------------------------------------------
- public void setStatementManager( StatementManager statementManager )
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
{
- this.statementManager = statementManager;
+ this.jdbcTemplate = jdbcTemplate;
}
// -------------------------------------------------------------------------
@@ -73,54 +72,41 @@
@Override
public List<Integer> executeSQL( String sql )
{
- StatementHolder holder = statementManager.getHolder();
-
- List<Integer> patientIds = new ArrayList<Integer>();
-
try
{
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement.executeQuery( sql );
-
- while ( resultSet.next() )
+ List<Integer> patientIds = jdbcTemplate.query( sql, new RowMapper<Integer>()
{
- int patientId = resultSet.getInt( 1 );
-
- patientIds.add( patientId );
- }
-
+ public Integer mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ return rs.getInt( 1 );
+ }
+ } );
+
return patientIds;
-
}
catch ( Exception ex )
{
ex.printStackTrace();
return null;
}
- finally
- {
- holder.close();
- }
}
@SuppressWarnings( "unchecked" )
@Override
public Collection<CaseAggregationCondition> get( DataElement dataElement )
{
- return getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ) )
- .list();
+ return getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ) ).list();
}
-
+
@Override
public CaseAggregationCondition get( DataElement dataElement, DataElementCategoryOptionCombo optionCombo )
{
- return (CaseAggregationCondition)getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ),
- Restrictions.eq( "optionCombo", optionCombo ))
- .uniqueResult();
+ return (CaseAggregationCondition) getCriteria( Restrictions.eq( "aggregationDataElement", dataElement ),
+ Restrictions.eq( "optionCombo", optionCombo ) ).uniqueResult();
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
@Override
public Collection<CaseAggregationCondition> get( Collection<DataElement> dataElements )
{
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2012-07-19 03:26:16 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2012-07-26 08:53:44 +0000
@@ -28,15 +28,13 @@
package org.hisp.dhis.patient.hibernate;
import java.sql.ResultSet;
-import java.sql.Statement;
+import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import org.amplecode.quick.StatementHolder;
-import org.amplecode.quick.StatementManager;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.Query;
@@ -51,6 +49,7 @@
import org.hisp.dhis.patient.PatientStore;
import org.hisp.dhis.program.Program;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -73,13 +72,6 @@
this.statementBuilder = statementBuilder;
}
- private StatementManager statementManager;
-
- public void setStatementManager( StatementManager statementManager )
- {
- this.statementManager = statementManager;
- }
-
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
@@ -108,6 +100,8 @@
@Override
public Collection<Patient> getByNames( String fullName, Integer min, Integer max )
{
+ List<Patient> patients = new ArrayList<Patient>();
+
fullName = fullName.toLowerCase();
String sql = "SELECT patientid FROM patient " + "where lower( " + statementBuilder.getPatientFullName() + ") "
+ "like '%" + fullName + "%' ";
@@ -117,30 +111,21 @@
sql += statementBuilder.limitRecord( min, max );
}
- StatementHolder holder = statementManager.getHolder();
-
- Set<Patient> patients = new HashSet<Patient>();
-
try
{
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement.executeQuery( sql );
-
- while ( resultSet.next() )
+ patients = jdbcTemplate.query( sql, new RowMapper<Patient>()
{
- Patient p = get( resultSet.getInt( 1 ) );
- patients.add( p );
- }
+ public Patient mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ return get( rs.getInt( 1 ) );
+ }
+ } );
}
catch ( Exception ex )
{
ex.printStackTrace();
}
- finally
- {
- holder.close();
- }
return patients;
}
@@ -257,29 +242,24 @@
public Collection<Patient> search( List<String> searchKeys, OrganisationUnit orgunit, Integer min, Integer max )
{
String sql = searchPatientSql( false, searchKeys, orgunit, min, max );
+
Collection<Patient> patients = new HashSet<Patient>();
- StatementHolder holder = statementManager.getHolder();
+
try
{
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement.executeQuery( sql );
-
- while ( resultSet.next() )
+ patients = jdbcTemplate.query( sql, new RowMapper<Patient>()
{
- int patientId = resultSet.getInt( 1 );
- patients.add( get( patientId ) );
- }
+ public Patient mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ return get( rs.getInt( 1 ) );
+ }
+ } );
}
catch ( Exception ex )
{
ex.printStackTrace();
}
- finally
- {
- holder.close();
- }
-
return patients;
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2012-07-10 06:06:52 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2012-07-26 08:53:44 +0000
@@ -32,15 +32,15 @@
import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_OBJECT;
import java.sql.ResultSet;
-import java.sql.Statement;
+import java.sql.SQLException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.amplecode.quick.StatementHolder;
-import org.amplecode.quick.StatementManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.system.startup.AbstractStartupRoutine;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -59,11 +59,11 @@
// Dependencies
// -------------------------------------------------------------------------
- private StatementManager statementManager;
+ private JdbcTemplate jdbcTemplate;
- public void setStatementManager( StatementManager statementManager )
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
{
- this.statementManager = statementManager;
+ this.jdbcTemplate = jdbcTemplate;
}
// -------------------------------------------------------------------------
@@ -126,21 +126,21 @@
private void updateProgramStageInstanceOrgunit()
{
- StatementHolder holder = statementManager.getHolder();
-
try
{
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement
- .executeQuery( "SELECT distinct programstageinstanceid, organisationunitid, providedByAnotherFacility FROM patientdatavalue" );
-
- while ( resultSet.next() )
+ String sql = "SELECT distinct programstageinstanceid, organisationunitid, providedByAnotherFacility FROM patientdatavalue";
+
+ jdbcTemplate.query( sql, new RowMapper<Boolean>()
{
- executeSql( "UPDATE programstageinstance SET organisationunitid=" + resultSet.getInt( 2 )
- + ", providedByAnotherFacility=" + resultSet.getBoolean( 3 ) + " WHERE programstageinstanceid="
- + resultSet.getInt( 1 ) );
- }
+ public Boolean mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ executeSql( "UPDATE programstageinstance SET organisationunitid=" + rs.getInt( 2 )
+ + ", providedByAnotherFacility=" + rs.getBoolean( 3 ) + " WHERE programstageinstanceid="
+ + rs.getInt( 1 ) );
+ return true;
+ }
+ } );
executeSql( "ALTER TABLE patientdatavalue DROP COLUMN organisationUnitid" );
executeSql( "ALTER TABLE patientdatavalue DROP COLUMN providedByAnotherFacility" );
@@ -150,69 +150,60 @@
{
log.debug( ex );
}
- finally
- {
- holder.close();
- }
}
private void updateCaseAggregationCondition()
{
- String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+" + SEPARATOR_ID
- + "[0-9]+" + "\\]";
try
{
- StatementHolder holder = statementManager.getHolder();
-
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement
- .executeQuery( "SELECT caseaggregationconditionid, aggregationExpression FROM caseaggregationcondition" );
-
- while ( resultSet.next() )
+ String sql = "SELECT caseaggregationconditionid, aggregationExpression FROM caseaggregationcondition";
+
+ jdbcTemplate.query( sql, new RowMapper<Boolean>()
{
- StringBuffer formular = new StringBuffer();
-
- // ---------------------------------------------------------------------
- // parse expressions
- // ---------------------------------------------------------------------
-
- Pattern pattern = Pattern.compile( regExp );
-
- Matcher matcher = pattern.matcher( resultSet.getString( 2 ) );
-
- while ( matcher.find() )
+ public Boolean mapRow( ResultSet rs, int rowNum )
+ throws SQLException
{
- String match = matcher.group();
- match = match.replaceAll( "[\\[\\]]", "" );
-
- String[] info = match.split( SEPARATOR_OBJECT );
- String[] ids = info[1].split( SEPARATOR_ID );
- int programStageId = Integer.parseInt( ids[0] );
-
- StatementHolder _holder = statementManager.getHolder();
- Statement _statement = _holder.getStatement();
- ResultSet rsProgramId = _statement
- .executeQuery( "SELECT programid FROM programstage where programstageid=" + programStageId );
-
- if ( rsProgramId.next() )
+ String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+"
+ + SEPARATOR_ID + "[0-9]+" + "\\]";
+
+ StringBuffer formula = new StringBuffer();
+
+ // ---------------------------------------------------------------------
+ // parse expressions
+ // ---------------------------------------------------------------------
+
+ Pattern pattern = Pattern.compile( regExp );
+
+ Matcher matcher = pattern.matcher( rs.getString( 2 ) );
+
+ while ( matcher.find() )
{
- int programId = rsProgramId.getInt( 1 );
+ String match = matcher.group();
+ match = match.replaceAll( "[\\[\\]]", "" );
+
+ String[] info = match.split( SEPARATOR_OBJECT );
+ String[] ids = info[1].split( SEPARATOR_ID );
+ int programStageId = Integer.parseInt( ids[0] );
+
+ String subSQL = "SELECT programid FROM programstage where programstageid=" + programStageId;
+
+ int programId = jdbcTemplate.queryForInt( subSQL );
String aggregationExpression = "[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT
+ programId + "." + programStageId + "." + ids[1] + "]";
- matcher.appendReplacement( formular, aggregationExpression );
+ matcher.appendReplacement( formula, aggregationExpression );
}
+
+ matcher.appendTail( formula );
+
+ executeSql( "UPDATE caseaggregationcondition SET aggregationExpression='" + formula.toString()
+ + "' WHERE caseaggregationconditionid=" + rs.getInt( 1 ) );
+
+ return true;
}
-
- matcher.appendTail( formular );
-
- executeSql( "UPDATE caseaggregationcondition SET aggregationExpression='" + formular.toString()
- + "' WHERE caseaggregationconditionid=" + resultSet.getInt( 1 ) );
-
- }
+ } );
}
catch ( Exception e )
{
@@ -224,18 +215,19 @@
{
try
{
- StatementHolder holder = statementManager.getHolder();
-
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement
- .executeQuery( "SELECT patienttabularreportid, organisationunitid FROM patienttabularreport" );
-
- while ( resultSet.next() )
+ String sql = "SELECT patienttabularreportid, organisationunitid FROM patienttabularreport";
+
+ jdbcTemplate.query( sql, new RowMapper<Boolean>()
{
- executeSql( " INSERT INTO patienttabularreport_organisationUnits ( patienttabularreportid, organisationunitid ) VALUES ( "
- + resultSet.getInt( 1 ) + ", " + resultSet.getInt( 2 ) + ")" );
- }
+ public Boolean mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ executeSql( " INSERT INTO patienttabularreport_organisationUnits ( patienttabularreportid, organisationunitid ) VALUES ( "
+ + rs.getInt( 1 ) + ", " + rs.getInt( 2 ) + ")" );
+ return true;
+ }
+ } );
+
executeSql( "ALTER TABLE patienttabularreport DROP COLUMN organisationunitid" );
}
catch ( Exception e )
@@ -248,26 +240,21 @@
{
try
{
- StatementHolder holder = statementManager.getHolder();
-
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement
- .executeQuery( "SELECT pd.patienttabularreportid, tr.programstageid, pd.elt, sort_order "
- + " FROM patienttabularreport_dataelements pd inner join patienttabularreport tr"
- + " on pd.patienttabularreportid=tr.patienttabularreportid" + " order by pd.patienttabularreportid" );
-
- while ( resultSet.next() )
+ String sql = "SELECT pd.patienttabularreportid, tr.programstageid, pd.elt, sort_order "
+ + " FROM patienttabularreport_dataelements pd inner join patienttabularreport tr"
+ + " on pd.patienttabularreportid=tr.patienttabularreportid" + " order by pd.patienttabularreportid";
+
+ jdbcTemplate.query( sql, new RowMapper<Boolean>()
{
- executeSql( "INSERT INTO patienttabularreport_programstagedataelements ( patienttabularreportid, programstageid, dataelementid, sort_order ) VALUES ( "
- + resultSet.getInt( 1 )
- + ", "
- + resultSet.getInt( 2 )
- + ", "
- + resultSet.getInt( 3 )
- + ", "
- + resultSet.getInt( 4 ) + ")" );
- }
+ public Boolean mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ executeSql( "INSERT INTO patienttabularreport_programstagedataelements ( patienttabularreportid, programstageid, dataelementid, sort_order ) VALUES ( "
+ + rs.getInt( 1 ) + ", " + rs.getInt( 2 ) + ", " + rs.getInt( 3 ) + ", " + rs.getInt( 4 ) + ")" );
+ return true;
+ }
+ } );
+
executeSql( "ALTER TABLE patienttabularreport DROP COLUMN programstageid" );
executeSql( "DROP TABLE patienttabularreport_dataelements" );
}
@@ -281,17 +268,19 @@
{
try
{
- StatementHolder holder = statementManager.getHolder();
- Statement statement = holder.getStatement();
-
- ResultSet resultSet = statement.executeQuery( "SELECT programstageinstanceid, storedBy"
- + " FROM programstageinstance where storedBy is not null" );
-
- while ( resultSet.next() )
+ String sql = "SELECT programstageinstanceid, storedBy"
+ + " FROM programstageinstance where storedBy is not null";
+
+ jdbcTemplate.query( sql, new RowMapper<Boolean>()
{
- executeSql( "UPDATE patientdatavalue SET storedBy='" + resultSet.getString( 2 )
- + "' where programstageinstanceid=" + resultSet.getInt( 1 ) );
- }
+ public Boolean mapRow( ResultSet rs, int rowNum )
+ throws SQLException
+ {
+ executeSql( "UPDATE patientdatavalue SET storedBy='" + rs.getString( 2 )
+ + "' where programstageinstanceid=" + rs.getInt( 1 ) );
+ return true;
+ }
+ } );
executeSql( "ALTER TABLE programstageinstance DROP COLUMN storedBy" );
}
@@ -299,18 +288,9 @@
{
}
}
-
- private int executeSql( String sql )
+
+ private void executeSql(String sql)
{
- try
- {
- return statementManager.getHolder().executeUpdate( sql );
- }
- catch ( Exception ex )
- {
- log.debug( ex );
-
- return -1;
- }
+ jdbcTemplate.execute( sql );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2012-07-26 02:25:06 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2012-07-26 08:53:44 +0000
@@ -9,15 +9,14 @@
<bean id="org.hisp.dhis.caseaggregation.CaseAggregationConditionStore"
class="org.hisp.dhis.caseaggregation.jdbc.JdbcCaseAggregationConditionStore">
- <property name="statementManager" ref="statementManager" />
- <property name="clazz"
- value="org.hisp.dhis.caseaggregation.CaseAggregationCondition" />
+ <property name="clazz" value="org.hisp.dhis.caseaggregation.CaseAggregationCondition" />
<property name="sessionFactory" ref="sessionFactory" />
+ <property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="org.hisp.dhis.activityplan.jdbc.JdbcActivityPlanStore"
class="org.hisp.dhis.activityplan.jdbc.JdbcActivityPlanStore">
- <property name="statementManager" ref="statementManager" />
+ <property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="statementBuilder" ref="statementBuilder" />
</bean>
@@ -66,7 +65,6 @@
<bean id="org.hisp.dhis.patient.PatientStore" class="org.hisp.dhis.patient.hibernate.HibernatePatientStore">
<property name="clazz" value="org.hisp.dhis.patient.Patient" />
<property name="sessionFactory" ref="sessionFactory" />
- <property name="statementManager" ref="statementManager" />
<property name="statementBuilder" ref="statementBuilder" />
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
@@ -371,7 +369,7 @@
<!-- Startup -->
<bean id="org.hisp.dhis.patient.startup.TableAlteror" class="org.hisp.dhis.patient.startup.TableAlteror">
- <property name="statementManager" ref="statementManager" />
+ <property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="name" value="PatientTableAlteror" />
<property name="runlevel" value="4" />
<property name="skipInTests" value="true" />
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java 2012-07-06 09:59:36 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/SearchPatientAction.java 2012-07-26 08:53:44 +0000
@@ -30,7 +30,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;