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

Fixes erroneous closing behavior in JtaConnection.java #6321

Merged
merged 4 commits into from
Mar 2, 2023

Conversation

ljnelson
Copy link
Member

@ljnelson ljnelson commented Feb 28, 2023

Consider the use case where a method is annotated with jakarta.transaction.Transactional and close() is called on a Connection obtained therein. close() in this case should not actually close the Connection at that very moment, but closing should happen after the completion of the transaction. The prior version of this class was OK on the first point, and butchered the second point, so these changes fix the behavior. Note that the JtaConnection class is not currently used in Helidon, but will be soon.

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
@ljnelson ljnelson added jpa/jta 3.x Issues for 3.x version branch labels Feb 28, 2023
@ljnelson ljnelson self-assigned this Feb 28, 2023
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 28, 2023
Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
@ljnelson
Copy link
Member Author

ljnelson commented Mar 1, 2023

@tjquinno I've incorporated your suggestion to bake an explicit state model into ConditionallyCloseableConnection without changing existing signatures etc. and without disturbing existing test behavior. While the change was a bit hairy for me to implement I greatly prefer it, so thank you for the suggestion. I'll resolve the other discussions above.

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
@danielkec
Copy link
Contributor

@ljnelson Please add link to corresponding issue

Copy link
Contributor

@danielkec danielkec left a comment

Choose a reason for hiding this comment

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

Can't we encapsulate this in AtomicReference for the sake of readability?

Enlistment enlistment = new Enlistment(t, xar);
if (!ENLISTMENT.compareAndSet(this, null, enlistment)) { // atomic volatile write
    // Setting this.enlistment could conceivably fail if another thread already enlisted this JtaConnection.
    // That would be bad.

@ljnelson
Copy link
Member Author

ljnelson commented Mar 1, 2023

Can't we encapsulate this in AtomicReference for the sake of readability?

Enlistment enlistment = new Enlistment(t, xar);
if (!ENLISTMENT.compareAndSet(this, null, enlistment)) { // atomic volatile write
    // Setting this.enlistment could conceivably fail if another thread already enlisted this JtaConnection.
    // That would be bad.

I'd rather keep the speedy and efficient VarHandle usage. (Additionally there is one static VarHandle for n occurrences of JtaConnection, not n occurrences of AtomicReference.)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
@ljnelson ljnelson requested review from danielkec and tjquinno March 1, 2023 18:05
Copy link
Member

@tjquinno tjquinno left a comment

Choose a reason for hiding this comment

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

I know it was work to use explicit states, but I think it's much clearer that way.

LGTM

@ljnelson ljnelson merged commit b5a744f into helidon-io:helidon-3.x Mar 2, 2023
ljnelson added a commit to ljnelson/helidon that referenced this pull request Aug 23, 2023
* Fixes erroneous closing behavior in JtaConnection.java

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
ljnelson added a commit that referenced this pull request Aug 25, 2023
* Improves integrations/jdbc/jdbc to better support future JPA improvements; initial work (#5654)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Squashable commit; initial work (#5716)

Lays some groundwork with deprecation and cleanup and isolated improvements to support ongoing JPA improvements.

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Introduces LocalXAResource and a few support classes in jta/jdbc. (#5733)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Adds connection unwrapping abilities to CDISEPlatform.java (#5790)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Introduces JtaConnection.java (#5905)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Fixes erroneous closing behavior in JtaConnection.java (#6321)

* Fixes erroneous closing behavior in JtaConnection.java

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Minor JPA cleanups; part of overall refactoring effort (#6435)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Improving JPA pom.xml as part of overall JPA refactoring (#6508)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Fixes merge conflicts etc. from cherry-pick of c9a849e

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Adds an enabled flag to JpaExtension to permit subsequent refactoring and replacement (#6512)

Adds an enabled flag to JpaExtension to permit subsequent refactoring and replacement

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Adds more classes as part of overall JPA refactoring effort (#6584)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Lets unit tests validating JpaExtension and unit tests validating PersistenceExtension run side-by-side; continuation of overall fix for nested transaction problems (#7118)

* Lets unit tests validating JpaExtension and unit tests validating PersistenceExtension run side-by-side; continuation of overall fix for nested transaction problems

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Resolves issue 7316, which features some intermittent database-related tests (#7317)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Addresses copyright plugin complaints after lots of cherry-picking from old 3.x commits

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

---------

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
dalexandrov pushed a commit to dalexandrov/helidon that referenced this pull request Aug 26, 2023
* Improves integrations/jdbc/jdbc to better support future JPA improvements; initial work (helidon-io#5654)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Squashable commit; initial work (helidon-io#5716)

Lays some groundwork with deprecation and cleanup and isolated improvements to support ongoing JPA improvements.

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Introduces LocalXAResource and a few support classes in jta/jdbc. (helidon-io#5733)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Adds connection unwrapping abilities to CDISEPlatform.java (helidon-io#5790)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Introduces JtaConnection.java (helidon-io#5905)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Fixes erroneous closing behavior in JtaConnection.java (helidon-io#6321)

* Fixes erroneous closing behavior in JtaConnection.java

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Minor JPA cleanups; part of overall refactoring effort (helidon-io#6435)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Improving JPA pom.xml as part of overall JPA refactoring (helidon-io#6508)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Fixes merge conflicts etc. from cherry-pick of c9a849e

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Adds an enabled flag to JpaExtension to permit subsequent refactoring and replacement (helidon-io#6512)

Adds an enabled flag to JpaExtension to permit subsequent refactoring and replacement

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Adds more classes as part of overall JPA refactoring effort (helidon-io#6584)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Lets unit tests validating JpaExtension and unit tests validating PersistenceExtension run side-by-side; continuation of overall fix for nested transaction problems (helidon-io#7118)

* Lets unit tests validating JpaExtension and unit tests validating PersistenceExtension run side-by-side; continuation of overall fix for nested transaction problems

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Resolves issue 7316, which features some intermittent database-related tests (helidon-io#7317)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

* Addresses copyright plugin complaints after lots of cherry-picking from old 3.x commits

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>

---------

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues for 3.x version branch jpa/jta OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

JtaConnection has erroneous closing behavior (3.x)
3 participants