Google Cloud Spanner C++ Client 2.8.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 };
82
83 /// Wrap the arguments to `PartitionRead()`.
84 struct PartitionReadParams {
87 };
88
89 /// Wrap the arguments to `ExecuteQuery()`, `ExecuteDml()`, `ProfileQuery()`,
90 /// `ProfileDml()`, and `AnalyzeSql()`.
91 struct SqlParams {
95 absl::optional<std::string> partition_token;
96 };
97
98 /// Wrap the arguments to `ExecutePartitionedDml()`.
102 };
103
104 /// Wrap the arguments to `PartitionQuery()`.
105 struct PartitionQueryParams {
109 };
110
111 /// Wrap the arguments to `ExecuteBatchDml()`.
112 struct ExecuteBatchDmlParams {
114 std::vector<SqlStatement> statements;
116 };
117
118 /// Wrap the arguments to `Commit()`.
119 struct CommitParams {
121 Mutations mutations;
123 };
124
125 /// Wrap the arguments to `Rollback()`.
126 struct RollbackParams {
128 };
129 ///@}
130
131 /// Returns the options used by the Connection.
132 virtual Options options() { return Options{}; }
133
134 /// Defines the interface for `Client::Read()`
135 virtual RowStream Read(ReadParams);
136
137 /// Defines the interface for `Client::PartitionRead()`
138 virtual StatusOr<std::vector<ReadPartition>> PartitionRead(
140
141 /// Defines the interface for `Client::ExecuteQuery()`
143
144 /// Defines the interface for `Client::ExecuteDml()`
145 virtual StatusOr<DmlResult> ExecuteDml(SqlParams);
146
147 /// Defines the interface for `Client::ProfileQuery()`
149
150 /// Defines the interface for `Client::ProfileDml()`
151 virtual StatusOr<ProfileDmlResult> ProfileDml(SqlParams);
152
153 /// Defines the interface for `Client::AnalyzeSql()`
154 virtual StatusOr<ExecutionPlan> AnalyzeSql(SqlParams);
155
156 /// Defines the interface for `Client::ExecutePartitionedDml()`
159
160 /// Defines the interface for `Client::PartitionQuery()`
161 virtual StatusOr<std::vector<QueryPartition>> PartitionQuery(
163
164 /// Defines the interface for `Client::ExecuteBatchDml()`
166
167 /// Defines the interface for `Client::Commit()`
168 virtual StatusOr<CommitResult> Commit(CommitParams);
169
170 /// Defines the interface for `Client::Rollback()`
172};
173
174GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
175} // namespace spanner
176} // namespace cloud
177} // namespace google
178
179#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:132
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:120
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:220
Represents the stream of Rows and profile stats returned from spanner::Client::ProfileQuery().
Definition: results.h:161
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:87
The ReadPartition class is a regular type that represents a single slice of a parallel Read operation...
Definition: read_partition.h:88
Represents the stream of Rows returned from spanner::Client::Read() or spanner::Client::ExecuteQuery(...
Definition: results.h:74
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:119
Mutations mutations
Definition: connection.h:121
CommitOptions options
Definition: connection.h:122
Transaction transaction
Definition: connection.h:120
Wrap the arguments to ExecuteBatchDml().
Definition: connection.h:112
std::vector< SqlStatement > statements
Definition: connection.h:114
Transaction transaction
Definition: connection.h:113
Wrap the arguments to ExecutePartitionedDml().
Definition: connection.h:99
QueryOptions query_options
Definition: connection.h:101
SqlStatement statement
Definition: connection.h:100
Wrap the arguments to PartitionQuery().
Definition: connection.h:105
Transaction transaction
Definition: connection.h:106
SqlStatement statement
Definition: connection.h:107
PartitionOptions partition_options
Definition: connection.h:108
Wrap the arguments to PartitionRead().
Definition: connection.h:84
PartitionOptions partition_options
Definition: connection.h:86
ReadParams read_params
Definition: connection.h:85
Wrap the arguments to Read().
Definition: connection.h:74
KeySet keys
Definition: connection.h:77
Transaction transaction
Definition: connection.h:75
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:126
Transaction transaction
Definition: connection.h:127
Wrap the arguments to ExecuteQuery(), ExecuteDml(), ProfileQuery(), ProfileDml(), and AnalyzeSql().
Definition: connection.h:91
SqlStatement statement
Definition: connection.h:93
absl::optional< std::string > partition_token
Definition: connection.h:95
Transaction transaction
Definition: connection.h:92
QueryOptions query_options
Definition: connection.h:94
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