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

issue #3153: return XAER_NOTA on rollback #3154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pgjdbc/src/main/java/org/postgresql/xa/PGXAConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ public boolean setTransactionTimeout(int seconds) {

private int mapSQLStateToXAErrorCode(SQLException sqlException) {
if (isPostgreSQLIntegrityConstraintViolation(sqlException)) {
committedOrRolledBack = true;
return XAException.XA_RBINTEGRITY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,8 @@ void networkIssueOnRollback() throws Exception {

/**
* When using deferred constraints a constraint violation can occur on prepare. This has to be
* mapped to the correct XA Error Code
* mapped to the correct XA Error Code. As a consequence, the transaction is rolled back.
* A subsequent rollback invocation should return XAER_NOTA.
*/
@Test
void mappingOfConstraintViolations() throws Exception {
Expand All @@ -791,6 +792,14 @@ void mappingOfConstraintViolations() throws Exception {
fail("Prepare is expected to fail as an integrity violation occurred");
} catch (XAException xae) {
assertEquals(XAException.XA_RBINTEGRITY, xae.errorCode, "Prepare call with deferred constraints violations expects XA_RBINTEGRITY");

try {
xaRes.rollback(xid);

fail("Rollback is expected to fail as the transaction should have been already rolled back during prepare");
} catch (XAException xaex) {
assertEquals(XAException.XAER_NOTA, xaex.errorCode, "Rollback call on the already rolled back xid " + xid + " expects XAER_NOTA");
}
}
}

Expand Down