From 5f2e298c08255bbda2b36ad0351146748d847bc6 Mon Sep 17 00:00:00 2001 From: Qimiao Chen Date: Mon, 16 Mar 2020 22:25:05 +0800 Subject: [PATCH] Extract isDebugEnabled() checks to local variables Closes gh-24683 --- .../jdbc/datasource/DataSourceUtils.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java index 3f1fcade31e..3237042f3ca 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java @@ -178,10 +178,11 @@ public abstract class DataSourceUtils { Assert.notNull(con, "No Connection specified"); + boolean debugEnabled = logger.isDebugEnabled(); // Set read-only flag. if (definition != null && definition.isReadOnly()) { try { - if (logger.isDebugEnabled()) { + if (debugEnabled) { logger.debug("Setting JDBC Connection [" + con + "] read-only"); } con.setReadOnly(true); @@ -203,7 +204,7 @@ public abstract class DataSourceUtils { // Apply specific isolation level, if any. Integer previousIsolationLevel = null; if (definition != null && definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { - if (logger.isDebugEnabled()) { + if (debugEnabled) { logger.debug("Changing isolation level of JDBC Connection [" + con + "] to " + definition.getIsolationLevel()); } @@ -232,10 +233,11 @@ public abstract class DataSourceUtils { Connection con, @Nullable Integer previousIsolationLevel, boolean resetReadOnly) { Assert.notNull(con, "No Connection specified"); + boolean debugEnabled = logger.isDebugEnabled(); try { // Reset transaction isolation to previous value, if changed for the transaction. if (previousIsolationLevel != null) { - if (logger.isDebugEnabled()) { + if (debugEnabled) { logger.debug("Resetting isolation level of JDBC Connection [" + 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. if (resetReadOnly) { - if (logger.isDebugEnabled()) { + if (debugEnabled) { logger.debug("Resetting read-only flag of JDBC Connection [" + con + "]"); } con.setReadOnly(false);