← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10436: Sql Views. Dropping sql views in reversed alphabetical order and re-creating them in regular alph...

 

------------------------------------------------------------
revno: 10436
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-29 12:56:00 +0100
message:
  Sql Views. Dropping sql views in reversed alphabetical order and re-creating them in regular alphabetical order. This allows for an ad-hoc way of having dependencies between views.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.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/sqlview/DefaultSqlViewService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.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/sqlview/SqlViewExpandStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.java	2013-01-28 19:43:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.java	2013-03-29 11:56:00 +0000
@@ -1,6 +1,6 @@
 package org.hisp.dhis.sqlview;
 
-import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 import org.hisp.dhis.common.Grid;
@@ -17,7 +17,7 @@
     // SqlView expanded
     // -------------------------------------------------------------------------
 
-    Collection<String> getAllSqlViewNames();
+    List<String> getAllSqlViewNames();
 
     boolean isViewTableExists( String viewTableName );
 

=== 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-01-28 19:43:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2013-03-29 11:56:00 +0000
@@ -70,8 +70,6 @@
     // SqlView Expanded
     // -------------------------------------------------------------------------
 
-    Collection<String> getAllSqlViewNames();
-
     boolean isViewTableExists( String viewTableName );
 
     boolean createAllViewTables();

=== 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	2013-01-28 19:43:36 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2013-03-29 11:56:00 +0000
@@ -27,11 +27,15 @@
  * 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.List;
 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;
 
@@ -136,12 +140,6 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public Collection<String> getAllSqlViewNames()
-    {
-        return sqlViewExpandStore.getAllSqlViewNames();
-    }
-
-    @Override
     public boolean isViewTableExists( String viewTableName )
     {
         return sqlViewExpandStore.isViewTableExists( viewTableName );
@@ -152,7 +150,11 @@
     {
         boolean success = true;
 
-        for ( SqlView sqlView : getAllSqlViews() )
+        List<SqlView> sqlViews = new ArrayList<SqlView>( getAllSqlViews() );
+        
+        Collections.sort( sqlViews, IdentifiableObjectNameComparator.INSTANCE );
+        
+        for ( SqlView sqlView : sqlViews )
         {
             if ( createViewTable( sqlView ) != null )
             {
@@ -194,7 +196,12 @@
     @Override
     public void dropAllSqlViewTables()
     {
-        for ( String viewName : getAllSqlViewNames() )
+        List<String> sqlViewNames = sqlViewExpandStore.getAllSqlViewNames();
+        
+        Collections.sort( sqlViewNames );
+        Collections.reverse( sqlViewNames );
+        
+        for ( String viewName : sqlViewNames )
         {
             dropViewTable( viewName );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java	2013-01-28 19:43:36 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java	2013-03-29 11:56:00 +0000
@@ -32,13 +32,12 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Collection;
-import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
+import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.Log;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.sqlview.SqlView;
 import org.hisp.dhis.sqlview.SqlViewExpandStore;
@@ -76,9 +75,9 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public Collection<String> getAllSqlViewNames()
+    public List<String> getAllSqlViewNames()
     {
-        Set<String> viewersName = new HashSet<String>();
+        List<String> viewNames = new ArrayList<String>();
 
         try
         {
@@ -88,7 +87,7 @@
 
             while ( rs.next() )
             {
-                viewersName.add( rs.getString( "TABLE_NAME" ) );
+                viewNames.add( rs.getString( "TABLE_NAME" ) );
             }
         }
         catch ( SQLException e )
@@ -96,7 +95,7 @@
             e.printStackTrace();
         }
 
-        return viewersName;
+        return viewNames;
 
     }