Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.

feat: introduce java.time variables and methods - #3495

Merged
gcf-merge-on-green[bot] merged 6 commits into
mainfrom
introduce-java-time
Dec 5, 2024
Merged

feat: introduce java.time variables and methods#3495
gcf-merge-on-green[bot] merged 6 commits into
mainfrom
introduce-java-time

Conversation

@diegomarquezp

Copy link
Copy Markdown
Contributor

This PR introduces java.time alternatives to existing org.threeten.bp.* methods, as well as switching internal variables (if any) to java.time

The main constraint is to keep the changes backwards compatible, so for each existing threeten method "method1(org.threeten.bp.Duration)" we will add an alternative with a Duration (or Timestamp when applicable) suffix: "method1Duration(java.time.Duration)".

For most cases, the implementation will be held in the java.time method and the old threeten method will just delegate the call to it. However, for the case of abstract classes, the implementation will be kept in the threeten method to avoid breaking changes (i.e. users that already overloaded the method in their user code).

@diegomarquezp
diegomarquezp requested a review from a team November 21, 2024 20:32
@product-auto-label product-auto-label Bot added the size: l Pull request size is large. label Nov 21, 2024
@diegomarquezp
diegomarquezp marked this pull request as draft November 21, 2024 20:32
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the googleapis/java-spanner API. label Nov 21, 2024
@diegomarquezp diegomarquezp added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 21, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 21, 2024
@diegomarquezp
diegomarquezp marked this pull request as ready for review November 21, 2024 22:50
@diegomarquezp
diegomarquezp requested review from a team and lqiu96 November 21, 2024 22:50
@diegomarquezp
diegomarquezp requested a review from lqiu96 November 22, 2024 19:11
private static void maybeWaitForSessionCreation(
SessionPoolOptions sessionPoolOptions, ApiFuture<SessionReference> future) {
org.threeten.bp.Duration waitDuration = sessionPoolOptions.getWaitForMinSessions();
java.time.Duration waitDuration = sessionPoolOptions.getWaitForMinSessions();

ghost Nov 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: java.time.Duration is already imported in this class. Can't we just remove org.threeten.bp.


@Override
public void attemptFailed(Throwable error, Duration delay) {
public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {

ghost Nov 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Can we import java.time.Duration so that we can remove java.time. in attemptFailedDuration method? https://github.com/googleapis/java-spanner/blob/main/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java#L119

ghost Dec 3, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done


@Override
public void attemptFailed(Throwable error, Duration delay) {
public void attemptFailedDuration(Throwable error, java.time.Duration delay) {

ghost Nov 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Can we import java.time.Duration?

ghost Dec 3, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

private final boolean autoDetectDialect;
private final Duration waitForMinSessions;
private final Duration acquireSessionTimeout;
private final java.time.Duration waitForMinSessions;

ghost Nov 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: We can import java.time.Duration so that in future we don't have a confusion on which class to use

ghost Nov 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and also it avoids so many changes in the code which is not really necessary.

ghost Dec 3, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@sakthivelmanii

ghost commented Nov 26, 2024

Copy link
Copy Markdown
Contributor

@diegomarquezp Can we make sure following in all the files?

import java.time.Duration in all the files(whereever is required) and use org.threeten.bp.Duration directly in obsolete methods. This avoids lot of code changes which is unnecessary. This also provides the standard that java.time.Duration should be used.

@diegomarquezp

ghost commented Nov 27, 2024

Copy link
Copy Markdown
Contributor Author

@diegomarquezp Can we make sure following in all the files?

import java.time.Duration in all the files(whereever is required) and use org.threeten.bp.Duration directly in obsolete methods. This avoids lot of code changes which is unnecessary. This also provides the standard that java.time.Duration should be used.

@sakthivelmanii Thanks for the review! Before switching to import java.time.Duration I'd like to double check if our rationale for not importing java.time.* seems sound to you: this is mainly to make it clear to the reader that there are two Duration/Instant classes coexisting in the same file and attention should be paid. We deliberately added these changes just to make this differentiation as explicit as possible. We've been doing it this way in other repos (e.g. googleapis/java-pubsub#2271 (comment)) (doesn't mean it should be done as in other repos).

Promoting java.time as the standard also makes sense, and it's ultimately the Spanner team's call, but wanted to make sure our approach doesn't come up as unintended. I'm happy to move forward either way.

}

org.threeten.bp.Duration asDuration() {
java.time.Duration asDuration() {

ghost Dec 3, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

need to keep this one in favor of com.google.protobuf.Duration

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Spanner team for approval.

@diegomarquezp diegomarquezp added the automerge Merge the pull request once unit tests and other checks pass. label Dec 5, 2024
@gcf-merge-on-green
gcf-merge-on-green Bot merged commit 8a7d533 into main Dec 5, 2024
@gcf-merge-on-green gcf-merge-on-green Bot removed the automerge Merge the pull request once unit tests and other checks pass. label Dec 5, 2024
@gcf-merge-on-green
gcf-merge-on-green Bot deleted the introduce-java-time branch December 5, 2024 17:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/java-spanner API. size: l Pull request size is large.

5 participants