dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08309
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1985: Fixed archiving data service test
------------------------------------------------------------
revno: 1985
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2010-11-02 15:28:21 +0700
message:
Fixed archiving data service test
modified:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataarchive/jdbc/JdbcDataArchiveStore.java
dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveServiceTest.java
dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.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-administration/src/main/java/org/hisp/dhis/dataarchive/jdbc/JdbcDataArchiveStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataarchive/jdbc/JdbcDataArchiveStore.java 2010-10-30 11:54:24 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataarchive/jdbc/JdbcDataArchiveStore.java 2010-11-02 08:28:21 +0000
@@ -36,10 +36,12 @@
import org.hisp.dhis.dataarchive.DataArchiveStore;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.transaction.annotation.Transactional;
/**
* @author Lars Helge Overland
*/
+@Transactional
public class JdbcDataArchiveStore
implements DataArchiveStore
{
@@ -70,9 +72,11 @@
public void archiveData( Date startDate, Date endDate )
{
// Move data from datavalue to datavaluearchive
- String sql = "INSERT INTO datavaluearchive ( " + "SELECT d.* FROM datavalue AS d "
- + "JOIN period AS p ON d.periodid=p.periodid " + "WHERE p.startdate>='" + getMediumDateString( startDate ) + "' " +
- "AND p.enddate<='" + getMediumDateString( endDate ) + "' );";
+ String sql = "INSERT INTO datavaluearchive ( "
+ + "SELECT d.* FROM datavalue AS d "
+ + "JOIN period AS p ON (d.periodid=p.periodid) "
+ + "WHERE p.startdate>='" + getMediumDateString( startDate ) + "' "
+ + "AND p.enddate<='" + getMediumDateString( endDate ) + "' );";
log.info( sql );
jdbcTemplate.execute( sql );
@@ -82,14 +86,17 @@
log.info( sql );
jdbcTemplate.execute( sql );
+
}
public void unArchiveData( Date startDate, Date endDate )
{
// Move data from datavalue to datavaluearchive
- String sql = "INSERT INTO datavalue ( " + "SELECT a.* FROM datavaluearchive AS a "
- + "JOIN period AS p ON a.periodid=p.periodid " + "WHERE p.startdate>='" + getMediumDateString( startDate ) + "' " +
- "AND p.enddate<='" + getMediumDateString( endDate ) + "' );";
+ String sql = "INSERT INTO datavalue ( "
+ + "SELECT a.* FROM datavaluearchive AS a "
+ + "JOIN period AS p ON (a.periodid=p.periodid) "
+ + "WHERE p.startdate>='" + getMediumDateString( startDate ) + "' "
+ + "AND p.enddate<='" + getMediumDateString( endDate ) + "' );";
log.info( sql );
jdbcTemplate.execute( sql );
@@ -100,13 +107,16 @@
log.info( sql );
jdbcTemplate.execute( sql );
+
}
public int getNumberOfOverlappingValues()
{
String sql = "SELECT COUNT(*) FROM datavaluearchive AS a "
- + "JOIN datavalue AS d ON a.dataelementid=d.dataelementid " + "AND a.periodid=d.periodid "
- + "AND a.sourceid=d.sourceid " + "AND a.categoryoptioncomboid=d.categoryoptioncomboid;";
+ + "JOIN datavalue AS d ON (a.dataelementid=d.dataelementid "
+ + "AND a.periodid=d.periodid "
+ + "AND a.sourceid=d.sourceid "
+ + "AND a.categoryoptioncomboid=d.categoryoptioncomboid);";
log.info( sql );
@@ -151,7 +161,7 @@
log.info( sql );
jdbcTemplate.execute( sql );
}
-
+
// -------------------------------------------------------------------------
// Implementation methods for Patient data values
// -------------------------------------------------------------------------
@@ -159,14 +169,15 @@
public void archivePatientData( Date startDate, Date endDate )
{
// Move data from patientdatavalue to patientdatavaluearchive
- String sql ="INSERT INTO patientdatavaluearchive ( " + "SELECT pdv.* FROM patientdatavalue AS pdv "
- + "INNER JOIN programstageinstance AS psi "
- + "ON pdv.programstageinstanceid = psi.programstageinstanceid "
- + "INNER JOIN programinstance AS pi "
- + "ON pi.programinstanceid = psi.programinstanceid "
- + "WHERE pi.enddate >= '" + getMediumDateString( startDate ) + "' "
- + "AND pi.enddate <= '" + getMediumDateString( endDate ) + "' );";
-
+ String sql = "INSERT INTO patientdatavaluearchive ( "
+ + "SELECT pdv.* FROM patientdatavalue AS pdv "
+ + "INNER JOIN programstageinstance AS psi "
+ + "ON pdv.programstageinstanceid = psi.programstageinstanceid "
+ + "INNER JOIN programinstance AS pi "
+ + "ON pi.programinstanceid = psi.programinstanceid "
+ + "WHERE pi.enddate >= '" + getMediumDateString( startDate ) + "' " + "AND pi.enddate <= '"
+ + getMediumDateString( endDate ) + "' );";
+
log.info( sql );
jdbcTemplate.execute( sql );
@@ -180,13 +191,14 @@
public void unArchivePatientData( Date startDate, Date endDate )
{
// Move data from patientdatavalue to patientdatavaluearchive
- String sql ="INSERT INTO patientdatavalue ( " + "SELECT pdv.* FROM patientdatavaluearchive AS pdv "
- + "INNER JOIN programstageinstance AS psi "
- + "ON pdv.programstageinstanceid = psi.programstageinstanceid "
- + "INNER JOIN programinstance AS pi "
- + "ON pi.programinstanceid = psi.programinstanceid "
- + "WHERE pi.enddate >= '" + getMediumDateString( startDate ) + "' "
- + "AND pi.enddate <= '" + getMediumDateString( endDate ) + "' );";
+ String sql = "INSERT INTO patientdatavalue ( "
+ + "SELECT pdv.* FROM patientdatavaluearchive AS pdv "
+ + "INNER JOIN programstageinstance AS psi "
+ + "ON pdv.programstageinstanceid = psi.programstageinstanceid "
+ + "INNER JOIN programinstance AS pi "
+ + "ON pi.programinstanceid = psi.programinstanceid "
+ + "WHERE pi.enddate >= '" + getMediumDateString( startDate ) + "' " + "AND pi.enddate <= '"
+ + getMediumDateString( endDate ) + "' );";
log.info( sql );
jdbcTemplate.execute( sql );
@@ -197,14 +209,14 @@
log.info( sql );
jdbcTemplate.execute( sql );
}
-
+
public int getNumberOfOverlappingPatientValues()
{
- String sql = "SELECT COUNT(*) FROM patientdatavaluearchive AS pdv "
- + "INNER JOIN programstageinstance AS psi "
- + "ON pdv.programstageinstanceid = psi.programstageinstanceid "
- + "INNER JOIN programinstance AS pi "
- + "ON pi.programinstanceid = psi.programinstanceid";
+ String sql = "SELECT COUNT(*) FROM patientdatavaluearchive AS pdv "
+ + "INNER JOIN programstageinstance AS psi "
+ + "ON pdv.programstageinstanceid = psi.programstageinstanceid "
+ + "INNER JOIN programinstance AS pi "
+ + "ON pi.programinstanceid = psi.programinstanceid";
log.info( sql );
return jdbcTemplate.queryForInt( sql );
@@ -236,13 +248,15 @@
public void deleteOldestOverlappingPatientData()
{
- // Delete overlaps from patientdatavalue which are older than patientdatavaluearchive
+ // Delete overlaps from patientdatavalue which are older than
+ // patientdatavaluearchive
String sql = statementBuilder.deleteOldestOverlappingPatientDataValue();
log.info( sql );
jdbcTemplate.execute( sql );
- // Delete overlaps from patientdatavaluearchive which are older than patientdatavalue
+ // Delete overlaps from patientdatavaluearchive which are older than
+ // patientdatavalue
sql = statementBuilder.deleteOldestOverlappingPatientArchiveData();
log.info( sql );
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveServiceTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveServiceTest.java 2010-10-29 14:09:49 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataarchive/DataArchiveServiceTest.java 2010-11-02 08:28:21 +0000
@@ -28,12 +28,10 @@
*/
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import java.util.Date;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -68,56 +66,69 @@
* operation, DataEliminationStrategy strategy );
*/
@Test
- @Ignore
public void testArchiveData()
{
- // Archives all datavalues to datavaluearchive from earliest to latest
- // date
- int archivedValuesNo = dataArchiveService.archiveData( STARTDATE, ENDDATE, DataArchiveOperation.UNARCHIVE,
- DataEliminationStrategy.REGULAR );
-
- //assertEquals( "Number of archived values equals 54", 54, archivedValuesNo );
- assertEquals( "Number of archived values equals 0", 0, archivedValuesNo );
-
- archivedValuesNo = dataArchiveService.archiveData( STARTDATE, ENDDATE, DataArchiveOperation.ARCHIVE,
+ /*
+ * STEP 1:
+ *
+ * Archives all datavalues to datavaluearchive follows from earliest to
+ * latest date
+ */
+ int archivedValuesNo = dataArchiveService.archiveData( STARTDATE, ENDDATE, DataArchiveOperation.ARCHIVE,
DataEliminationStrategy.ARCHIVE );
-
- //assertEquals( "Number of archived values more than 0", 6, archivedValuesNo );
- assertEquals( "Number of archived values equals 0", 0, archivedValuesNo );
-
- // Archives all datavalues to datavaluearchive from "2005-05-01" to
- // "2005-05-31" of periodD by weekly
+
+ assertEquals( "There will have 54 records in datavaluearchive table from STARTDATE to ENDDATE", 54,
+ archivedValuesNo );
+
+ /*
+ * STEP 2:
+ *
+ * Archives all datavalues to datavaluearchive from "2005-05-01" to
+ * "2005-05-31" of periodD by weekly
+ */
archivedValuesNo = dataArchiveService.archiveData( periodD.getStartDate(), periodD.getEndDate(),
DataArchiveOperation.ARCHIVE, DataEliminationStrategy.ARCHIVE );
- //assertEquals( "Number of archived values equals 6", 6, archivedValuesNo );
- assertNotSame( "Number of archived values more than 0", 6, archivedValuesNo );
+ assertEquals( "54 records still in datavaluearchive table because of "
+ + "periodD is also in range from STARTDATE to ENDDATE", 54, archivedValuesNo );
- // Archives all datavalues to datavaluearchive from "2005-05-01" to
- // "2005-05-31" of periodD by weekly
+ /*
+ * STEP 3: Un-archives all datavaluearchive to datavalues from
+ * "2005-05-01" to "2005-05-31" of periodD by weekly
+ */
archivedValuesNo = dataArchiveService.archiveData( periodD.getStartDate(), periodD.getEndDate(),
DataArchiveOperation.UNARCHIVE, DataEliminationStrategy.REGULAR );
- assertSame( "Number of unarchived values more than 0", 0, archivedValuesNo );
-
+ assertSame( "6 records from 2005-05-01 to 2005-05-31 have been removed back into datavalue table."
+ + " So now, datavaluearchive contains 48 records only", 48, archivedValuesNo );
+
+ /*
+ * STEP 4: Un-archives all datavaluearchive to datavalues from earliest
+ * to latest date. This is the final step to do empty datavaluearchive
+ * table to avoid the referential integrity constraint violation.
+ *
+ * Because the emptyDatabaseAfterTest() method doesn't work properly
+ */
+ archivedValuesNo = dataArchiveService.archiveData( STARTDATE, ENDDATE, DataArchiveOperation.UNARCHIVE,
+ DataEliminationStrategy.REGULAR );
+
+ assertEquals( "Empty datavaluearchive table", 0, archivedValuesNo );
}
/**
* int getNumberOfOverlappingValues();
*/
@Test
- @Ignore
public void testGetNumberOfOverlappingValues()
{
int archivedValuesNo = dataArchiveService.archiveData( STARTDATE, ENDDATE, DataArchiveOperation.UNARCHIVE,
DataEliminationStrategy.REGULAR );
- //assertEquals( "Number of archived values equals 54", 54, archivedValuesNo );
- assertEquals( "Number of archived values equals 0", 0, archivedValuesNo );
+ assertEquals( "5Number of archived values equals 0", 0, archivedValuesNo );
archivedValuesNo = dataArchiveService.getNumberOfOverlappingValues();
- assertEquals( "Number of archived values equals 0", 0, archivedValuesNo );
+ assertEquals( "6Number of archived values equals 0", 0, archivedValuesNo );
}
}
=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java 2010-10-30 11:54:24 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java 2010-11-02 08:28:21 +0000
@@ -221,7 +221,7 @@
public String archiveData( String startDate, String endDate )
{
- return "DELETE FROM datavaluearchive AS a " +
+ return "DELETE FROM datavalue AS a " +
"WHERE EXISTS (" +
"SELECT 1 FROM period AS p " +
"WHERE a.periodid=p.periodid " +