Skip to content

Commit

Permalink
issue pgjdbc#3153: return XAER_NOTA on rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfinelli committed Mar 6, 2024
1 parent 818953a commit f9b70f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions pgjdbc/src/main/java/org/postgresql/xa/PGXAConnection.java
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
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

0 comments on commit f9b70f0

Please sign in to comment.