Skip to content

Add the conflicts flag to view queries. #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions org.ektorp/src/main/java/org/ektorp/ViewQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void copyTo(KeyOrRawKey other) {
private boolean inclusiveEnd = true;
private boolean ignoreNotFound = false;
private boolean updateSeq = false;
private boolean conflicts = false;

private boolean cacheOk = false;

Expand Down Expand Up @@ -191,6 +192,10 @@ public boolean isUpdateSeq() {
return updateSeq;
}

public boolean isConflicts() {
return conflicts;
}

public ViewQuery dbPath(String s) {
reset();
dbPath = s;
Expand Down Expand Up @@ -608,6 +613,17 @@ public ViewQuery updateSeq(boolean b) {
return this;
}

/**
* The conflicts option will include the conflicting revisions for each document.
* @param b the conflicts flag
* @return the view query for chained calls
*/
public ViewQuery conflicts(boolean b) {
reset();
conflicts = b;
return this;
}

public ViewQuery queryParam(String name, String value) {
queryParams.put(name, value);
return this;
Expand Down Expand Up @@ -721,6 +737,11 @@ public URI buildQueryURI() {
if(updateSeq) {
query.param("update_seq", "true");
}

if (conflicts) {
query.param("conflicts", "true");
}

return query;
}

Expand Down Expand Up @@ -752,6 +773,7 @@ public ViewQuery clone() {
copy.startDocId = startDocId;
startKey.copyTo(copy.startKey);
copy.updateSeq = updateSeq;
copy.conflicts = conflicts;
copy.viewName = viewName;
return copy;
}
Expand Down Expand Up @@ -813,6 +835,7 @@ public int hashCode() {
result = prime * result + (includeDocs ? 1231 : 1237);
result = prime * result + (inclusiveEnd ? 1231 : 1237);
result = prime * result + (updateSeq ? 1231 : 1237);
result = prime * result + (conflicts ? 1231 : 1237);
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + limit;
result = prime * result
Expand Down Expand Up @@ -878,6 +901,8 @@ public boolean equals(Object obj) {
return false;
if (updateSeq != other.updateSeq)
return false;
if (conflicts != other.conflicts)
return false;
if (key == null) {
if (other.key != null)
return false;
Expand Down
10 changes: 9 additions & 1 deletion org.ektorp/src/test/java/org/ektorp/ViewQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ public void update_seq_parameter_added() {
.buildQuery();
assertTrue(contains(url, "?update_seq=true"));
}


@Test
public void conflicts_parameter_added() {
String url = query
.conflicts(true)
.buildQuery();
assertTrue(contains(url, "?conflicts=true"));
}

@Test
public void stale_ok_parameter_added() {
String url = query
Expand Down