Skip to content

Commit

Permalink
[CONJ-948] adding a technical option 'forceTransactionEnd' to force R…
Browse files Browse the repository at this point in the history
…OLLBACK/COMMIT commands when not needed
  • Loading branch information
rusher committed May 17, 2022
1 parent 0609c6d commit 2bb83ed
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/org/mariadb/jdbc/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class Connection implements java.sql.Connection {
private final boolean canUseServerTimeout;
private final boolean canUseServerMaxRows;
private final int defaultFetchSize;
private final boolean forceTransactionEnd;
private MariaDbPoolConnection poolConnection;

/**
Expand All @@ -58,6 +59,7 @@ public class Connection implements java.sql.Connection {
*/
public Connection(Configuration conf, ReentrantLock lock, Client client) {
this.conf = conf;
this.forceTransactionEnd = Boolean.parseBoolean(conf.nonMappedOptions().getProperty("forceTransactionEnd", "false"));
this.lock = lock;
this.exceptionFactory = client.getExceptionFactory().setConnection(this);
this.client = client;
Expand Down Expand Up @@ -198,7 +200,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
public void commit() throws SQLException {
lock.lock();
try {
if ((client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
client.execute(new QueryPacket("COMMIT"), false);
}
} finally {
Expand All @@ -210,7 +212,7 @@ public void commit() throws SQLException {
public void rollback() throws SQLException {
lock.lock();
try {
if ((client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
client.execute(new QueryPacket("ROLLBACK"), true);
}
} finally {
Expand Down Expand Up @@ -842,7 +844,7 @@ && getContext().getVersion().getMinorVersion() == 2
}

// in transaction => rollback
if ((client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
if (forceTransactionEnd || (client.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
client.execute(new QueryPacket("ROLLBACK"), true);
}

Expand Down

0 comments on commit 2bb83ed

Please sign in to comment.