=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java' --- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java 2014-03-17 17:34:56 +0000 +++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/hibernate/HibernateTrackedEntityInstanceStore.java 2014-03-17 17:39:08 +0000 @@ -122,6 +122,10 @@ public List> getTrackedEntityInstances( TrackedEntityInstanceQueryParams params ) { SqlHelper hlp = new SqlHelper(); + + // --------------------------------------------------------------------- + // Select clause + // --------------------------------------------------------------------- String sql = "select tei.uid as " + TRACKED_ENTITY_INSTANCE_ID + ", " + @@ -138,6 +142,10 @@ } sql = sql.substring( 0, sql.length() - 2 ); // Remove last comma + + // --------------------------------------------------------------------- + // From, join and restriction clause + // --------------------------------------------------------------------- sql += "from trackedentityinstance tei " + @@ -175,9 +183,22 @@ { sql += hlp.whereAnd() + " tei.organisationunitid in (" + getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ") "; } - + + // --------------------------------------------------------------------- + // Paging clause + // --------------------------------------------------------------------- + + if ( params.isPaging() ) + { + sql += "limit " + params.getPageSizeWithDefault() + " offset " + params.getOffset(); + } + log.info( "Tracked entity instance query SQL: " + sql ); - + + // --------------------------------------------------------------------- + // Query + // --------------------------------------------------------------------- + SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql ); List> list = new ArrayList>();