dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31100
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15816: Period type, more performance fixes
------------------------------------------------------------
revno: 15816
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-23 17:07:29 +0200
message:
Period type, more performance fixes
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.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-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-06-23 14:46:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-06-23 15:07:29 +0000
@@ -230,11 +230,28 @@
return createPeriod( calendar.fromIso( DateUnit.fromJdkCalendar( cal ) ), calendar );
}
+ /**
+ * Creates a valid Period based on the given date. E.g. the given date is
+ * February 10. 2007, a monthly PeriodType should return February 2007. This
+ * method is intended for use in situations where a huge number of of periods
+ * will be generated and its desirable to re-use the calendar.
+ *
+ * @param date the date which is contained by the created period.
+ * @param calendar the calendar implementation to use.
+ * @return the valid Period based on the given date
+ */
+ public Period createPeriod( Date date, org.hisp.dhis.calendar.Calendar calendar )
+ {
+ Calendar cal = createCalendarInstance( date );
+
+ return createPeriod( calendar.fromIso( DateUnit.fromJdkCalendar( cal ) ), calendar );
+ }
+
public Period toIsoPeriod( DateUnit start, DateUnit end )
{
org.hisp.dhis.calendar.Calendar cal = getCalendar();
- return new Period( this, cal.toIso( start ).toJdkDate(), cal.toIso( end ).toJdkDate() );
+ return toIsoPeriod( start, end, cal );
}
protected Period toIsoPeriod( DateUnit start, DateUnit end, org.hisp.dhis.calendar.Calendar calendar )
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2014-05-04 09:55:24 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2014-06-23 15:07:29 +0000
@@ -44,6 +44,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataelement.CategoryOptionGroup;
import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
@@ -423,7 +424,6 @@
// PeriodTable
// -------------------------------------------------------------------------
- @Transactional
public void generateDatePeriodTable()
{
// ---------------------------------------------------------------------
@@ -440,10 +440,12 @@
List<Object[]> batchArgs = new ArrayList<Object[]>();
- Date startDate = new Cal( 1970, 1, 1 ).time(); //TODO
+ Date startDate = new Cal( 1975, 1, 1 ).time(); //TODO
Date endDate = new Cal( 2030, 1 , 1 ).time();
-
+
List<Period> days = new DailyPeriodType().generatePeriods( startDate, endDate );
+
+ Calendar cal = PeriodType.getCalendar();
for ( Period day : days )
{
@@ -453,7 +455,7 @@
for ( PeriodType periodType : periodTypes )
{
- Period period = periodType.createPeriod( day.getStartDate() );
+ Period period = periodType.createPeriod( day.getStartDate(), cal );
Assert.notNull( period );
@@ -462,7 +464,7 @@
batchArgs.add( values.toArray() );
}
-
+
resourceTableStore.batchUpdate( PeriodType.PERIOD_TYPES.size() + 1, TABLE_NAME_DATE_PERIOD_STRUCTURE, batchArgs );
log.info( "Period table generated" );