← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18467: Resource tables, moved createAll/dropAll methods to resource table service to ensure that all vie...

 

------------------------------------------------------------
revno: 18467
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-03-03 17:18:51 +0100
message:
  Resource tables, moved createAll/dropAll methods to resource table service to ensure that all views are dropped in separate transaction, so that process continues even if drop operations fail
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java
  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/scheduling/ResourceTableTask.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/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-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2015-02-20 14:46:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2015-03-03 16:18:51 +0000
@@ -94,4 +94,14 @@
      * option combinations.
      */
     void generateDataElementCategoryOptionComboTable();
+    
+    /**
+     * Create all SQL views.
+     */
+    void createAllSqlViews();
+    
+    /**
+     * Drop all SQL views.
+     */
+    void dropAllSqlViews();
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2015-02-20 14:46:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2015-03-03 16:18:51 +0000
@@ -86,10 +86,6 @@
 
     String createViewTable( SqlView sqlView );
 
-    void createAllSqlViews();
-    
-    void dropAllSqlViews();
-    
     void dropViewTable( String viewName );
     
     /**

=== 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	2015-02-20 14:46:12 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2015-03-03 16:18:51 +0000
@@ -70,6 +70,8 @@
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.resourcetable.statement.CreateCategoryOptionGroupSetTableStatement;
+import org.hisp.dhis.sqlview.SqlView;
+import org.hisp.dhis.sqlview.SqlViewService;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -133,6 +135,13 @@
         this.periodService = periodService;
     }
 
+    private SqlViewService sqlViewService;
+
+    public void setSqlViewService( SqlViewService sqlViewService )
+    {
+        this.sqlViewService = sqlViewService;
+    }
+
     // -------------------------------------------------------------------------
     // OrganisationUnitStructure
     // -------------------------------------------------------------------------
@@ -507,4 +516,40 @@
 
         log.info( "Data element category option combo table generated" );
     }
+    
+    // -------------------------------------------------------------------------
+    // SQL Views. Each view is created/dropped in separate transactions so that
+    // process continues even if individual operations fail.
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void createAllSqlViews()
+    {
+        List<SqlView> views = new ArrayList<>( sqlViewService.getAllSqlViewsNoAcl() );
+        Collections.sort( views, IdentifiableObjectNameComparator.INSTANCE );
+        
+        for ( SqlView view : views )
+        {
+            if ( !view.isQuery() )
+            {
+                sqlViewService.createViewTable( view );
+            }
+        }
+    }
+
+    @Override
+    public void dropAllSqlViews()
+    {
+        List<SqlView> views = new ArrayList<>( sqlViewService.getAllSqlViewsNoAcl() );
+        Collections.sort( views, IdentifiableObjectNameComparator.INSTANCE );
+        Collections.reverse( views );
+
+        for ( SqlView view : views )
+        {
+            if ( !view.isQuery() )
+            {
+                sqlViewService.dropViewTable( view.getViewName() );
+            }
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java	2015-02-20 14:46:12 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java	2015-03-03 16:18:51 +0000
@@ -36,7 +36,6 @@
 import org.hisp.dhis.resourcetable.ResourceTableService;
 import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.setting.SystemSettingManager;
-import org.hisp.dhis.sqlview.SqlViewService;
 import org.hisp.dhis.system.notification.NotificationLevel;
 import org.hisp.dhis.system.notification.Notifier;
 import org.hisp.dhis.system.util.Clock;
@@ -53,9 +52,6 @@
     private ResourceTableService resourceTableService;
     
     @Autowired
-    private SqlViewService sqlViewService;
-    
-    @Autowired
     private Notifier notifier;
 
     @Autowired
@@ -111,7 +107,7 @@
 
     private void generateAll()
     {
-        sqlViewService.dropAllSqlViews();
+        resourceTableService.dropAllSqlViews();
         resourceTableService.generateOrganisationUnitStructures();   
         resourceTableService.generateCategoryOptionComboNames();
         resourceTableService.generateCategoryOptionGroupSetTable();
@@ -123,6 +119,6 @@
         resourceTableService.generatePeriodTable();
         resourceTableService.generateDatePeriodTable();
         resourceTableService.generateDataElementCategoryOptionComboTable();
-        sqlViewService.createAllSqlViews();
+        resourceTableService.createAllSqlViews();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2015-02-22 20:02:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2015-03-03 16:18:51 +0000
@@ -28,11 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.regex.Matcher;
@@ -42,7 +39,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.IllegalQueryException;
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.system.grid.ListGrid;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -161,38 +157,6 @@
     }
     
     @Override
-    public void createAllSqlViews()
-    {
-        List<SqlView> views = new ArrayList<>( getAllSqlViewsNoAcl() );
-        Collections.sort( views, IdentifiableObjectNameComparator.INSTANCE );
-        
-        for ( SqlView view : views )
-        {
-            if ( !view.isQuery() )
-            {
-                createViewTable( view );
-            }
-        }
-    }
-
-
-    @Override
-    public void dropAllSqlViews()
-    {
-        List<SqlView> views = new ArrayList<>( getAllSqlViewsNoAcl() );
-        Collections.sort( views, IdentifiableObjectNameComparator.INSTANCE );
-        Collections.reverse( views );
-
-        for ( SqlView view : views )
-        {
-            if ( !view.isQuery() )
-            {
-                dropViewTable( view.getViewName() );
-            }
-        }
-    }
-    
-    @Override
     public Grid getSqlViewGrid( SqlView sqlView, Map<String, String> criteria, Map<String, String> variables )
     {
         Grid grid = new ListGrid();

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2015-02-27 13:42:52 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2015-03-03 16:18:51 +0000
@@ -17,6 +17,7 @@
     <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
     <property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
     <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+    <property name="sqlViewService" ref="org.hisp.dhis.sqlview.SqlViewService" />
   </bean>
   
   <!-- Data integrity -->

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2015-02-27 12:31:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2015-03-03 16:18:51 +0000
@@ -48,7 +48,6 @@
 import org.hisp.dhis.resourcetable.ResourceTableService;
 import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.setting.SystemSettingManager;
-import org.hisp.dhis.sqlview.SqlViewService;
 import org.hisp.dhis.system.notification.Notifier;
 import org.hisp.dhis.system.util.Clock;
 import org.hisp.dhis.system.util.ConcurrentUtils;
@@ -80,9 +79,6 @@
     private ResourceTableService resourceTableService;
     
     @Autowired
-    private SqlViewService sqlViewService;
-    
-    @Autowired
     private PartitionManager partitionManager;
     
     @Autowired
@@ -169,7 +165,7 @@
     @Override
     public void generateResourceTables()
     {
-        sqlViewService.dropAllSqlViews();
+        resourceTableService.dropAllSqlViews();
         resourceTableService.generateOrganisationUnitStructures();        
         resourceTableService.generateCategoryOptionComboNames();
         resourceTableService.generateCategoryOptionGroupSetTable();
@@ -181,7 +177,7 @@
         resourceTableService.generatePeriodTable();
         resourceTableService.generateDatePeriodTable();
         resourceTableService.generateDataElementCategoryOptionComboTable();
-        sqlViewService.createAllSqlViews();
+        resourceTableService.createAllSqlViews();
     }
     
     // -------------------------------------------------------------------------
@@ -285,14 +281,14 @@
     
     private void swapTables( List<AnalyticsTable> tables )
     {
-        sqlViewService.dropAllSqlViews();
+        resourceTableService.dropAllSqlViews();
         
         for ( AnalyticsTable table : tables )
         {
             tableManager.swapTable( table );
         }
         
-        sqlViewService.createAllSqlViews();
+        resourceTableService.createAllSqlViews();
     }
     
     /**

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java	2015-03-02 07:43:42 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MaintenanceController.java	2015-03-03 16:18:51 +0000
@@ -28,21 +28,30 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.analytics.partition.PartitionManager;
 import org.hisp.dhis.cache.HibernateCacheManager;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dxf2.common.Options;
 import org.hisp.dhis.dxf2.metadata.ExportService;
 import org.hisp.dhis.dxf2.metadata.MetaData;
-import org.hisp.dhis.dxf2.common.Options;
 import org.hisp.dhis.dxf2.render.RenderService;
 import org.hisp.dhis.dxf2.schema.SchemaValidator;
 import org.hisp.dhis.dxf2.schema.ValidationViolation;
 import org.hisp.dhis.maintenance.MaintenanceService;
+import org.hisp.dhis.resourcetable.ResourceTableService;
 import org.hisp.dhis.schema.Property;
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
-import org.hisp.dhis.sqlview.SqlViewService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -50,15 +59,6 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
-import javax.servlet.http.HttpServletResponse;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author Lars Helge Overland
  */
@@ -93,7 +93,7 @@
     private RenderService renderService;
     
     @Autowired
-    private SqlViewService sqlViewService;
+    private ResourceTableService resourceTableService;
 
     @RequestMapping( value = "/periodPruning", method = { RequestMethod.PUT, RequestMethod.POST } )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )
@@ -113,14 +113,14 @@
     @PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )
     public void dropSqlViews()
     {
-        sqlViewService.dropAllSqlViews();
+        resourceTableService.dropAllSqlViews();
     }
     
     @RequestMapping( value = "/createSqlViews", method = { RequestMethod.PUT, RequestMethod.POST } )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )
     public void createSqlViews()
     {
-        sqlViewService.createAllSqlViews();
+        resourceTableService.createAllSqlViews();
     }
     
     @RequestMapping( value = "/categoryOptionComboUpdate", method = { RequestMethod.PUT, RequestMethod.POST } )

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java	2015-02-20 14:53:31 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/maintenance/PerformMaintenanceAction.java	2015-03-03 16:18:51 +0000
@@ -38,7 +38,7 @@
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.datamart.DataMartManager;
 import org.hisp.dhis.maintenance.MaintenanceService;
-import org.hisp.dhis.sqlview.SqlViewService;
+import org.hisp.dhis.resourcetable.ResourceTableService;
 import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork2.Action;
@@ -113,11 +113,11 @@
         this.categoryService = categoryService;
     }
 
-    private SqlViewService sqlViewService;
+    private ResourceTableService resourceTableService;
 
-    public void setSqlViewService( SqlViewService sqlViewService )
+    public void setResourceTableService( ResourceTableService resourceTableService )
     {
-        this.sqlViewService = sqlViewService;
+        this.resourceTableService = resourceTableService;
     }
 
     // -------------------------------------------------------------------------
@@ -206,7 +206,7 @@
         
         if ( clearAnalytics )
         {
-            sqlViewService.dropAllSqlViews();
+            resourceTableService.dropAllSqlViews();
             analyticsTableService.dropTables();
             completenessTableService.dropTables();
             completenessTargetTableService.dropTables();
@@ -272,14 +272,14 @@
 
         if ( dropSqlViews )
         {
-            sqlViewService.dropAllSqlViews();
+            resourceTableService.dropAllSqlViews();
             
             log.info( "'" + username + "': Dropped SQL views" );
         }
         
         if ( createSqlViews )
         {
-            sqlViewService.createAllSqlViews();
+            resourceTableService.createAllSqlViews();
             
             log.info( "'" + username + "': Created SQL views" );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2015-02-20 14:53:31 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml	2015-03-03 16:18:51 +0000
@@ -14,7 +14,7 @@
     <property name="dataMartManager" ref="org.hisp.dhis.datamart.DataMartManager" />
     <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
     <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
-    <property name="sqlViewService" ref="org.hisp.dhis.sqlview.SqlViewService" />
+    <property name="resourceTableService" ref="org.hisp.dhis.resourcetable.ResourceTableService" />
   </bean>
 
   <!-- Cache -->