Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lazy initializer #423

Merged
merged 2 commits into from Sep 15, 2020
Merged

feat: add lazy initializer #423

merged 2 commits into from Sep 15, 2020

Conversation

olavloite
Copy link
Collaborator

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-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 12, 2020
@codecov
Copy link

codecov bot commented Sep 12, 2020

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 Files Coverage Δ Complexity Δ
...m/google/cloud/spanner/LazySpannerInitializer.java 50.00% <50.00%> (ø) 1.00 <1.00> (?)
.../google/cloud/spanner/AbstractLazyInitializer.java 92.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-label product-auto-label bot added the api: spanner Issues 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).

Copy link
Contributor

@thiagotnunes thiagotnunes left a comment

Choose a reason for hiding this comment

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

LGTM

@olavloite olavloite merged commit e8522b9 into master Sep 15, 2020
@olavloite olavloite 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 GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. 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

2 participants