public static String createResultCountQuery ( String query ) { String resultCountQueryString = null ; int select = query . toLowerCase ( ) . indexOf ( "select" ) ; int from = query . toLowerCase ( ) . indexOf ( "from" ) ; if ( select == - 1 || from == - 1 ) { return null ; } resultCountQueryString = "select count(" + query . substring ( select + 6 , from ) . trim ( ) + ") " + query . substring ( from ) ; // remove order by // TODO: remove more parts if ( resultCountQueryString . toLowerCase ( ) . contains ( "order by" ) ) { resultCountQueryString = resultCountQueryString . substring ( 0 , resultCountQueryString . toLowerCase ( ) . indexOf ( "order by" ) ) ; } log . debug ( "Created query for counting results '{}'" , resultCountQueryString ) ; return resultCountQueryString ; }
Build a query based on the original query to count results