Thanks for the suggestion. I’ll add the ability to set the viewmode property programmatically for the 2.8-beta release.
As for changes, we definitely made a few API changes. I’ll try to capture them all here, but if I miss something let me know.
The first thing we did was made it so that there is only one query function. Previously, we had three, but now based on how you define your query CouchbaseClient will call the appropriate query function. So we have
HttpFuture asyncQuery(View view, Query query)
instead of
ViewFuture asyncQuery(View view, Query query)
HttpFuture asyncQueryAndExcludeDocs(View view, Query query)
HttpFuture asyncQueryAndReduce(View view, Query query)
We also made all ViewResponse classes (ViewResponseWithDocs, ViewResponseNoDocs, ViewResponseReduced) implement ViewResponse and all classes contain the same functions. What this means to you is that developers only need to be aware of the ViewResponse class.
We also consolidated the Row classes and renamed them. All of the row classes now implement ViewRow and contain all of the Row classes contain the same functions. This means that you only have to deal with one type, ViewRow, when dealing with rows.
I put some examples below of the new API, but first off I want to mention that with this added simplicity you also need to be a little bit more careful about how you use the api. For example, if you do a query that doesn’t get the document for each row and you try to access the document in the ViewRow you will get an exception saying that the view doesn’t contain documents. This shouldn’t present any huge issues for developers, but it does mean that you need to be aware of what type of query you are doing and handle the response appropriately.
Old API:
Query query = new Query();
query.setRange(“a”, “m”);
query.setDescending(false);
ViewFuture result = client.query(view, query);
ViewResponseWithDocs response;
try {
response = result.get();
} catch (ExecutionException e) {
e.printStackTrace();
continue;
}
Iterator itr = response.iterator();
while(itr.hasNext()) {
RowWithDocs row = itr.next();
String doc = (String)row.getDoc();
System.out.println(doc);
}
New API:
Query query = new Query();
query.setRange(“a”, “m”);
query.setDescending(false);
query.setIncludeDocs(true);
HttpFuture result = client.asyncQuery(view, query);
ViewResponse response;
try {
response = result.get();
} catch (ExecutionException e) {
e.printStackTrace();
continue;
}
Iterator itr = response.iterator();
while(itr.hasNext()) {
ViewRow row = itr.next();
String doc = (String)row.getDoc();
System.out.println(doc);
}
If you wish to track your improvement request I have filed it here.
http://www.couchbase.com/issues/browse/SPY-50
Let me know if you have any other questions.