Search in sources :

Example 1 with QueryAndParameterAppender

use of org.jbpm.query.jpa.impl.QueryAndParameterAppender in project jbpm by kiegroup.

the class JPAAuditLogService method createDeleteQuery.

private static String createDeleteQuery(String queryBase, QueryWhere queryWhere, Map<String, Object> queryParams, boolean skipMetaParams, String subQuery) {
    // setup
    StringBuilder queryBuilder = new StringBuilder(queryBase);
    QueryAndParameterAppender queryAppender = new QueryAndParameterAppender(queryBuilder, queryParams);
    boolean addLastCriteria = false;
    List<Object[]> varValCriteriaList = new ArrayList<Object[]>();
    List<QueryCriteria> queryWhereCriteriaList = queryWhere.getCriteria();
    // 3. apply normal query parameters
    checkVarValCriteria(queryWhere, varValCriteriaList);
    // last criteria
    Iterator<QueryCriteria> iter = queryWhereCriteriaList.iterator();
    while (iter.hasNext()) {
        QueryCriteria criteria = iter.next();
        if (criteria.getListId().equals(LAST_VARIABLE_LIST)) {
            addLastCriteria = true;
            iter.remove();
        }
    }
    for (QueryCriteria criteria : queryWhere.getCriteria()) {
        String listId = criteria.getListId();
        switch(criteria.getType()) {
            case NORMAL:
                queryAppender.addQueryParameters(criteria.getParameters(), listId, criteriaFieldClasses.get(listId), criteriaFields.get(listId), criteria.isUnion());
                break;
            case RANGE:
                queryAppender.addRangeQueryParameters(criteria.getParameters(), listId, criteriaFieldClasses.get(listId), criteriaFields.get(listId), criteria.isUnion());
                break;
            case REGEXP:
                List<String> stringParams = castToStringList(criteria.getParameters());
                queryAppender.addRegexQueryParameters(stringParams, listId, criteriaFields.get(listId), criteria.isUnion());
                break;
            default:
                throw new IllegalArgumentException("Unknown criteria type in delete query builder: " + criteria.getType().toString());
        }
    }
    while (queryAppender.getParenthesesNesting() > 0) {
        queryAppender.closeParentheses();
    }
    // 6. Add special criteria
    boolean addWhereClause = !queryAppender.hasBeenUsed();
    if (!varValCriteriaList.isEmpty()) {
        addVarValCriteria(addWhereClause, queryAppender, "l", varValCriteriaList);
        addWhereClause = false;
    }
    if (addLastCriteria) {
        addLastInstanceCriteria(queryAppender);
    }
    if (subQuery != null && !subQuery.isEmpty()) {
        queryAppender.addToQueryBuilder(subQuery, false);
    }
    // 8. return query
    return queryBuilder.toString();
}
Also used : QueryCriteria(org.jbpm.query.jpa.data.QueryCriteria) ArrayList(java.util.ArrayList) QueryAndParameterAppender(org.jbpm.query.jpa.impl.QueryAndParameterAppender)

Aggregations

ArrayList (java.util.ArrayList)1 QueryCriteria (org.jbpm.query.jpa.data.QueryCriteria)1 QueryAndParameterAppender (org.jbpm.query.jpa.impl.QueryAndParameterAppender)1