Permalink
Browse files

Patches from Michael Bridgen <mikeb@lshift.net>

  • Loading branch information...
1 parent 56f7d25 commit 99997caec6580daacc33f148d8addfbc8528c4d0 @mbreese committed Jun 25, 2009
@@ -44,7 +44,9 @@
private Session session;
- private static final String VIEW = "_view";
+ private static final String VIEW = "/_view/";
+ private static final String DESIGN = "_design/";
+
/**
* C-tor only used by the Session object. You'd never call this directly.
@@ -118,8 +120,8 @@ public ViewResults getAllDocuments(int revision) {
* @return
*/
public ViewResults view(View view) {
- return view(view, true);
- }
+ return view(view, true);
+ }
/**
* Runs a view, appending "_view" to the request if isPermanentView is true.
@@ -131,7 +133,8 @@ public ViewResults view(View view) {
private ViewResults view(final View view, final boolean isPermanentView) {
String url = null;
if (isPermanentView) {
- url = this.name + "/" + VIEW + "/" + view.getFullName();
+ String[] elements = view.getFullName().split("/");
+ url = this.name + "/" + ((elements.length < 2) ? elements[0] : DESIGN + elements[0] + VIEW + elements[1]);
} else {
url = this.name + "/" + view.getFullName();
}
@@ -94,7 +94,9 @@ public Session(String host, int port, String user, String pass, boolean usesAuth
this.secure = secure;
DefaultHttpClient defaultClient = new DefaultHttpClient();
- defaultClient.getCredentialsProvider().setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(user, pass) );
+ if (user != null) {
+ defaultClient.getCredentialsProvider().setCredentials( AuthScope.ANY, new UsernamePasswordCredentials(user, pass) );
+ }
this.httpClient = defaultClient;
@@ -236,7 +238,7 @@ protected String buildUrl(String url) {
}
protected String buildUrl(String url, String queryString) {
- return url + "?" + queryString;
+ return (queryString != null) ? buildUrl(url) + "?" + queryString : buildUrl(url);
}
protected String buildUrl(String url, NameValuePair[] params) {
@@ -382,7 +384,9 @@ protected CouchResponse http(HttpRequestBase req) {
HttpEntity entity = null;
try {
- req.getParams().setBooleanParameter(ClientPNames.HANDLE_AUTHENTICATION, true);
+ if (usesAuth) {
+ req.getParams().setBooleanParameter(ClientPNames.HANDLE_AUTHENTICATION, true);
+ }
httpResponse = httpClient.execute(req);
entity = httpResponse.getEntity();
lastResponse = new CouchResponse(req, httpResponse);
@@ -30,10 +30,11 @@
public class View {
protected String startKey;
protected String endKey;
- protected Integer count;
+ protected Integer limit;
protected Boolean update;
protected Boolean reverse;
protected String skip;
+ protected Boolean group;
protected String name;
protected Document document;
@@ -64,7 +65,7 @@ public View(String fullname) {
* This <i>does not actually add it to the document</i>. That is handled by
* Document.addView()
* <p>
- * This contructor should only be called by Document.addView();
+ * This constructor should only be called by Document.addView();
*
* @param doc
* @param name
@@ -96,28 +97,44 @@ public String getQueryString() {
if (!queryString.equals("")) { queryString+="&"; }
queryString+="skip="+skip;
}
- if (count!=null) {
+ if (limit!=null) {
if (!queryString.equals("")) { queryString+="&"; }
- queryString+="count="+count;
+ queryString+="limit="+limit;
}
if (update!=null && update.booleanValue()) {
if (!queryString.equals("")) { queryString+="&"; }
queryString+="update=true";
}
if (reverse!=null && reverse.booleanValue()) {
if (!queryString.equals("")) { queryString+="&"; }
- queryString+="reverse=true";
+ queryString+="descending=true";
}
+ if (group!=null && group.booleanValue()) {
+ if (!queryString.equals("")) { queryString+="&"; }
+ queryString+="group=true";
+ }
return queryString.equals("") ? null : queryString;
+
}
/**
* The number of entries to return
* @param count
+ * @deprecated CouchDB 0.9 uses limit instead
*/
public void setCount(Integer count) {
- this.count = count;
+ //this.count = count;
+ setLimit(count);
}
+
+ public void setLimit(Integer limit) {
+ this.limit = limit;
+ }
+
+ public void setGroup(Boolean group) {
+ this.group = group;
+ }
+
/**
* Stop listing at this key
* @param endKey
@@ -128,10 +145,15 @@ public void setEndKey(String endKey) {
/**
* Reverse the listing
* @param reverse
+ * @deprecated CouchDB 0.9 uses "descending" instead
*/
public void setReverse(Boolean reverse) {
this.reverse = reverse;
}
+
+ public void setDescending(Boolean descending) {
+ this.reverse = descending;
+ }
/**
* Skip listing these keys (not sure if this works, or the format)
* @param skip

0 comments on commit 99997ca

Please sign in to comment.