Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
connection.h
1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CONNECTION_H
17
18#include "google/cloud/spanner/batch_dml_result.h"
19#include "google/cloud/spanner/commit_options.h"
20#include "google/cloud/spanner/commit_result.h"
21#include "google/cloud/spanner/keys.h"
22#include "google/cloud/spanner/mutations.h"
23#include "google/cloud/spanner/partition_options.h"
24#include "google/cloud/spanner/partitioned_dml_result.h"
25#include "google/cloud/spanner/query_options.h"
26#include "google/cloud/spanner/read_options.h"
27#include "google/cloud/spanner/results.h"
28#include "google/cloud/spanner/sql_statement.h"
29#include "google/cloud/spanner/transaction.h"
30#include "google/cloud/spanner/version.h"
31#include "google/cloud/optional.h"
32#include "google/cloud/options.h"
33#include "google/cloud/status_or.h"
34#include "absl/types/optional.h"
35#include <string>
36#include <vector>
37
38namespace google {
39namespace cloud {
40namespace spanner {
41GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
42
43class ReadPartition;
44class QueryPartition;
45
46/**
47 * A connection to a Spanner database instance.
48 *
49 * This interface defines pure-virtual methods for each of the user-facing
50 * overload sets in `Client`. That is, all of `Client`'s `Read()` overloads
51 * will forward to the one pure-virtual `Read()` method declared in this
52 * interface, and similar for `Client`'s other methods. This allows users to
53 * inject custom behavior (e.g., with a Google Mock object) in a `Client`
54 * object for use in their own tests.
55 *
56 * To create a concrete instance that connects you to a real Spanner database,
57 * see `MakeConnection()`.
58 */
59class Connection {
60 public:
61 virtual ~Connection() = default;
62
63 ///@{
64 /**
65 * @name Defines the arguments for each member function.
66 *
67 * Applications may define classes derived from `Connection`, for example,
68 * because they want to mock the class. To avoid breaking all such derived
69 * classes when we change the number or type of the arguments to the member
70 * functions we define light weight structures to pass the arguments.
71 */
72
73 /// Wrap the arguments to `Read()`.
74 struct ReadParams {
76 std::string table;
78 std::vector<std::string> columns;
80 absl::optional<std::string> partition_token;
81 bool partition_data_boost = false; // when partition_token
82 };
83
84 /// Wrap the arguments to `PartitionRead()`.
85 struct PartitionReadParams {
88 };
89
90 /// Wrap the arguments to `ExecuteQuery()`, `ExecuteDml()`, `ProfileQuery()`,
91 /// `ProfileDml()`, and `AnalyzeSql()`.
92 struct SqlParams {
96 absl::optional<std::string> partition_token;
97 bool partition_data_boost = false; // when partition_token
98 };
99
100 /// Wrap the arguments to `ExecutePartitionedDml()`.
104 };
105
106 /// Wrap the arguments to `PartitionQuery()`.
107 struct PartitionQueryParams {
111 };
112
113 /// Wrap the arguments to `ExecuteBatchDml()`.
114 struct ExecuteBatchDmlParams {
116 std::vector<SqlStatement> statements;
118 };
119
120 /// Wrap the arguments to `Commit()`.
121 struct CommitParams {
123 Mutations mutations;
125 };
126
127 /// Wrap the arguments to `Rollback()`.
128 struct RollbackParams {
130 };
131 ///@}
132
133 /// Returns the options used by the Connection.
134 virtual Options options() { return Options{}; }
135
136 /// Defines the interface for `Client::Read()`
137 virtual RowStream Read(ReadParams);
138
139 /// Defines the interface for `Client::PartitionRead()`
140 virtual StatusOr<std::vector<ReadPartition>> PartitionRead(
142
143 /// Defines the interface for `Client::ExecuteQuery()`
145
146 /// Defines the interface for `Client::ExecuteDml()`
147 virtual StatusOr<DmlResult> ExecuteDml(SqlParams);
148
149 /// Defines the interface for `Client::ProfileQuery()`
151
152 /// Defines the interface for `Client::ProfileDml()`
153 virtual StatusOr<ProfileDmlResult> ProfileDml(SqlParams);
154
155 /// Defines the interface for `Client::AnalyzeSql()`
156 virtual StatusOr<ExecutionPlan> AnalyzeSql(SqlParams);
157
158 /// Defines the interface for `Client::ExecutePartitionedDml()`
161
162 /// Defines the interface for `Client::PartitionQuery()`
163 virtual StatusOr<std::vector<QueryPartition>> PartitionQuery(
165
166 /// Defines the interface for `Client::ExecuteBatchDml()`
168
169 /// Defines the interface for `Client::Commit()`
170 virtual StatusOr<CommitResult> Commit(CommitParams);
171
172 /// Defines the interface for `Client::Rollback()`
174};
175
176GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
177} // namespace spanner
178} // namespace cloud
179} // namespace google
180
181#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CONNECTION_H
Set options on calls to spanner::Client::Commit().
Definition: commit_options.h:35
A connection to a Spanner database instance.
Definition: connection.h:59
virtual RowStream ExecuteQuery(SqlParams)
Defines the interface for Client::ExecuteQuery()
virtual StatusOr< CommitResult > Commit(CommitParams)
Defines the interface for Client::Commit()
virtual ProfileQueryResult ProfileQuery(SqlParams)
Defines the interface for Client::ProfileQuery()
virtual RowStream Read(ReadParams)
Defines the interface for Client::Read()
virtual StatusOr< ProfileDmlResult > ProfileDml(SqlParams)
Defines the interface for Client::ProfileDml()
virtual StatusOr< ExecutionPlan > AnalyzeSql(SqlParams)
Defines the interface for Client::AnalyzeSql()
virtual StatusOr< BatchDmlResult > ExecuteBatchDml(ExecuteBatchDmlParams)
Defines the interface for Client::ExecuteBatchDml()
virtual StatusOr< std::vector< ReadPartition > > PartitionRead(PartitionReadParams)
Defines the interface for Client::PartitionRead()
virtual StatusOr< DmlResult > ExecuteDml(SqlParams)
Defines the interface for Client::ExecuteDml()
virtual Options options()
Returns the options used by the Connection.
Definition: connection.h:134
virtual StatusOr< std::vector< QueryPartition > > PartitionQuery(PartitionQueryParams)
Defines the interface for Client::PartitionQuery()
virtual StatusOr< PartitionedDmlResult > ExecutePartitionedDml(ExecutePartitionedDmlParams)
Defines the interface for Client::ExecutePartitionedDml()
virtual Status Rollback(RollbackParams)
Defines the interface for Client::Rollback()
Represents the result of a data modifying operation using spanner::Client::ExecuteDml().
Definition: results.h:146
The KeySet class is a regular type that represents a collection of Keys.
Definition: keys.h:157
Represents the result and profile stats of a data modifying operation using spanner::Client::ProfileD...
Definition: results.h:244
Represents the stream of Rows and profile stats returned from spanner::Client::ProfileQuery().
Definition: results.h:186
These QueryOptions allow users to configure features about how their SQL queries executes on the serv...
Definition: query_options.h:37
The QueryPartition class is a regular type that represents a single slice of a parallel SQL read.
Definition: query_partition.h:89
The ReadPartition class is a regular type that represents a single slice of a parallel Read operation...
Definition: read_partition.h:90
Represents the stream of Rows returned from spanner::Client::Read() or spanner::Client::ExecuteQuery(...
Definition: results.h:101
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:51
The representation of a Cloud Spanner transaction.
Definition: transaction.h:58
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
The result of executing a batch of DML statements.
Definition: batch_dml_result.h:39
The result of committing a Transaction.
Definition: commit_result.h:38
Wrap the arguments to Commit().
Definition: connection.h:121
Mutations mutations
Definition: connection.h:123
CommitOptions options
Definition: connection.h:124
Transaction transaction
Definition: connection.h:122
Wrap the arguments to ExecuteBatchDml().
Definition: connection.h:114
std::vector< SqlStatement > statements
Definition: connection.h:116
Transaction transaction
Definition: connection.h:115
Wrap the arguments to ExecutePartitionedDml().
Definition: connection.h:101
QueryOptions query_options
Definition: connection.h:103
SqlStatement statement
Definition: connection.h:102
Wrap the arguments to PartitionQuery().
Definition: connection.h:107
Transaction transaction
Definition: connection.h:108
SqlStatement statement
Definition: connection.h:109
PartitionOptions partition_options
Definition: connection.h:110
Wrap the arguments to PartitionRead().
Definition: connection.h:85
PartitionOptions partition_options
Definition: connection.h:87
ReadParams read_params
Definition: connection.h:86
Wrap the arguments to Read().
Definition: connection.h:74
KeySet keys
Definition: connection.h:77
Transaction transaction
Definition: connection.h:75
bool partition_data_boost
Definition: connection.h:81
absl::optional< std::string > partition_token
Definition: connection.h:80
std::string table
Definition: connection.h:76
std::vector< std::string > columns
Definition: connection.h:78
ReadOptions read_options
Definition: connection.h:79
Wrap the arguments to Rollback().
Definition: connection.h:128
Transaction transaction
Definition: connection.h:129
Wrap the arguments to ExecuteQuery(), ExecuteDml(), ProfileQuery(), ProfileDml(), and AnalyzeSql().
Definition: connection.h:92
SqlStatement statement
Definition: connection.h:94
absl::optional< std::string > partition_token
Definition: connection.h:96
Transaction transaction
Definition: connection.h:93
bool partition_data_boost
Definition: connection.h:97
QueryOptions query_options
Definition: connection.h:95
Options passed to Client::PartitionRead or Client::PartitionQuery.
Definition: partition_options.h:38
The result of executing a Partitioned DML query.
Definition: partitioned_dml_result.h:29
Options passed to Client::Read or Client::PartitionRead.
Definition: read_options.h:32