Extract isDebugEnabled() checks to local variables

Closes gh-24683
This commit is contained in:
Qimiao Chen 2020-03-16 22:25:05 +08:00 committed by GitHub
parent 193a76fe2a
commit 5f2e298c08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -178,10 +178,11 @@ public abstract class DataSourceUtils {
Assert.notNull(con, "No Connection specified"); Assert.notNull(con, "No Connection specified");
boolean debugEnabled = logger.isDebugEnabled();
// Set read-only flag. // Set read-only flag.
if (definition != null && definition.isReadOnly()) { if (definition != null && definition.isReadOnly()) {
try { try {
if (logger.isDebugEnabled()) { if (debugEnabled) {
logger.debug("Setting JDBC Connection [" + con + "] read-only"); logger.debug("Setting JDBC Connection [" + con + "] read-only");
} }
con.setReadOnly(true); con.setReadOnly(true);
@ -203,7 +204,7 @@ public abstract class DataSourceUtils {
// Apply specific isolation level, if any. // Apply specific isolation level, if any.
Integer previousIsolationLevel = null; Integer previousIsolationLevel = null;
if (definition != null && definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { if (definition != null && definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
if (logger.isDebugEnabled()) { if (debugEnabled) {
logger.debug("Changing isolation level of JDBC Connection [" + con + "] to " + logger.debug("Changing isolation level of JDBC Connection [" + con + "] to " +
definition.getIsolationLevel()); definition.getIsolationLevel());
} }
@ -232,10 +233,11 @@ public abstract class DataSourceUtils {
Connection con, @Nullable Integer previousIsolationLevel, boolean resetReadOnly) { Connection con, @Nullable Integer previousIsolationLevel, boolean resetReadOnly) {
Assert.notNull(con, "No Connection specified"); Assert.notNull(con, "No Connection specified");
boolean debugEnabled = logger.isDebugEnabled();
try { try {
// Reset transaction isolation to previous value, if changed for the transaction. // Reset transaction isolation to previous value, if changed for the transaction.
if (previousIsolationLevel != null) { if (previousIsolationLevel != null) {
if (logger.isDebugEnabled()) { if (debugEnabled) {
logger.debug("Resetting isolation level of JDBC Connection [" + logger.debug("Resetting isolation level of JDBC Connection [" +
con + "] to " + previousIsolationLevel); con + "] to " + previousIsolationLevel);
} }
@ -244,7 +246,7 @@ public abstract class DataSourceUtils {
// Reset read-only flag if we originally switched it to true on transaction begin. // Reset read-only flag if we originally switched it to true on transaction begin.
if (resetReadOnly) { if (resetReadOnly) {
if (logger.isDebugEnabled()) { if (debugEnabled) {
logger.debug("Resetting read-only flag of JDBC Connection [" + con + "]"); logger.debug("Resetting read-only flag of JDBC Connection [" + con + "]");
} }
con.setReadOnly(false); con.setReadOnly(false);