Conversation

olavloite

Adds a LazyInitializer for Spanner instances that can be used in environments where it is desirable to initialize one instance once, and reuse this for multiple purposes, such as for example Google Cloud Functions.

This change would allow us to simplify the Google Cloud Functions Java sample.

Towards GoogleCloudPlatform/java-docs-samples#2862.

@google-clagoogle-cla bot added the cla: yesThis human has signed the Contributor License Agreement.label Sep 12, 2020
@codecov

Codecov Report

Merging #423 into master will increase coverage by 0.00%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #423   +/-   ##
=========================================
  Coverage     82.16%   82.17%           
- Complexity     2455     2460    +5     
=========================================
  Files           136      138    +2     
  Lines         13589    13605   +16     
  Branches       1307     1309    +2     
=========================================
+ Hits          11166    11180   +14     
- Misses         1895     1896    +1     
- Partials        528      529    +1     
Impacted FilesCoverage ΔComplexity Δ
...m/google/cloud/spanner/LazySpannerInitializer.java50.00% <50.00%> (ø)1.00 <1.00> (?)
.../google/cloud/spanner/AbstractLazyInitializer.java92.85% <92.85%> (ø)4.00 <4.00> (?)

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 6154008...be9ddd1. Read the comment docs.

@product-auto-labelproduct-auto-label bot added the api: spannerIssues related to the googleapis/java-spanner API.label Sep 13, 2020
* Generic {@link AbstractLazyInitializer} for any heavy-weight object that might throw an exception
* during initialization. The underlying object is initialized at most once.
*/
public abstract class AbstractLazyInitializer<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use composition instead of inheritance (pass in the initialiser function instead of overriding it)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would be possible, but as we have to support Java 7, that would mean that we would have to use com.google.cloud.base.Function in the public interface. I think that it is more idiomatic to use inheritance than composition for Java 7 (once we drop Java 7 support, I would agree that using composition would be a lot nicer in this case).

Choose a reason for hiding this comment

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

LGTM

@olavloiteolavloite merged commit e8522b9 into master Sep 15, 2020
@olavloiteolavloite deleted the lazy-initializer branch September 15, 2020 14:07
ansh0l pushed a commit to ansh0l/java-spanner that referenced this pull request Nov 10, 2022
This is an auto-generated regeneration of the .pb.go files by
cloud.google.com/go/internal/gapicgen. Once this PR is submitted, genbot will
update the corresponding PR to depend on the newer version of go-genproto, and
assign reviewers. Whilst this or any regen PR is open in go-genproto, genbot
will not create any more regeneration PRs. If all regen PRs are closed,
gapicgen will create a new set of regeneration PRs once per night.

If you have been assigned to review this PR, please:

- Ensure that CI is passing. If it's failing, it requires your manual attention.
- Approve and submit this PR if you believe it's ready to ship. That will prompt
genbot to assign reviewers to the google-cloud-go PR.


Corresponding google-cloud-go PR: googleapis/google-cloud-go#2682
rajatbhatta pushed a commit to rajatbhatta/java-spanner that referenced this pull request Nov 17, 2022
Sign up for free to join this conversation on . Already have an account? Sign in to comment
api: spannerIssues related to the googleapis/java-spanner API.cla: yesThis human has signed the Contributor License Agreement.
None yet

Successfully merging this pull request may close these issues.