/** * Generates portion of the query for subcapability WHERE * * @param sql already existing portion of the SQL, with SELECT and FROM clauses finished * @param capabilityAlias alias of the capability for which the condition is to be made * @param filter filter describing the condition * @param filterPath indexes into the capability lists up to the root starting from this * capability filter. It is used to give MyBatis information where to look for parameter * values */ private void processCapabilityWhere( SimpleStringBuilder sql, String capabilityAlias, CapabilityFilter filter, List<Integer> filterPath) { sql.append("(", capabilityAlias, ".namespace = "); buildParameterValuePath(sql, filterPath, null, "namespace"); processAttributesWhere(sql, filter.getAttributes(), filterPath, capabilityAlias); for (int i = 0; i < filter.getSubFilters().size(); i++) { List<Integer> path = new LinkedList<>(filterPath); path.add(i); sql.append(" AND "); processCapabilityWhere(sql, capabilityAlias + i, filter.getSubFilters().get(i), path); } sql.append(")"); }
/** * Generates portion of the query for subcapability JOIN * * @param sql already existing portion of the SQL, presumed to have at least SELECT and FROM * clauses. * @param filter filter for the particular subcapability * @param parentCapabilityAlias alias of the subcapability's parent in the #sql query */ private void processSubCapabilitiesJoin( SQL sql, CapabilityFilter filter, String parentCapabilityAlias) { String subAlias; CapabilityFilter subFilter; for (int k = 0; k < filter.getSubFilters().size(); k++) { subFilter = filter.getSubFilters().get(k); subAlias = parentCapabilityAlias + k; sql.INNER_JOIN( "capability " + subAlias + " ON " + parentCapabilityAlias + ".capability_id = " + subAlias + ".parent_capability_id"); processAttributesJoin(sql, subFilter.getAttributes(), subAlias); processSubCapabilitiesJoin(sql, subFilter, subAlias); } }