private void performMultiQuery ( HttpServletRequest request , HttpServletResponse response ) throws Exception { User user = AuthenticationUtils . getUserFromRequest ( request ) ; String [ ] queriesStrings = request . getParameterValues ( "queries" ) ; if ( 1 != queriesStrings . length ) { throw new Exception ( "Parameter 'queries' must be specified exactly oncce" ) ; } // Create list of Query instances List < Query > queries = parseQueriesJson ( queriesStrings [ 0 ] ) ; // Perform queries JSONObject result = new JSONObject ( ) ; { Map < String , DbTableAccess > tableAccessCache = new HashMap < String , DbTableAccess > ( ) ; for ( Query query : queries ) { String tableName = query . getTableName ( ) ; List < RecordSelector > whereMap = query . getWhereExpressions ( ) ; List < FieldSelector > fieldSelectors = query . getFieldSelectors ( ) ; List < FieldSelector > groupByColumnNames = query . getGroupByColumnNames ( ) ; List < OrderSpecifier > orderSpecifiers = query . getOrderBySpecifiers ( ) ; Integer limit = query . getLimit ( ) ; Integer offset = query . getOffset ( ) ; DbTableAccess tableAccess = tableAccessCache . get ( tableName ) ; if ( null == tableAccess ) { tableAccess = DbTableAccess . getAccess ( dbSecurity , tableName , new DbUserAdaptor ( user ) ) ; tableAccessCache . put ( tableName , tableAccess ) ; } try { JSONArray queriedObjects = tableAccess . query ( whereMap , fieldSelectors , groupByColumnNames , orderSpecifiers , limit , offset ) ; result . put ( query . getQueryKey ( ) , queriedObjects ) ; } catch ( Exception e ) { result . put ( query . getQueryKey ( ) , errorToJson ( e ) ) ; } } } sendJsonResponse ( response , result ) ; }
Perform multiple SQL queries via dbSec .