dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18378
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7727: Reverted table alteror in patient service, spammed log
------------------------------------------------------------
revno: 7727
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-07-26 13:26:41 +0200
message:
Reverted table alteror in patient service, spammed log
modified:
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
--
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/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2012-07-26 08:53:44 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java 2012-07-26 11:26:41 +0000
@@ -32,15 +32,15 @@
import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_OBJECT;
import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.sql.Statement;
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 JdbcTemplate jdbcTemplate;
+ private StatementManager statementManager;
- public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ public void setStatementManager( StatementManager statementManager )
{
- this.jdbcTemplate = jdbcTemplate;
+ this.statementManager = statementManager;
}
// -------------------------------------------------------------------------
@@ -126,21 +126,21 @@
private void updateProgramStageInstanceOrgunit()
{
+ StatementHolder holder = statementManager.getHolder();
+
try
{
- String sql = "SELECT distinct programstageinstanceid, organisationunitid, providedByAnotherFacility FROM patientdatavalue";
-
- jdbcTemplate.query( sql, new RowMapper<Boolean>()
+ Statement statement = holder.getStatement();
+
+ ResultSet resultSet = statement
+ .executeQuery( "SELECT distinct programstageinstanceid, organisationunitid, providedByAnotherFacility FROM patientdatavalue" );
+
+ while ( resultSet.next() )
{
- 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( "UPDATE programstageinstance SET organisationunitid=" + resultSet.getInt( 2 )
+ + ", providedByAnotherFacility=" + resultSet.getBoolean( 3 ) + " WHERE programstageinstanceid="
+ + resultSet.getInt( 1 ) );
+ }
executeSql( "ALTER TABLE patientdatavalue DROP COLUMN organisationUnitid" );
executeSql( "ALTER TABLE patientdatavalue DROP COLUMN providedByAnotherFacility" );
@@ -150,60 +150,69 @@
{
log.debug( ex );
}
+ finally
+ {
+ holder.close();
+ }
}
private void updateCaseAggregationCondition()
{
+ String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+" + SEPARATOR_ID
+ + "[0-9]+" + "\\]";
try
{
- String sql = "SELECT caseaggregationconditionid, aggregationExpression FROM caseaggregationcondition";
-
- jdbcTemplate.query( sql, new RowMapper<Boolean>()
+ StatementHolder holder = statementManager.getHolder();
+
+ Statement statement = holder.getStatement();
+
+ ResultSet resultSet = statement
+ .executeQuery( "SELECT caseaggregationconditionid, aggregationExpression FROM caseaggregationcondition" );
+
+ while ( resultSet.next() )
{
- public Boolean mapRow( ResultSet rs, int rowNum )
- throws SQLException
+ StringBuffer formular = new StringBuffer();
+
+ // ---------------------------------------------------------------------
+ // parse expressions
+ // ---------------------------------------------------------------------
+
+ Pattern pattern = Pattern.compile( regExp );
+
+ Matcher matcher = pattern.matcher( resultSet.getString( 2 ) );
+
+ while ( matcher.find() )
{
- 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() )
+ 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 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 );
+ int programId = rsProgramId.getInt( 1 );
String aggregationExpression = "[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT
+ programId + "." + programStageId + "." + ids[1] + "]";
- matcher.appendReplacement( formula, aggregationExpression );
+ matcher.appendReplacement( formular, 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 )
{
@@ -215,19 +224,18 @@
{
try
{
- String sql = "SELECT patienttabularreportid, organisationunitid FROM patienttabularreport";
-
- jdbcTemplate.query( sql, new RowMapper<Boolean>()
+ StatementHolder holder = statementManager.getHolder();
+
+ Statement statement = holder.getStatement();
+
+ ResultSet resultSet = statement
+ .executeQuery( "SELECT patienttabularreportid, organisationunitid FROM patienttabularreport" );
+
+ while ( resultSet.next() )
{
- 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( " INSERT INTO patienttabularreport_organisationUnits ( patienttabularreportid, organisationunitid ) VALUES ( "
+ + resultSet.getInt( 1 ) + ", " + resultSet.getInt( 2 ) + ")" );
+ }
executeSql( "ALTER TABLE patienttabularreport DROP COLUMN organisationunitid" );
}
catch ( Exception e )
@@ -240,21 +248,26 @@
{
try
{
- 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>()
+ 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() )
{
- 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( "INSERT INTO patienttabularreport_programstagedataelements ( patienttabularreportid, programstageid, dataelementid, sort_order ) VALUES ( "
+ + resultSet.getInt( 1 )
+ + ", "
+ + resultSet.getInt( 2 )
+ + ", "
+ + resultSet.getInt( 3 )
+ + ", "
+ + resultSet.getInt( 4 ) + ")" );
+ }
executeSql( "ALTER TABLE patienttabularreport DROP COLUMN programstageid" );
executeSql( "DROP TABLE patienttabularreport_dataelements" );
}
@@ -268,19 +281,17 @@
{
try
{
- String sql = "SELECT programstageinstanceid, storedBy"
- + " FROM programstageinstance where storedBy is not null";
-
- jdbcTemplate.query( sql, new RowMapper<Boolean>()
+ 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() )
{
- 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( "UPDATE patientdatavalue SET storedBy='" + resultSet.getString( 2 )
+ + "' where programstageinstanceid=" + resultSet.getInt( 1 ) );
+ }
executeSql( "ALTER TABLE programstageinstance DROP COLUMN storedBy" );
}
@@ -288,9 +299,18 @@
{
}
}
-
- private void executeSql(String sql)
+
+ private int executeSql( String sql )
{
- jdbcTemplate.execute( sql );
+ try
+ {
+ return statementManager.getHolder().executeUpdate( sql );
+ }
+ catch ( Exception ex )
+ {
+ log.debug( ex );
+
+ return -1;
+ }
}
}
=== 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 08:53:44 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2012-07-26 11:26:41 +0000
@@ -369,7 +369,7 @@
<!-- Startup -->
<bean id="org.hisp.dhis.patient.startup.TableAlteror" class="org.hisp.dhis.patient.startup.TableAlteror">
- <property name="jdbcTemplate" ref="jdbcTemplate" />
+ <property name="statementManager" ref="statementManager" />
<property name="name" value="PatientTableAlteror" />
<property name="runlevel" value="4" />
<property name="skipInTests" value="true" />