|
7 | 7 | import com.couchbase.client.java.json.JsonObject; |
8 | 8 | import com.couchbase.client.java.query.QueryOptions; |
9 | 9 | import com.couchbase.client.java.query.QueryResult; |
| 10 | +import com.couchbase.client.java.query.QueryScanConsistency; |
10 | 11 |
|
11 | 12 | import java.time.Duration; |
12 | 13 | import java.time.LocalDate; |
@@ -54,25 +55,27 @@ public static void main(String[] args) { |
54 | 55 |
|
55 | 56 | private static JsonObject retrieveStudent(Cluster cluster, String name) throws CouchbaseException { |
56 | 57 |
|
| 58 | + QueryOptions studentQueryOptions = QueryOptions.queryOptions(); |
| 59 | + studentQueryOptions.parameters(JsonObject.create().put("name", name)); |
| 60 | + studentQueryOptions.scanConsistency(QueryScanConsistency.REQUEST_PLUS); |
| 61 | + |
57 | 62 | final QueryResult result = cluster.query("select META().id, src.* " + |
58 | 63 | "from `student-bucket`.`art-school-scope`.`student-record-collection` src " + |
59 | | - "where src.`name` = $name", |
60 | | - QueryOptions.queryOptions() |
61 | | - .parameters(JsonObject.create() |
62 | | - .put("name", name))); |
| 64 | + "where src.`name` = $name", studentQueryOptions); |
63 | 65 |
|
64 | 66 | return result.rowsAsObject().get(0); |
65 | 67 |
|
66 | 68 | } |
67 | 69 |
|
68 | 70 | private static JsonObject retrieveCourse(Cluster cluster, String course) throws CouchbaseException { |
69 | 71 |
|
| 72 | + QueryOptions courseQueryOptions = QueryOptions.queryOptions(); |
| 73 | + courseQueryOptions.parameters(JsonObject.create().put("courseName", course)); |
| 74 | + courseQueryOptions.scanConsistency(QueryScanConsistency.REQUEST_PLUS); |
| 75 | + |
70 | 76 | final QueryResult result = cluster.query("select META().id, crc.* " + |
71 | 77 | "from `student-bucket`.`art-school-scope`.`course-record-collection` crc " + |
72 | | - "where crc.`course-name` = $courseName", |
73 | | - QueryOptions.queryOptions() |
74 | | - .parameters(JsonObject.create() |
75 | | - .put("courseName", course))); |
| 78 | + "where crc.`course-name` = $courseName", courseQueryOptions); |
76 | 79 |
|
77 | 80 | return result.rowsAsObject().get(0); |
78 | 81 |
|
|
0 commit comments