Skip to content

Commit 620d4c0

Browse files
authored
Merge pull request #103 from djsauble/patch-18
Update FindPage.java
2 parents 1a42351 + b0954e7 commit 620d4c0

File tree

1 file changed

+35
-41
lines changed
  • astra-db-client/src/test/java/com/dtsx/astra/sdk/documentation

1 file changed

+35
-41
lines changed

astra-db-client/src/test/java/com/dtsx/astra/sdk/documentation/FindPage.java

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,42 @@
99
import io.stargate.sdk.json.domain.odm.Result;
1010

1111
public class FindPage {
12-
public static void main(String[] args) {
13-
14-
// Accessing existing DB
15-
AstraDB db = new AstraDB("<token>", "<api_endpoint>");
16-
17-
// Access existing collection
18-
AstraDBCollection collection = db
19-
.createCollection("collection_vector1", 14);
20-
21-
// Retrieve page1 of a search
22-
Page<JsonResult> page1 = collection.findPage(SelectQuery.builder()
23-
.where("product_price").isEqualsTo(9.99)
24-
.build());
25-
26-
// Retrieving page 2 of the same search if more than 20
27-
page1.getPageState().ifPresent(pageState -> {
28-
Page<JsonResult> page2 = collection.findPage(SelectQuery.builder()
29-
.where("product_price").isEqualsTo(9.99)
30-
.withPagingState(pageState)
31-
.build());
32-
});
33-
34-
/*
35-
* As for any find* you can map the output as Result<T>
36-
* using either a java pojo or mapper.
37-
*/
38-
Page<Result<MyBean>> page = collection.findPage(SelectQuery.builder()
39-
.where("product_price").isEqualsTo(9.99)
40-
.build(), MyBean.class);
41-
42-
}
43-
44-
public static class MyBean {
45-
@JsonProperty("product_name")
46-
String name;
47-
@JsonProperty("product_price")
48-
Double price;
12+
public static void main(String[] args) {
13+
AstraDB db = new AstraDB("<token>", "<api_endpoint>");
14+
AstraDBCollection collection = db.createCollection("collection_vector1", 14);
15+
16+
// Retrieve page 1 of a search (up to 20 results)
17+
Page<JsonResult> page1 = collection.findPage(
18+
SelectQuery.builder()
19+
.where("product_price")
20+
.isEqualsTo(9.99)
21+
.build());
22+
23+
// Retrieve page 2 of the same search (if there are more than 20 results)
24+
page1.getPageState().ifPresent(pageState -> {
25+
Page<JsonResult> page2 = collection.findPage(
26+
SelectQuery.builder()
27+
.where("product_price").isEqualsTo(9.99)
28+
.withPagingState(pageState)
29+
.build());
30+
});
31+
32+
// You can map the output as Result<T> using either a Java pojo or mapper
33+
Page<Result<MyBean>> page = collection.findPage(
34+
SelectQuery.builder()
35+
.where("product_price")
36+
.isEqualsTo(9.99)
37+
.build(),
38+
MyBean.class);
39+
}
40+
41+
public static class MyBean {
42+
@JsonProperty("product_name") String name;
43+
@JsonProperty("product_price") Double price;
4944

5045
public MyBean(String name, Double price) {
51-
this.name = name;
52-
this.price = price;
46+
this.name = name;
47+
this.price = price;
5348
}
54-
// getters and setters
55-
}
49+
}
5650
}

0 commit comments

Comments
 (0)