← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7656: Sql view, simplification, no need to have view name generation method in store when it has no dep...

 

------------------------------------------------------------
revno: 7656
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-07-21 15:43:46 +0200
message:
  Sql view, simplification, no need to have view name generation method in store when it has no dependencies
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java
  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
  dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/CheckViewTableExistenceAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.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/SqlView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java	2012-04-11 04:56:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java	2012-07-21 13:43:46 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.regex.Pattern;
+
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonView;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
@@ -44,6 +46,8 @@
 public class SqlView
     extends BaseIdentifiableObject
 {
+    public static final String PREFIX_VIEWNAME = "_view";
+
     // -------------------------------------------------------------------------
     // Variables
     // -------------------------------------------------------------------------
@@ -109,6 +113,28 @@
     }
 
     // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public String getViewName()
+    {
+        final Pattern p = Pattern.compile( "\\W" );
+
+        String input = new String( this.name );
+        
+        String[] items = p.split( input.trim().replaceAll( "_", "" ) );
+
+        input = "";
+
+        for ( String s : items )
+        {
+            input += (s.equals( "" ) == true) ? "" : ("_" + s);
+        }
+
+        return PREFIX_VIEWNAME + input;
+    }
+    
+    // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
 

=== 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	2012-04-04 10:48:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewExpandStore.java	2012-07-21 13:43:46 +0000
@@ -26,7 +26,5 @@
 
     void setUpDataSqlViewTable( Grid sqlViewGrid, String viewTableName );
 
-    String setUpViewTableName( String input );
-
     String testSqlGrammar( String sql );
 }

=== 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	2012-04-04 10:48:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2012-07-21 13:43:46 +0000
@@ -65,8 +65,6 @@
 
     String makeUpForQueryStatement( String query );
 
-    String setUpViewTableName( String input );
-
     // -------------------------------------------------------------------------
     // SqlView Expanded
     // -------------------------------------------------------------------------
@@ -84,6 +82,8 @@
     void dropAllSqlViewTables();
 
     Grid getDataSqlViewGrid( String viewTableName );
-
+    
+    Grid getDataSqlViewGrid( SqlView sqlView );
+    
     String testSqlGrammar( String sql );
 }

=== 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	2012-04-04 10:48:27 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2012-07-21 13:43:46 +0000
@@ -135,12 +135,6 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public String setUpViewTableName( String input )
-    {
-        return sqlViewExpandStore.setUpViewTableName( input );
-    }
-
-    @Override
     public Collection<String> getAllSqlViewNames()
     {
         return sqlViewExpandStore.getAllSqlViewNames();
@@ -185,6 +179,12 @@
     }
 
     @Override
+    public Grid getDataSqlViewGrid( SqlView sqlView )
+    {
+        return getDataSqlViewGrid( sqlView.getViewName() );
+    }
+
+    @Override
     public String testSqlGrammar( String sql )
     {
         return sqlViewExpandStore.testSqlGrammar( sql );

=== 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	2012-07-20 09:12:57 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java	2012-07-21 13:43:46 +0000
@@ -35,7 +35,6 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.regex.Pattern;
 
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.sqlview.SqlView;
@@ -56,12 +55,8 @@
 
     private static final String PREFIX_SELECT_QUERY = "SELECT * FROM ";
 
-    private static final String PREFIX_VIEWNAME = "_view";
-
     private static final String[] types = { "VIEW" };
 
-    private static final Pattern p = Pattern.compile( "\\W" );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -87,7 +82,7 @@
         {
             mtdt = jdbcTemplate.getDataSource().getConnection().getMetaData();
 
-            ResultSet rs = mtdt.getTables( null, null, PREFIX_VIEWNAME + "%", types );
+            ResultSet rs = mtdt.getTables( null, null, SqlView.PREFIX_VIEWNAME + "%", types );
 
             while ( rs.next() )
             {
@@ -124,7 +119,7 @@
     @Override
     public String createView( SqlView sqlViewInstance )
     {
-        String viewName = setUpViewTableName( sqlViewInstance.getName() );
+        String viewName = sqlViewInstance.getViewName();
 
         try
         {
@@ -147,7 +142,7 @@
 
         try
         {
-            rs = this.getScrollableResult( PREFIX_SELECT_QUERY + viewTableName, jdbcTemplate );
+            rs = this.getResultSet( PREFIX_SELECT_QUERY + viewTableName, jdbcTemplate );
         }
         catch ( SQLException e )
         {
@@ -159,21 +154,6 @@
     }
 
     @Override
-    public String setUpViewTableName( String input )
-    {
-        String[] items = p.split( input.trim().replaceAll( "_", "" ) );
-
-        input = "";
-
-        for ( String s : items )
-        {
-            input += (s.equals( "" ) == true) ? "" : ("_" + s);
-        }
-
-        return PREFIX_VIEWNAME + input;
-    }
-
-    @Override
     public String testSqlGrammar( String sql )
     {
         try
@@ -213,7 +193,7 @@
      * @param holder the StatementHolder object
      * @return null or the ResultSet
      */
-    private ResultSet getScrollableResult( String sql, JdbcTemplate jdbcTemplate )
+    private ResultSet getResultSet( String sql, JdbcTemplate jdbcTemplate )
         throws SQLException
     {
         Connection con = jdbcTemplate.getDataSource().getConnection();

=== 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	2012-03-12 20:25:54 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/sqlview/SqlViewServiceTest.java	2012-07-21 13:43:46 +0000
@@ -203,14 +203,8 @@
         SqlView sqlViewC = createSqlView( 'C', SQL3 );
         SqlView sqlViewD = createSqlView( 'D', SQL4 );
 
-        sqlViewService.saveSqlView( sqlViewC );
-        sqlViewService.saveSqlView( sqlViewD );
-
-        String viewC = sqlViewService.setUpViewTableName( sqlViewService.getSqlView( "SqlViewC" ).getName() );
-        String viewD = sqlViewService.setUpViewTableName( sqlViewService.getSqlView( "SqlViewD" ).getName() );
-
-        assertEquals( "_view_SqlViewC", viewC );
-        assertNotSame( "_view_SqlViewC", viewD );
+        assertEquals( "_view_SqlViewC", sqlViewC.getViewName() );
+        assertNotSame( "_view_SqlViewC", sqlViewD.getViewName() );
 
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/CheckViewTableExistenceAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/CheckViewTableExistenceAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/CheckViewTableExistenceAction.java	2012-07-21 13:43:46 +0000
@@ -98,7 +98,7 @@
             return ERROR;
         }
 
-        String viewTableName = sqlViewService.setUpViewTableName( sqlViewService.getSqlView( id ).getName() );
+        String viewTableName = sqlViewService.getSqlView( id ).getViewName();
 
         if ( !sqlViewService.isViewTableExists( viewTableName ) )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java	2012-03-01 08:45:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/sqlview/ExecuteSqlViewQueryAction.java	2012-07-21 13:43:46 +0000
@@ -96,7 +96,8 @@
         }
 
         SqlView sqlViewInstance = sqlViewService.getSqlView( id );
-        String viewName = sqlViewService.setUpViewTableName( sqlViewInstance.getName() );
+        
+        String viewName = sqlViewInstance.getViewName();
 
         message = sqlViewService.createViewTable( sqlViewInstance );