Create interface for access to generated filter Builder classes
See original GitHub issueIs your feature request related to a problem? Please describe. Have many objects with same field - coding each one is tedious when I need to do something like set the default ‘statusCode’ to a standard query of int eq 0. Looking for a leaner way to do bulk query initialization in code.
Describe the solution you’d like Change the generated inner class on objects from “public static class Builder {” to something like “public static class Builder implements QBuilder” or some interface name of your choosing. This way with my 20 builder objects that I’m setting up - instead of calling builderX.setStatusCode(…) on every one I can create a method that accepts a list of QBuilder interfaces and call a generic version of the set methods that are generated. Here’s an example of the common set method implementation:
public schema.queryObj_filter.Builder withStatusCode(schema.INTEGERQueryArgument $value) {
((schema.queryObj_filter)RuntimeMethods.constructProxy(this._result, schema.queryObj_filter.class)).getBindings().put("statusCode", RuntimeMethods.coerceToBindingValue($value));
return this;
}
new interface method could be something like
@Override
public QBuilder setBinding (String $key, Object $value) {
((schema.queryObj_filter)RuntimeMethods.constructProxy(this._result, schema.queryObj_filter.class)).getBindings().put($key, RuntimeMethods.coerceToBindingValue($value));
return this;
}
Generated code for all the set methods then could be changed to:
public schema.queryObj_filter.Builder withStatusCode(schema.INTEGERQueryArgument $value) {
return setBinding("statusCode", $value);
}
Describe alternatives you’ve considered Reflection on client side would be too slow. only alternative is to have chunky code that sets the same thing on every strongly typed Builder class.
Additional context This will allow me to create code like
void setDefaultCriteria (String fieldName, IBindingsBacked query, QBuilder... filterBuilders) {
Arrays.stream(filterBuilders).forEach(f -> f.setBinding(fieldName, query));
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
GqlBuilder interface working great for us - thanks!! This can be closed.
@djchapm sorry about the inconvenience. As you’ve discovered method refs are not supported on structural interfaces, see https://github.com/manifold-systems/manifold/issues/30. This may be addressed in a future release, but for now lambdas are the workaround.