Not specifically about CouchDB, but have been experimenting with
REST-based Java/Groovy DAOs using CouchDB as the backend. Thought folks
here might be interested in the info.
I created some REST DAOs using Groovy's HttpBuilder, and Spring's
RestTemplate. Both use Google's GSON library for serializing to JSON.
Examples of create method:
Spring's RestTemplate implementation:
public String create(Pojo pojo) {
Map response = restTemplate.postForObject(url, pojo, Map.class);
String id = (String)response.get("id");
String rev = (String)response.get("rev");
pojo.setKey(id);
pojo.setRevision(rev);
return pojo.getKey();
}
Groovy's HttpBuilder implementation:
String create(Pojo pojo) {
httpBuilder.request(POST, JSON) {
send JSON, toJson(pojo)
response.success = {resp, json ->
pojo.key = json.id as String
pojo.revision = json.rev as String
}
}
pojo.key
}
The Spring implementation is nearly 50 times faster than the Groovy implementation!
Of course, the Groovy implementation was much easier to learn and implement the Couch API with and was great for prototyping.