Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

refactor!: remove c'tors from Connection::* param structs #1257

Merged
merged 2 commits into from
Feb 11, 2020

Conversation

devjgm
Copy link
Contributor

@devjgm devjgm commented Feb 10, 2020

Background

https://github.com/googleapis/google-cloud-cpp-spanner/blob/master/google/cloud/spanner/connection.h defines the Connection interface, which allows us and our customers to mock out the Spanner "backend" for easier unit testing. That interface defines several FooParms structs, which hold all the parameters for each of the virtual methods. Most of those structs are normal/trivial structs, i.e., they do not have constructors.

However, we do have two structs that have constructors:

ReadParams(Transaction transaction, std::string table, KeySet keys,

and

SqlParams(Transaction transaction, SqlStatement statement,

These exist for convenience because the partition_token struct field is optional.

Proposal

This PR proposes to remove the constructors to make all the params structs the same. This means that all callers constructing the Params will need to specify all fields, including the partition_token. But this is the same for all the other params structs already.

This doesn't prevent us from ever adding a constructor back at some point in the future, for example, if we decide that we need to add another optional member to a struct.


This change is Reviewable

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 10, 2020
@codecov
Copy link

codecov bot commented Feb 10, 2020

Codecov Report

Merging #1257 into master will decrease coverage by 0.13%.
The diff coverage is 98.8%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1257      +/-   ##
==========================================
- Coverage   94.97%   94.84%   -0.14%     
==========================================
  Files         184      185       +1     
  Lines       13813    13821       +8     
==========================================
- Hits        13119    13108      -11     
- Misses        694      713      +19
Impacted Files Coverage Δ
google/cloud/spanner/connection.h 100% <ø> (ø) ⬆️
google/cloud/spanner/client.cc 97.01% <100%> (-0.4%) ⬇️
google/cloud/spanner/client_test.cc 94.81% <100%> (ø) ⬆️
google/cloud/spanner/read_partition.cc 94.87% <100%> (-0.13%) ⬇️
...gle/cloud/spanner/internal/connection_impl_test.cc 97.86% <97.56%> (-0.96%) ⬇️
google/cloud/spanner/internal/polling_loop.h 91.89% <0%> (-2.71%) ⬇️
google/cloud/spanner/samples/samples.cc 87.57% <0%> (-0.48%) ⬇️
google/cloud/spanner/keys.h 100% <0%> (ø) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 01f634f...296ef47. Read the comment docs.

@devjgm devjgm requested a review from coryan February 11, 2020 14:29
@devjgm devjgm marked this pull request as ready for review February 11, 2020 14:29
Copy link
Member

@coryan coryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 5 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@devjgm devjgm merged commit 6449251 into googleapis:master Feb 11, 2020
@devjgm devjgm deleted the no-struct-ctor branch February 11, 2020 14:44
devjgm added a commit to devjgm/google-cloud-cpp that referenced this pull request May 7, 2020
…/google-cloud-cpp-spanner#1257)

# Background

https://github.com/googleapis/google-cloud-cpp-spanner/blob/master/google/cloud/spanner/connection.h defines the `Connection` interface, which allows us and our customers to mock out the Spanner "backend" for easier unit testing. That interface defines several `FooParms` structs, which hold all the parameters for each of the virtual methods. Most of those structs are normal/trivial structs, i.e., *they do not have constructors*.

However, we do have two structs that have constructors: 
https://github.com/googleapis/google-cloud-cpp-spanner/blob/01f634f75a08dc4cc98949ff0ad2a554100f31d4/google/cloud/spanner/connection.h#L78

and

https://github.com/googleapis/google-cloud-cpp-spanner/blob/01f634f75a08dc4cc98949ff0ad2a554100f31d4/google/cloud/spanner/connection.h#L102

These exist for convenience because the `partition_token` struct field is optional.

# Proposal

This PR proposes to remove the constructors to make all the params structs the same. This means that all callers constructing the Params will need to specify all fields, including the `partition_token`. But this is the same for all the other params structs already.

This doesn't prevent us from ever adding a constructor back at some point in the future, for example, if we decide that we need to add another *optional* member to a struct.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants