Skip to content
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

Support multi-key querying with complex keys (issue #54) #56

Merged
merged 1 commit into from Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/lightcouch/View.java
Expand Up @@ -540,7 +540,7 @@ public View updateSeq(Boolean updateSeq) {
* @param keys
* @return
*/
public View keys(List<String> keys) {
public View keys(List<?> keys) {
this.allDocsKeys = String.format("{%s:%s}", gson.toJson("keys"), gson.toJson(keys));
return this;
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/lightcouch/tests/ViewsTest.java
Expand Up @@ -25,6 +25,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.Vector;

import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -94,6 +95,18 @@ public void byComplexKey() {
assertThat(foos.size(), is(2));
}

@Test
public void byComplexKeys() {
List<int[]> keysToGet = new Vector<int[]>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is just a test and doesn't need changing. But in Java you're generally better off using an ArrayList rather than a Vector because most code doesn't need the synchronization that Vector provides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. But as you said this is just a test so I'm not going to invest more time in it.

keysToGet.add(new int[] { 2011, 10, 15 });
keysToGet.add(new int[] { 2013, 12, 17 });
ViewResult<Integer[], Integer, Foo> fooRows = dbClient.view("example/by_date")
.keys(keysToGet)
.group(true)
.queryView(Integer[].class, Integer.class, Foo.class);
assertThat(fooRows.getRows().size(), is(2));
}

@Test
public void viewResultEntries() {
ViewResult<int[], String, Foo> viewResult = dbClient.view("example/by_date")
Expand Down