dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37854
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19326: DataValueSetStore, performance improvement for gettin data values, using start/end dates directly...
------------------------------------------------------------
revno: 19326
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-06-09 21:59:15 +0200
message:
DataValueSetStore, performance improvement for gettin data values, using start/end dates directly in SQL
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.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-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java 2015-06-09 08:37:13 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java 2015-06-09 19:59:15 +0000
@@ -48,6 +48,10 @@
private Set<Period> periods = new HashSet<>();
+ private Date startDate;
+
+ private Date endDate;
+
private Set<OrganisationUnit> organisationUnits = new HashSet<>();
private boolean includeChildren;
@@ -80,6 +84,11 @@
return periods != null && !periods.isEmpty() ? periods.iterator().next() : null;
}
+ public boolean hasStartEndDate()
+ {
+ return startDate != null && endDate != null;
+ }
+
public OrganisationUnit getFirstOrganisationUnit()
{
return organisationUnits != null && !organisationUnits.isEmpty() ? organisationUnits.iterator().next() : null;
@@ -139,6 +148,26 @@
this.periods = periods;
}
+ public Date getStartDate()
+ {
+ return startDate;
+ }
+
+ public void setStartDate( Date startDate )
+ {
+ this.startDate = startDate;
+ }
+
+ public Date getEndDate()
+ {
+ return endDate;
+ }
+
+ public void setEndDate( Date endDate )
+ {
+ this.endDate = endDate;
+ }
+
public Set<OrganisationUnit> getOrganisationUnits()
{
return organisationUnits;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-06-09 08:37:13 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-06-09 19:59:15 +0000
@@ -174,8 +174,8 @@
}
else if ( startDate != null && endDate != null )
{
- List<Period> pes = new ArrayList<Period>( periodService.getPeriodsBetweenDates( startDate, endDate ) );
- params.getPeriods().addAll( periodService.reloadPeriods( pes ) );
+ params.setStartDate( startDate );
+ params.setEndDate( endDate );
}
if ( organisationUnits != null )
@@ -212,11 +212,16 @@
violation = "At least one valid data set must be specified";
}
- if ( params.getPeriods().isEmpty() )
+ if ( params.getPeriods().isEmpty() && !params.hasStartEndDate() )
{
violation = "At least one valid period or start/end dates must be specified";
}
+ if ( params.hasStartEndDate() && params.getStartDate().after( params.getEndDate() ) )
+ {
+ violation = "Start date must be before end date";
+ }
+
if ( params.getOrganisationUnits().isEmpty() )
{
violation = "At least one valid organisation unit must be specified";
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2015-06-09 08:37:13 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2015-06-09 19:59:15 +0000
@@ -30,6 +30,7 @@
import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;
import static org.hisp.dhis.system.util.DateUtils.getLongGmtDateString;
+import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
import static org.hisp.dhis.util.TextUtils.getCommaDelimitedString;
import java.io.OutputStream;
@@ -41,6 +42,8 @@
import java.util.Set;
import org.amplecode.staxwax.factory.XMLFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataset.DataSet;
@@ -61,6 +64,8 @@
public class SpringDataValueSetStore
implements DataValueSetStore
{
+ private static final Log log = LogFactory.getLog( SpringDataValueSetStore.class );
+
private static final char CSV_DELIM = ',';
@Autowired
@@ -187,9 +192,17 @@
"join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
"join categoryoptioncombo aoc on (dv.attributeoptioncomboid=aoc.categoryoptioncomboid) " +
"where de.dataelementid in (" + getCommaDelimitedString( getIdentifiers( getDataElements( params.getDataSets() ) ) ) + ") " +
- "and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( params.getPeriods() ) ) + ") " +
"and dv.sourceid in (" + getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ") ";
+ if ( params.hasStartEndDate() )
+ {
+ sql += "and (pe.startdate >= '" + getMediumDateString( params.getStartDate() ) + "' and pe.enddate <= '" + getMediumDateString( params.getEndDate() ) + "') ";
+ }
+ else
+ {
+ sql += "and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( params.getPeriods() ) ) + ") ";
+ }
+
if ( params.hasLastUpdated() )
{
sql += "and dv.lastupdated >= '" + getLongGmtDateString( params.getLastUpdated() ) + "' ";
@@ -200,6 +213,8 @@
sql += "limit " + params.getLimit();
}
+ log.debug( "Get data value set SQL: " + sql );
+
return sql;
}