private static void appendDynamicQuery(final StringBuilder jpqlString, final Map<String, Object> parameters,
            List<String> categories, List<String> aliases, List<String> deviceTypes) {

        // OPTIONAL query arguments, as provided.....
        // are aliases present ??
        if (isListEmpty(aliases)) {
            // append the string:
            jpqlString.append(" AND installation.alias IN :aliases");
            // add the params:
            parameters.put("aliases", aliases);
        }

        // are devices present ??
        if (isListEmpty(deviceTypes)) {
            // append the string:
            jpqlString.append(" AND installation.deviceType IN :deviceTypes");
            // add the params:
            parameters.put("deviceTypes", deviceTypes);
        }

        // is a category present ?
        if (isListEmpty(categories)) {
            jpqlString.append(" AND ( c.name in (:categories))");
            parameters.put("categories", categories);
        }
    }
private static void appendDynamicQuery ( final StringBuilder jpqlString , final Map < String , Object > parameters , List < String > categories , List < String > aliases , List < String > deviceTypes ) { if ( isListEmpty ( aliases ) ) { jpqlString . append ( " AND installation.alias IN :aliases" ) ; parameters . put ( "aliases" , aliases ) ; } if ( isListEmpty ( deviceTypes ) ) { jpqlString . append ( " AND installation.deviceType IN :deviceTypes" ) ; parameters . put ( "deviceTypes" , deviceTypes ) ; } if ( isListEmpty ( categories ) ) { jpqlString . append ( " AND ( c.name in (:categories))" ) ; parameters . put ( "categories" , categories ) ; } }
A dynamic finder for all sorts of queries around selecting Device-Token, based on different criterias.
The method appends different criterias to the given JPQL string, IF PRESENT.

Done in one method, instead of having similar, but error-thrown Strings, in different methods.

TODO: perhaps moving to Criteria API for this later