dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21541
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10214: Upgraded charts to use the RelativePeriods entity instead of embedding through component mapping
------------------------------------------------------------
revno: 10214
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-03-14 12:08:04 +0100
message:
Upgraded charts to use the RelativePeriods entity instead of embedding through component mapping
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.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-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-03-14 10:12:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-03-14 11:08:04 +0000
@@ -535,8 +535,9 @@
executeSql( "ALTER TABLE usergroup DROP CONSTRAINT usergroup_name_key" );
executeSql( "ALTER TABLE datadictionary DROP CONSTRAINT datadictionary_name_key" );
+ upgradeChartRelativePeriods();
+ upgradeReportTableRelativePeriods();
upgradeReportTableColumns();
- upgradeReportTableRelativePeriods();
// clear out sharing of de-group/de-group-set for now
executeSql( "UPDATE dataelementgroup SET userid=NULL WHERE userid IS NOT NULL" );
@@ -551,6 +552,74 @@
log.info( "Tables updated" );
}
+ private void upgradeChartRelativePeriods()
+ {
+ BatchHandler<RelativePeriods> batchHandler = batchHandlerFactory.createBatchHandler( RelativePeriodsBatchHandler.class ).init();
+
+ try
+ {
+ String sql = "select reportingmonth, * from chart";
+
+ ResultSet rs = statementManager.getHolder().getStatement().executeQuery( sql );
+
+ while ( rs.next() )
+ {
+ RelativePeriods r = new RelativePeriods(
+ rs.getBoolean( "reportingmonth" ),
+ false,
+ rs.getBoolean( "reportingquarter" ),
+ rs.getBoolean( "lastsixmonth" ),
+ rs.getBoolean( "monthsthisyear" ),
+ rs.getBoolean( "quartersthisyear" ),
+ rs.getBoolean( "thisyear" ),
+ false, false,
+ rs.getBoolean( "lastyear" ),
+ rs.getBoolean( "last5years" ),
+ rs.getBoolean( "last12months" ),
+ rs.getBoolean( "last3months" ),
+ false,
+ rs.getBoolean( "last4quarters" ),
+ rs.getBoolean( "last2sixmonths" ),
+ false, false, false,
+ false, false, false );
+
+ int chartId = rs.getInt( "chartid" );
+
+ if ( !r.isEmpty() )
+ {
+ int relativePeriodsId = batchHandler.insertObject( r, true );
+
+ String update = "update chart set relativeperiodsid=" + relativePeriodsId + " where chartid=" + chartId;
+
+ executeSql( update );
+
+ log.info( "Updated relative periods for chart with id: " + chartId );
+ }
+ }
+
+ executeSql( "alter table chart drop column reportingmonth" );
+ executeSql( "alter table chart drop column reportingquarter" );
+ executeSql( "alter table chart drop column lastsixmonth" );
+ executeSql( "alter table chart drop column monthsthisyear" );
+ executeSql( "alter table chart drop column quartersthisyear" );
+ executeSql( "alter table chart drop column thisyear" );
+ executeSql( "alter table chart drop column lastyear" );
+ executeSql( "alter table chart drop column last5years" );
+ executeSql( "alter table chart drop column last12months" );
+ executeSql( "alter table chart drop column last3months" );
+ executeSql( "alter table chart drop column last4quarters" );
+ executeSql( "alter table chart drop column last2sixmonths" );
+ }
+ catch ( Exception ex )
+ {
+ log.warn( ex );
+ }
+ finally
+ {
+ batchHandler.flush();
+ }
+ }
+
private void upgradeReportTableRelativePeriods()
{
BatchHandler<RelativePeriods> batchHandler = batchHandlerFactory.createBatchHandler( RelativePeriodsBatchHandler.class ).init();
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml 2013-03-13 15:03:10 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml 2013-03-14 11:08:04 +0000
@@ -91,18 +91,8 @@
foreign-key="fk_chart_periods_periodid" />
</list>
- <component name="relatives">
- <property name="reportingMonth" />
- <property name="reportingQuarter" />
- <property name="lastSixMonth" />
- <property name="thisYear" />
- <property name="last12Months" />
- <property name="last3Months" />
- <property name="last4Quarters" />
- <property name="last2SixMonths" />
- <property name="lastYear" />
- <property name="last5Years" />
- </component>
+ <many-to-one name="relatives" unique="true" class="org.hisp.dhis.period.RelativePeriods" column="relativeperiodsid"
+ cascade="all-delete-orphan" foreign-key="fk_report_relativeperiodsid" />
<property name="userOrganisationUnit" />