Skip to content

Commit 2392afe

Browse files
authored
docs(samples): add tag to statement timeout sample (#2931)
* docs(samples): add tag to statement timeout sample Add a tag to the StatementTimeoutExample, so we can include this sample in the documentation. * docs: add clarifying comment regarding setting longer timeout * chore: reduce line lengths
1 parent 4905921 commit 2392afe

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
class StatementTimeoutExample {
3434

35+
// [START spanner_set_statement_timeout]
36+
3537
static void executeSqlWithTimeout() {
3638
// TODO(developer): Replace these variables before running the sample.
3739
String projectId = "my-project";
@@ -52,6 +54,10 @@ public <ReqT, RespT> ApiCallContext configure(ApiCallContext context, ReqT reque
5254
MethodDescriptor<ReqT, RespT> method) {
5355
// DML uses the ExecuteSql RPC.
5456
if (method == SpannerGrpc.getExecuteSqlMethod()) {
57+
// NOTE: You can use a GrpcCallContext to set a custom timeout for a single RPC
58+
// invocation. This timeout can however ONLY BE SHORTER than the default timeout
59+
// for the RPC. If you set a timeout that is longer than the default timeout, then
60+
// the default timeout will be used.
5561
return GrpcCallContext.createDefault()
5662
.withCallOptions(CallOptions.DEFAULT.withDeadlineAfter(60L, TimeUnit.SECONDS));
5763
}
@@ -73,4 +79,5 @@ public <ReqT, RespT> ApiCallContext configure(ApiCallContext context, ReqT reque
7379
})
7480
);
7581
}
82+
// [END spanner_set_statement_timeout]
7683
}

0 commit comments

Comments
 (0)