← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10566: Sql view, re-implemented check for existence of view using spring jdbc template to avoid potentia...

 

------------------------------------------------------------
revno: 10566
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-04-15 19:43:49 +0200
message:
  Sql view, re-implemented check for existence of view using spring jdbc template to avoid potential resource leak
modified:
  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-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-04-15 17:38:55 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/jdbc/JdbcSqlViewExpandStore.java	2013-04-15 17:43:49 +0000
@@ -28,7 +28,6 @@
  */
 
 import java.sql.Connection;
-import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -77,15 +76,13 @@
     {
         try
         {
-            DatabaseMetaData mtdt = jdbcTemplate.getDataSource().getConnection().getMetaData();
+            jdbcTemplate.queryForRowSet( "select * from " + viewTableName.toLowerCase() + " limit 1" );
             
-            ResultSet rs = mtdt.getTables( null, null, viewTableName.toLowerCase(), types );
-
-            return rs.next();
+            return true;
         }
-        catch ( Exception e )
+        catch ( BadSqlGrammarException ex )
         {
-            return false;
+            return false; // View does not exist
         }
     }