Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,10 @@ public boolean isAutoCommit() {
return autoCommit;
}

public boolean isReadOnly() {
return readOnly;
}

int transactionIsolation() {
return transactionIsolation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ final class PooledConnection extends ConnectionDelegator {
* connected to a read-only instance and should reset.
*/
private boolean failoverToReadOnly;
private boolean resetAutoCommit;
private boolean autoCommit;
private boolean readOnly;
private int transactionIsolation;
private int schemaState = SCHEMA_CATALOG_UNKNOWN;
private int catalogState = SCHEMA_CATALOG_UNKNOWN;

Expand Down Expand Up @@ -135,7 +137,7 @@ final class PooledConnection extends ConnectionDelegator {
* Slot position in the BusyConnectionBuffer.
*/
private int slotId;
private boolean resetIsolationReadOnlyRequired;


/**
* Construct the connection that can refer back to the pool it belongs to.
Expand All @@ -150,6 +152,9 @@ final class PooledConnection extends ConnectionDelegator {
this.name = pool.name() + uniqueId;
this.originalSchema = pool.schema();
this.originalCatalog = pool.catalog();
this.autoCommit = pool.isAutoCommit();
this.readOnly = pool.isReadOnly();
this.transactionIsolation = pool.transactionIsolation();
if (originalSchema != null) {
this.schemaState = SCHEMA_CATALOG_KNOWN;
this.cacheKeySchema = originalSchema;
Expand Down Expand Up @@ -446,16 +451,20 @@ public void close() throws SQLException {
return;
}
// reset the autoCommit back if client code changed it
if (resetAutoCommit) {
if (autoCommit != pool.isAutoCommit()) {
connection.setAutoCommit(pool.isAutoCommit());
resetAutoCommit = false;
autoCommit = pool.isAutoCommit();
}
// Generally resetting Isolation level seems expensive.
// Hence using resetIsolationReadOnlyRequired flag
// performance reasons.
if (resetIsolationReadOnlyRequired) {
resetIsolationReadOnly();
resetIsolationReadOnlyRequired = false;
if (transactionIsolation != pool.transactionIsolation()) {
connection.setTransactionIsolation(pool.transactionIsolation());
transactionIsolation = pool.transactionIsolation();
}
if (readOnly != pool.isReadOnly()) {
connection.setReadOnly(readOnly);
readOnly = pool.isReadOnly();
}

if (catalogState == SCHEMA_CATALOG_CHANGED) {
Expand Down Expand Up @@ -484,16 +493,6 @@ public void close() throws SQLException {
}
}

private void resetIsolationReadOnly() throws SQLException {
int level = pool.transactionIsolation();
if (connection.getTransactionIsolation() != level) {
connection.setTransactionIsolation(level);
}
if (connection.isReadOnly()) {
connection.setReadOnly(false);
}
}

/**
* Return true if the connection is too old.
*/
Expand Down Expand Up @@ -567,8 +566,16 @@ void setLastStatement(String lastStatement) {
*/
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
resetIsolationReadOnlyRequired = true;
connection.setReadOnly(readOnly);
if (status == STATUS_IDLE) {
throw new SQLException(IDLE_CONNECTION_ACCESSED_ERROR + "setTransactionIsolation()");
}
try {
connection.setReadOnly(readOnly);
this.readOnly = readOnly;
} catch (SQLException ex) {
markWithError(ex);
throw ex;
}
}


Expand All @@ -581,8 +588,8 @@ public void setTransactionIsolation(int level) throws SQLException {
throw new SQLException(IDLE_CONNECTION_ACCESSED_ERROR + "setTransactionIsolation()");
}
try {
resetIsolationReadOnlyRequired = true;
connection.setTransactionIsolation(level);
this.transactionIsolation = level;
} catch (SQLException ex) {
markWithError(ex);
throw ex;
Expand Down Expand Up @@ -727,7 +734,7 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
}
try {
connection.setAutoCommit(autoCommit);
resetAutoCommit = true;
this.autoCommit = autoCommit;
} catch (SQLException ex) {
markWithError(ex);
throw ex;
Expand Down
Loading