Closed julianobrasil closed 3 years ago
One from main philosophy whinstone is keep SQL away from java, but for whinstone-couchdb there is one way to do that.
I didn't try but you need create a Selector Class that represents Request JSON Object
public class SelectorSample {
@JsonProperty("selector")
private Selector selector;
@JsonProperty("fields")
private List<String> fields = null;
@JsonProperty("sort")
private List<Sort> sort = null;
@JsonProperty("limit")
private Integer limit;
@JsonProperty("skip")
private Integer skip;
@JsonProperty("execution_stats")
private Boolean executionStats;
Your XML
<select id="generic-query" returnType="my.domain.MyEntity">
:query
</select>
Your java:
SelectorSample selector = new SelectorSample();
QueryFactory.of("generic-query","query", selector);
whinstone-couchdb parse your object parameters using jackson
String jsonBody = new ObjectMapper().readValue(selector);
The jsonBody
beccome HTTP body. So your SelectorSample class must be very smart to represent the attribute selector couchdb request JSON object with your operators and combination of operators like $eq, $gt, $gte, $lt, $lte, $elemMatch, $allMatch etc.
Thanks. I'll test it and let you know the result.
Is there a way I can send an entire mango query to the xml file? I was thinking of doing this:
and then, in java code, send the entire query through the
query
key. But I couldn't figure out how to right double quotes to the query variable without messing with the final generated mango json query.If I do something like:
I end up with
Because the above
json
attributes are written without any double quotes (malformed),couchdb
doesn't execute the query.If I do something like (trying to escape the double quotes in
Java
):I end up with the following json:
Actually in the project I was just trying out
jkniv
possibilities, as it could open my way to build a fluentQueryBuilder
, for exemple. (In the real project, I can work it around by writing specific queries in thexml
file).