← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2027: Centralized the reload period methods

 

------------------------------------------------------------
revno: 2027
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Mon 2010-06-21 23:21:07 +0200
message:
  Centralized the reload period methods
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.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/PeriodStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodStore.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodStore.java	2010-06-21 21:21:07 +0000
@@ -165,6 +165,25 @@
      */
     Collection<Period> getPeriods( Period period, Collection<DataElement> dataElements, Collection<? extends Source> sources );
     
+    /**
+     * Checks if the given period is associated with the current session and loads
+     * it if not. Null is returned if the period does not exist.
+     * 
+     * @param period the Period.
+     * @return the Period.
+     */
+    Period reloadPeriod( Period period );
+
+    /**
+     * Checks if the given period is associated with the current session and loads
+     * it if not. The period is persisted if it does not exist. The persisted Period
+     * is returned.
+     * 
+     * @param period the Period.
+     * @return the persisted Period.
+     */
+    Period reloadForceAddPeriod( Period period );
+    
     // -------------------------------------------------------------------------
     // PeriodType
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java	2010-05-18 15:42:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java	2010-06-21 21:21:07 +0000
@@ -75,42 +75,12 @@
     }
 
     // -------------------------------------------------------------------------
-    // Support methods for reloading periods
-    // -------------------------------------------------------------------------
-
-    private final Period reloadPeriod( Period period )
-    {
-        Session session = sessionFactory.getCurrentSession();
-
-        if ( session.contains( period ) )
-        {
-            return period; // Already in session, no reload needed
-        }
-
-        return periodStore.getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() );
-    }
-
-    private final Period reloadPeriodForceAdd( Period period )
-    {
-        Period storedPeriod = reloadPeriod( period );
-
-        if ( storedPeriod == null )
-        {
-            periodStore.addPeriod( period );
-
-            return period;
-        }
-
-        return storedPeriod;
-    }
-
-    // -------------------------------------------------------------------------
     // Basic DataValue
     // -------------------------------------------------------------------------
 
     public void addDataValue( DataValue dataValue )
     {
-        dataValue.setPeriod( reloadPeriodForceAdd( dataValue.getPeriod() ) );
+        dataValue.setPeriod( periodStore.reloadForceAddPeriod( dataValue.getPeriod() ) );
 
         Session session = sessionFactory.getCurrentSession();
 
@@ -119,7 +89,7 @@
 
     public void updateDataValue( DataValue dataValue )
     {
-        dataValue.setPeriod( reloadPeriodForceAdd( dataValue.getPeriod() ) );
+        dataValue.setPeriod( periodStore.reloadForceAddPeriod( dataValue.getPeriod() ) );
 
         Session session = sessionFactory.getCurrentSession();
 
@@ -158,7 +128,7 @@
     {
         Session session = sessionFactory.getCurrentSession();
 
-        Period storedPeriod = reloadPeriod( period );
+        Period storedPeriod = periodStore.reloadPeriod( period );
 
         if ( storedPeriod == null )
         {
@@ -200,7 +170,7 @@
     @SuppressWarnings( "unchecked" )
     public Collection<DataValue> getDataValues( Source source, Period period )
     {
-        Period storedPeriod = reloadPeriod( period );
+        Period storedPeriod = periodStore.reloadPeriod( period );
 
         if ( storedPeriod == null )
         {
@@ -243,7 +213,7 @@
     @SuppressWarnings( "unchecked" )
     public Collection<DataValue> getDataValues( Source source, Period period, Collection<DataElement> dataElements )
     {
-        Period storedPeriod = reloadPeriod( period );
+        Period storedPeriod = periodStore.reloadPeriod( period );
 
         if ( storedPeriod == null )
         {
@@ -264,7 +234,7 @@
     public Collection<DataValue> getDataValues( Source source, Period period, Collection<DataElement> dataElements,
         Collection<DataElementCategoryOptionCombo> optionCombos )
     {
-        Period storedPeriod = reloadPeriod( period );
+        Period storedPeriod = periodStore.reloadPeriod( period );
 
         if ( storedPeriod == null )
         {
@@ -286,7 +256,7 @@
     public Collection<DataValue> getDataValues( DataElement dataElement, Period period,
         Collection<? extends Source> sources )
     {
-        Period storedPeriod = reloadPeriod( period );
+        Period storedPeriod = periodStore.reloadPeriod( period );
 
         if ( storedPeriod == null )
         {
@@ -311,7 +281,7 @@
 
         for ( Period period : periods )
         {
-            Period storedPeriod = reloadPeriod( period );
+            Period storedPeriod = periodStore.reloadPeriod( period );
 
             if ( storedPeriod != null )
             {
@@ -337,7 +307,7 @@
 
         for ( Period period : periods )
         {
-            Period storedPeriod = reloadPeriod( period );
+            Period storedPeriod = periodStore.reloadPeriod( period );
 
             if ( storedPeriod != null )
             {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java	2010-05-18 15:42:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java	2010-06-21 21:21:07 +0000
@@ -196,6 +196,32 @@
         return periods;
     }
 
+    public Period reloadPeriod( Period period )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        if ( session.contains( period ) )
+        {
+            return period; // Already in session, no reload needed
+        }
+
+        return getPeriod( period.getStartDate(), period.getEndDate(), period.getPeriodType() );
+    }
+
+    public Period reloadForceAddPeriod( Period period )
+    {
+        Period storedPeriod = reloadPeriod( period );
+
+        if ( storedPeriod == null )
+        {
+            addPeriod( period );
+
+            return period;
+        }
+
+        return storedPeriod;
+    }
+
     // -------------------------------------------------------------------------
     // PeriodType
     // -------------------------------------------------------------------------