@Test public void shouldCreateQueriesForGivenFormats() { EqualProperty eqProperty = new EqualProperty<>("strProp", "text", String.class.getName()); CustomOperatorProperty matchesProperty1 = new CustomOperatorProperty<>("textField", "searchStr", String.class.getName(), "matches()"); CustomOperatorProperty matchesProperty2 = new CustomOperatorProperty<>("textField2", "searchStr", String.class.getName(), "matches()"); String pattern = "%s && (%s || %s)"; List<Property> properties = asList(eqProperty, matchesProperty1, matchesProperty2); QueryUtil.useFilterFromPattern(query, pattern, properties); verify(query).setFilter("strProp == param0 && (textField.matches(param1) || textField2.matches(param2))"); verify(query).declareParameters("java.lang.String param0, java.lang.String param1, java.lang.String param2"); }
public static void useFilterFromPattern(Query query, String pattern, List<Property> properties) { int propertiesCount = (properties == null) ? 0 : properties.size(); CharSequence[] propertyArgs = new CharSequence[propertiesCount]; CharSequence[] declareParameters = new CharSequence[propertiesCount]; for (int i = 0; i < propertiesCount; i++) { propertyArgs[i] = properties.get(i).asFilter(i); declareParameters[i] = properties.get(i).asDeclareParameter(i); } query.setFilter(String.format(pattern, propertyArgs)); query.declareParameters(StringUtils.join(declareParameters, ", ")); }
QueryUtil { public static void useFilterFromPattern(Query query, String pattern, List<Property> properties) { int propertiesCount = (properties == null) ? 0 : properties.size(); CharSequence[] propertyArgs = new CharSequence[propertiesCount]; CharSequence[] declareParameters = new CharSequence[propertiesCount]; for (int i = 0; i < propertiesCount; i++) { propertyArgs[i] = properties.get(i).asFilter(i); declareParameters[i] = properties.get(i).asDeclareParameter(i); } query.setFilter(String.format(pattern, propertyArgs)); query.declareParameters(StringUtils.join(declareParameters, ", ")); } }
QueryUtil { public static void useFilterFromPattern(Query query, String pattern, List<Property> properties) { int propertiesCount = (properties == null) ? 0 : properties.size(); CharSequence[] propertyArgs = new CharSequence[propertiesCount]; CharSequence[] declareParameters = new CharSequence[propertiesCount]; for (int i = 0; i < propertiesCount; i++) { propertyArgs[i] = properties.get(i).asFilter(i); declareParameters[i] = properties.get(i).asDeclareParameter(i); } query.setFilter(String.format(pattern, propertyArgs)); query.declareParameters(StringUtils.join(declareParameters, ", ")); } private  QueryUtil(); }
QueryUtil { public static void useFilterFromPattern(Query query, String pattern, List<Property> properties) { int propertiesCount = (properties == null) ? 0 : properties.size(); CharSequence[] propertyArgs = new CharSequence[propertiesCount]; CharSequence[] declareParameters = new CharSequence[propertiesCount]; for (int i = 0; i < propertiesCount; i++) { propertyArgs[i] = properties.get(i).asFilter(i); declareParameters[i] = properties.get(i).asDeclareParameter(i); } query.setFilter(String.format(pattern, propertyArgs)); query.declareParameters(StringUtils.join(declareParameters, ", ")); } private  QueryUtil(); static void setQueryParams(Query query, QueryParams queryParams); static void useFilters(Query query, Filters filters); static void useFilter(Query query, String[] properties, Object[] values, Map<String, String> fieldTypeMap); static void useFilter(Query query, String[] properties, Object[] values, Map<String, String> fieldTypeMap,
                                 InstanceSecurityRestriction restriction); static void useFilter(Query query, List<Property> properties); static void useFilter(Query query, List<Property> properties,
                                 InstanceSecurityRestriction restriction); static void useFilterFromPattern(Query query, String pattern, List<Property> properties); static String asMatchesPattern(String string); static String asEqualsPattern(String string); static void setCountResult(Query query); }
QueryUtil { public static void useFilterFromPattern(Query query, String pattern, List<Property> properties) { int propertiesCount = (properties == null) ? 0 : properties.size(); CharSequence[] propertyArgs = new CharSequence[propertiesCount]; CharSequence[] declareParameters = new CharSequence[propertiesCount]; for (int i = 0; i < propertiesCount; i++) { propertyArgs[i] = properties.get(i).asFilter(i); declareParameters[i] = properties.get(i).asDeclareParameter(i); } query.setFilter(String.format(pattern, propertyArgs)); query.declareParameters(StringUtils.join(declareParameters, ", ")); } private  QueryUtil(); static void setQueryParams(Query query, QueryParams queryParams); static void useFilters(Query query, Filters filters); static void useFilter(Query query, String[] properties, Object[] values, Map<String, String> fieldTypeMap); static void useFilter(Query query, String[] properties, Object[] values, Map<String, String> fieldTypeMap,
                                 InstanceSecurityRestriction restriction); static void useFilter(Query query, List<Property> properties); static void useFilter(Query query, List<Property> properties,
                                 InstanceSecurityRestriction restriction); static void useFilterFromPattern(Query query, String pattern, List<Property> properties); static String asMatchesPattern(String string); static String asEqualsPattern(String string); static void setCountResult(Query query);  }