dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25297
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12513: Event analytics, making sure that queries for partitions which do not exist fail gracefully and a...
------------------------------------------------------------
revno: 12513
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-10-08 19:54:16 +0200
message:
Event analytics, making sure that queries for partitions which do not exist fail gracefully and allow data for partitions that do exist to be returned
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.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-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-10-08 16:55:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-10-08 17:54:16 +0000
@@ -36,6 +36,8 @@
import java.util.Arrays;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.analytics.DataQueryParams;
import org.hisp.dhis.analytics.event.EventAnalyticsManager;
import org.hisp.dhis.analytics.event.EventQueryParams;
@@ -46,9 +48,11 @@
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.system.grid.ListGrid;
import org.hisp.dhis.system.util.TextUtils;
import org.hisp.dhis.system.util.Timer;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
@@ -60,8 +64,12 @@
public class JdbcEventAnalyticsManager
implements EventAnalyticsManager
{
+ private static final Log log = LogFactory.getLog( JdbcEventAnalyticsManager.class );
+
private static final int MAX_LIMIT = 10000;
+ private static final String QUERY_ERR_MSG = "Query failed, likely because the requested analytics table does not exist";
+
@Autowired
private JdbcTemplate jdbcTemplate;
@@ -114,8 +122,24 @@
// Grid
// ---------------------------------------------------------------------
+ try
+ {
+ grid.addRows( getAggregatedEventData( params, sql ) );
+ }
+ catch ( BadSqlGrammarException ex )
+ {
+ log.info( QUERY_ERR_MSG, ex );
+ }
+
+ return grid;
+ }
+
+ private Grid getAggregatedEventData( EventQueryParams params, String sql )
+ {
Timer t = new Timer().start();
+ Grid grid = new ListGrid();
+
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
t.getTime( "Analytics event aggregate SQL: " + sql );
@@ -190,7 +214,23 @@
int rowLength = grid.getHeaders().size();
+ try
+ {
+ grid.addRows( getEvents( params, sql, rowLength ) );
+ }
+ catch ( BadSqlGrammarException ex )
+ {
+ log.info( QUERY_ERR_MSG, ex );
+ }
+
+ return grid;
+ }
+
+ private Grid getEvents( EventQueryParams params, String sql, int rowLength )
+ {
Timer t = new Timer().start();
+
+ Grid grid = new ListGrid();
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
@@ -210,13 +250,29 @@
return grid;
}
-
+
public int getEventCount( EventQueryParams params )
{
String sql = "select count(psi) ";
sql += getFromWhereClause( params );
+ int count = 0;
+
+ try
+ {
+ count = getEventCount( sql );
+ }
+ catch ( BadSqlGrammarException ex )
+ {
+ log.info( QUERY_ERR_MSG, ex );
+ }
+
+ return count;
+ }
+
+ private int getEventCount( String sql )
+ {
Timer t = new Timer().start();
int count = jdbcTemplate.queryForObject( sql, Integer.class );