@@ -43,7 +43,18 @@ enum QueryAnalyzeMode {
43
43
* to the first {@link ResultSet#next()} call. Regardless of blocking behavior, any {@link
44
44
* SpannerException} is deferred to the first or subsequent {@link ResultSet#next()} call.
45
45
*
46
- * <p>TODO(user): Code examples.
46
+ * <!--SNIPPET read_context_read-->
47
+ * <pre>{@code
48
+ * ReadContext readContext = dbClient.singleUse();
49
+ * ResultSet resultSet =
50
+ * readContext.read(
51
+ * "Albums",
52
+ * // KeySet.all() can be used to read all rows in a table. KeySet exposes other
53
+ * // methods to read only a subset of the table.
54
+ * KeySet.all(),
55
+ * Arrays.asList("SingerId", "AlbumId", "AlbumTitle"));
56
+ * }</pre>
57
+ * <!--SNIPPET read_context_read-->
47
58
*
48
59
* @param table the name of the table to read
49
60
* @param keys the keys and ranges of rows to read. Regardless of ordering in {@code keys}, rows
@@ -61,6 +72,15 @@ enum QueryAnalyzeMode {
61
72
* to the first {@link ResultSet#next()} call. Regardless of blocking behavior, any {@link
62
73
* SpannerException} is deferred to the first or subsequent {@link ResultSet#next()} call.
63
74
*
75
+ * <!--SNIPPET read_context_read_index-->
76
+ * <pre>{@code
77
+ * ReadContext readContext = dbClient.singleUse();
78
+ * Struct row =
79
+ * readContext.readRowUsingIndex("Albums", "AlbumsByAlbumId", Key.of(1, "Green"),
80
+ * Arrays.asList("AlbumId", "AlbumTitle"));
81
+ * }</pre>
82
+ * <!--SNIPPET read_context_read_index-->
83
+ *
64
84
* @param table the name of the table to read
65
85
* @param index the name of the index on {@code table} to use
66
86
* @param keys the keys and ranges of index rows to read. Regardless of ordering in {@code keys},
@@ -74,6 +94,14 @@ ResultSet readUsingIndex(
74
94
/**
75
95
* Reads a single row from a database, returning {@code null} if the row does not exist.
76
96
*
97
+ * <!--SNIPPET read_context_read_row-->
98
+ * <pre>{@code
99
+ * ReadContext readContext = dbClient.singleUse();
100
+ * Struct row =
101
+ * readContext.readRow("Albums", Key.of(2, 1), Arrays.asList("MarketingBudget"));
102
+ * }</pre>
103
+ * <!--SNIPPET read_context_read_row-->
104
+ *
77
105
* @param table the name of the table to read
78
106
* @param key the row to read
79
107
* @param columns the columns to return
@@ -85,6 +113,15 @@ ResultSet readUsingIndex(
85
113
* Reads a single row from a database using an index, returning {@code null} if the row does not
86
114
* exist.
87
115
*
116
+ * <!--SNIPPET read_context_read_index-->
117
+ * <pre>{@code
118
+ * ReadContext readContext = dbClient.singleUse();
119
+ * Struct row =
120
+ * readContext.readRowUsingIndex("Albums", "AlbumsByAlbumId", Key.of(1, "Green"),
121
+ * Arrays.asList("AlbumId", "AlbumTitle"));
122
+ * }</pre>
123
+ * <!--SNIPPET read_context_read_index-->
124
+ *
88
125
* @param table the name of the table to read
89
126
* @param index the name of the index on {@code table} to use
90
127
* @param key the index row to read
@@ -101,6 +138,18 @@ ResultSet readUsingIndex(
101
138
* is deferred to the first {@link ResultSet#next()} call. Regardless of blocking behavior, any
102
139
* {@link SpannerException} is deferred to the first or subsequent {@link ResultSet#next()} call.
103
140
*
141
+ * <!--SNIPPET read_context_execute_query-->
142
+ * <pre>{@code
143
+ * // Rows without an explicit value for MarketingBudget will have a MarketingBudget equal to
144
+ * // null.
145
+ * ReadContext readContext = dbClient.singleUse();
146
+ * ResultSet resultSet =
147
+ * readContext.executeQuery(
148
+ * Statement.of(
149
+ * "SELECT SingerId, AlbumId, MarketingBudget, LastUpdateTime FROM Albums"));
150
+ * }</pre>
151
+ * <!--SNIPPET read_context_execute_query-->
152
+ *
104
153
* @param statement the query statement to execute
105
154
* @param options the options to configure the query
106
155
*/
@@ -113,6 +162,21 @@ ResultSet readUsingIndex(
113
162
* com.google.spanner.v1.ResultSetStats} that can be accessed by calling {@link
114
163
* ResultSet#getStats()} on the returned {@code ResultSet}.
115
164
*
165
+ * <!--SNIPPET read_context_analyze_query-->
166
+ * <pre>{@code
167
+ * ReadContext rc = dbClient.singleUse();
168
+ * ResultSet resultSet =
169
+ * rc.analyzeQuery(
170
+ * Statement.of("SELECT SingerId, AlbumId, MarketingBudget FROM Albums"),
171
+ * ReadContext.QueryAnalyzeMode.PROFILE);
172
+ * while (resultSet.next()) {
173
+ * // Discard the results. We're only processing because getStats() below requires it.
174
+ * resultSet.getCurrentRowAsStruct();
175
+ * }
176
+ * ResultSetStats stats = resultSet.getStats();
177
+ * }</pre>
178
+ * <!--SNIPPET read_context_analyze_query-->
179
+ *
116
180
* @param statement the query statement to execute
117
181
* @param queryMode the mode in which to execute the query
118
182
*/
0 commit comments