← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13901: SQL views, resource tables. Making sure individual views are dropped/created in separate transact...

 

------------------------------------------------------------
revno: 13901
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-30 18:10:35 +0200
message:
  SQL views, resource tables. Making sure individual views are dropped/created in separate transactions so that if one fails it will abort the tx, and the next one will run in its own tx instead of attempting new operation in an aborted tx.
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-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.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/resourcetable/ResourceTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2013-09-24 07:41:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2014-01-30 16:10:35 +0000
@@ -87,4 +87,14 @@
      * option combinations.
      */
     void generateDataElementCategoryOptionComboTable();
+    
+    /**
+     * Create all sql views in the database.
+     */
+    void createAllSqlViews();
+    
+    /**
+     * Drop all sql views in the database.
+     */
+    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	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2014-01-30 16:10:35 +0000
@@ -73,14 +73,10 @@
 
     boolean viewTableExists( String viewTableName );
 
-    boolean createAllViewTables();
-
     String createViewTable( SqlView sqlViewInstance );
 
     void dropViewTable( String viewName );
 
-    void dropAllSqlViewTables();
-
     Grid getSqlViewGrid( SqlView sqlView, Map<String, String> criteria );
     
     String testSqlGrammar( String sql );

=== 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	2013-09-24 07:41:09 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2014-01-30 16:10:35 +0000
@@ -72,6 +72,8 @@
 import org.hisp.dhis.resourcetable.statement.CreateDataElementGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateIndicatorGroupSetTableStatement;
 import org.hisp.dhis.resourcetable.statement.CreateOrganisationUnitGroupSetTableStatement;
+import org.hisp.dhis.sqlview.SqlView;
+import org.hisp.dhis.sqlview.SqlViewService;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
@@ -135,6 +137,13 @@
     {
         this.periodService = periodService;
     }
+    
+    private SqlViewService sqlViewService;
+
+    public void setSqlViewService( SqlViewService sqlViewService )
+    {
+        this.sqlViewService = sqlViewService;
+    }
 
     // -------------------------------------------------------------------------
     // OrganisationUnitStructure
@@ -568,4 +577,34 @@
         
         log.info( "Data element category option combo table generated" );
     }
+
+    // -------------------------------------------------------------------------
+    // SQL views
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void createAllSqlViews()
+    {
+        List<SqlView> sqlViews = new ArrayList<SqlView>( sqlViewService.getAllSqlViews() );
+        Collections.sort( sqlViews, IdentifiableObjectNameComparator.INSTANCE );
+
+        for ( SqlView sqlView : sqlViews )
+        {
+            sqlViewService.createViewTable( sqlView );
+        }
+    }
+
+
+    @Override
+    public void dropAllSqlViews()
+    {
+        List<SqlView> views = new ArrayList<SqlView>( sqlViewService.getAllSqlViews() );
+        Collections.sort( views, IdentifiableObjectNameComparator.INSTANCE );
+        Collections.reverse( views );
+
+        for ( SqlView view : views )
+        {
+            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	2013-09-24 07:41:09 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/scheduling/ResourceTableTask.java	2014-01-30 16:10:35 +0000
@@ -31,7 +31,6 @@
 import org.hisp.dhis.message.MessageService;
 import org.hisp.dhis.resourcetable.ResourceTableService;
 import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.sqlview.SqlViewService;
 import org.hisp.dhis.system.notification.NotificationLevel;
 import org.hisp.dhis.system.notification.Notifier;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,9 +45,6 @@
     private ResourceTableService resourceTableService;
     
     @Autowired
-    private SqlViewService sqlViewService;
-
-    @Autowired
     private Notifier notifier;
 
     @Autowired
@@ -92,7 +88,7 @@
 
     private void generateAll()
     {
-        sqlViewService.dropAllSqlViewTables();
+        resourceTableService.dropAllSqlViews();
         resourceTableService.generateOrganisationUnitStructures();        
         resourceTableService.generateCategoryOptionComboNames();
         resourceTableService.generateDataElementGroupSetTable();
@@ -103,6 +99,6 @@
         resourceTableService.generatePeriodTable();
         resourceTableService.generateDatePeriodTable();
         resourceTableService.generateDataElementCategoryOptionComboTable();
-        sqlViewService.createAllViewTables();
+        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	2014-01-28 14:18:54 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2014-01-30 16:10:35 +0000
@@ -28,18 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+import java.util.Map;
+
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.common.Grid;
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.system.grid.ListGrid;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author Dang Duy Hieu
  * @version $Id DefaultSqlViewService.java July 06, 2010$
@@ -149,26 +145,6 @@
     }
 
     @Override
-    public boolean createAllViewTables()
-    {
-        boolean success = true;
-
-        List<SqlView> sqlViews = new ArrayList<SqlView>( getAllSqlViews() );
-
-        Collections.sort( sqlViews, IdentifiableObjectNameComparator.INSTANCE );
-
-        for ( SqlView sqlView : sqlViews )
-        {
-            if ( createViewTable( sqlView ) != null )
-            {
-                success = false;
-            }
-        }
-
-        return success;
-    }
-
-    @Override
     public String createViewTable( SqlView sqlViewInstance )
     {
         return sqlViewExpandStore.createViewTable( sqlViewInstance );
@@ -195,18 +171,4 @@
     {
         sqlViewExpandStore.dropViewTable( sqlViewTableName );
     }
-
-    @Override
-    public void dropAllSqlViewTables()
-    {
-        List<SqlView> views = sqlViewStore.getAllOrderedName();
-
-        Collections.sort( views, IdentifiableObjectNameComparator.INSTANCE );
-        Collections.reverse( views );
-
-        for ( SqlView view : views )
-        {
-            dropViewTable( view.getViewName() );
-        }
-    }
 }
\ No newline at end of file

=== 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	2013-09-24 11:21:38 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2014-01-30 16:10:35 +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-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java	2013-10-02 14:23:56 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java	2014-01-30 16:10:35 +0000
@@ -221,34 +221,6 @@
     }
 
     @Test
-    public void testGetAllSqlViewNames()
-    {
-        SqlView sqlViewA = createSqlView( 'A', SQL4 );
-        SqlView sqlViewB = createSqlView( 'B', SQL4 );
-        SqlView sqlViewC = createSqlView( 'C', SQL4 );
-        SqlView sqlViewD = createSqlView( 'D', SQL4 );
-
-        sqlViewService.saveSqlView( sqlViewA );
-        sqlViewService.saveSqlView( sqlViewB );
-        sqlViewService.saveSqlView( sqlViewC );
-        sqlViewService.saveSqlView( sqlViewD );
-
-        boolean flag = sqlViewService.createAllViewTables();
-
-        assertTrue( flag );
-
-        sqlViewService.dropViewTable( sqlViewA.getViewName() );
-        sqlViewService.dropViewTable( sqlViewB.getViewName() );
-        sqlViewService.dropViewTable( sqlViewC.getViewName() );
-        sqlViewService.dropViewTable( sqlViewD.getViewName() );
-
-        sqlViewService.deleteSqlView( sqlViewA );
-        sqlViewService.deleteSqlView( sqlViewB );
-        sqlViewService.deleteSqlView( sqlViewC );
-        sqlViewService.deleteSqlView( sqlViewD );
-    }
-
-    @Test
     public void testTestSqlGrammar()
     {
         String sql = "select de.name, de.name from dataelement de";

=== 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	2013-11-18 14:39:37 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2014-01-30 16:10:35 +0000
@@ -154,7 +154,7 @@
 
     public void generateResourceTables()
     {
-        sqlViewService.dropAllSqlViewTables();
+        resourceTableService.dropAllSqlViews();
         resourceTableService.generateOrganisationUnitStructures();        
         resourceTableService.generateCategoryOptionComboNames();
         resourceTableService.generateDataElementGroupSetTable();
@@ -165,7 +165,7 @@
         resourceTableService.generatePeriodTable();
         resourceTableService.generateDatePeriodTable();
         resourceTableService.generateDataElementCategoryOptionComboTable();
-        sqlViewService.createAllViewTables();
+        resourceTableService.createAllSqlViews();
     }
     
     // -------------------------------------------------------------------------