← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16908: HibernateCompleteDataSetRegistrationStore. Replaced method for reloading period to PeriodStore. R...

 

------------------------------------------------------------
revno: 16908
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-10-01 13:57:21 +0200
message:
  HibernateCompleteDataSetRegistrationStore. Replaced method for reloading period to PeriodStore. Removed explicit session flush on delete.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java
  dhis-2/dhis-services/dhis-service-core/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-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java	2014-06-23 21:31:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateCompleteDataSetRegistrationStore.java	2014-10-01 11:57:21 +0000
@@ -41,7 +41,7 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodStore;
 
 /**
  * @author Lars Helge Overland
@@ -61,46 +61,27 @@
         this.sessionFactory = sessionFactory;
     }
 
-    private PeriodService periodService;
-
-    public void setPeriodService( PeriodService periodService )
-    {
-        this.periodService = periodService;
-    }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private Period reloadPeriod( Period period )
-    {
-        Period persistedPeriod = periodService.getPeriod( 
-            period.getStartDate(), period.getEndDate(), period.getPeriodType() );
-        
-        if ( persistedPeriod != null )
-        {
-            return persistedPeriod;
-        }
-        
-        periodService.addPeriod( period );
-        
-        return period;
-    }
-    
+    private PeriodStore periodStore;
+
+    public void setPeriodStore( PeriodStore periodStore )
+    {
+        this.periodStore = periodStore;
+    }
+
     // -------------------------------------------------------------------------
     // DataSetCompleteRegistrationStore implementation
     // -------------------------------------------------------------------------
 
     public void saveCompleteDataSetRegistration( CompleteDataSetRegistration registration )
     {
-        registration.setPeriod( reloadPeriod( registration.getPeriod() ) );
+        registration.setPeriod( periodStore.reloadForceAddPeriod( registration.getPeriod() ) );
         
         sessionFactory.getCurrentSession().save( registration );
     }
 
     public void updateCompleteDataSetRegistration( CompleteDataSetRegistration registration )
     {
-        registration.setPeriod( reloadPeriod( registration.getPeriod() ) );
+        registration.setPeriod( periodStore.reloadForceAddPeriod( registration.getPeriod() ) );
         
         sessionFactory.getCurrentSession().update( registration );
     }
@@ -108,12 +89,17 @@
     public CompleteDataSetRegistration getCompleteDataSetRegistration( DataSet dataSet, Period period, 
         OrganisationUnit source, DataElementCategoryOptionCombo attributeOptionCombo )
     {
-        period = reloadPeriod( period );
-        
+        Period storedPeriod = periodStore.reloadPeriod( period );
+
+        if ( storedPeriod == null )
+        {
+            return null;
+        }
+
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( CompleteDataSetRegistration.class );
         
         criteria.add( Restrictions.eq( "dataSet", dataSet ) );
-        criteria.add( Restrictions.eq( "period", period ) );
+        criteria.add( Restrictions.eq( "period", storedPeriod ) );
         criteria.add( Restrictions.eq( "source", source ) );
         criteria.add( Restrictions.eq( "attributeOptionCombo", attributeOptionCombo ) );
         
@@ -123,21 +109,24 @@
     public void deleteCompleteDataSetRegistration( CompleteDataSetRegistration registration )
     {
         sessionFactory.getCurrentSession().delete( registration );
-        
-        sessionFactory.getCurrentSession().flush();
     }
 
     @SuppressWarnings( "unchecked" )
     public Collection<CompleteDataSetRegistration> getCompleteDataSetRegistrations( 
         DataSet dataSet, Collection<OrganisationUnit> sources, Period period )
     {
-        period = reloadPeriod( period );
-        
+        Period storedPeriod = periodStore.reloadPeriod( period );
+
+        if ( storedPeriod == null )
+        {
+            return null;
+        }
+
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( CompleteDataSetRegistration.class );
         
         criteria.add( Restrictions.eq( "dataSet", dataSet ) );
+        criteria.add( Restrictions.eq( "period", storedPeriod ) );
         criteria.add( Restrictions.in( "source", sources ) );
-        criteria.add( Restrictions.eq( "period", period ) );
         
         return criteria.list();
     }
@@ -154,7 +143,7 @@
     {
         for ( Period period : periods )
         {
-            period = reloadPeriod( period );
+            period = periodStore.reloadPeriod( period );
         }        
         
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( CompleteDataSetRegistration.class );
@@ -170,8 +159,13 @@
     public Collection<CompleteDataSetRegistration> getCompleteDataSetRegistrations( 
         DataSet dataSet, Collection<OrganisationUnit> sources, Period period, Date deadline )
     {
-        period = reloadPeriod( period );
-        
+        Period storedPeriod = periodStore.reloadPeriod( period );
+
+        if ( storedPeriod == null )
+        {
+            return null;
+        }
+
         Criteria criteria = sessionFactory.getCurrentSession().createCriteria( CompleteDataSetRegistration.class );
         
         criteria.add( Restrictions.eq( "dataSet", dataSet ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-10-01 10:19:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-10-01 11:57:21 +0000
@@ -143,7 +143,7 @@
   <bean id="org.hisp.dhis.dataset.CompleteDataSetRegistrationStore"
     class="org.hisp.dhis.dataset.hibernate.HibernateCompleteDataSetRegistrationStore">
     <property name="sessionFactory" ref="sessionFactory" />
-    <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+    <property name="periodStore" ref="org.hisp.dhis.period.PeriodStore" />
   </bean>
 
   <bean id="org.hisp.dhis.minmax.MinMaxDataElementStore" class="org.hisp.dhis.minmax.hibernate.HibernateMinMaxDataElementStore">