Skip to content

Commit 8468cb8

Browse files
committed
[ci] Combine 'if' statements
1 parent 9b20e5a commit 8468cb8

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

src/main/java/org/apache/ibatis/datasource/pooled/PooledDataSource.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -536,36 +536,33 @@ protected boolean pingConnection(PooledConnection conn) {
536536
result = false;
537537
}
538538

539-
if (result) {
540-
if (poolPingEnabled) {
541-
if (poolPingConnectionsNotUsedFor >= 0 && conn.getTimeElapsedSinceLastUse() > poolPingConnectionsNotUsedFor) {
542-
try {
543-
if (log.isDebugEnabled()) {
544-
log.debug("Testing connection " + conn.getRealHashCode() + " ...");
545-
}
546-
Connection realConn = conn.getRealConnection();
547-
try (Statement statement = realConn.createStatement()) {
548-
statement.executeQuery(poolPingQuery).close();
549-
}
550-
if (!realConn.getAutoCommit()) {
551-
realConn.rollback();
552-
}
553-
result = true;
554-
if (log.isDebugEnabled()) {
555-
log.debug("Connection " + conn.getRealHashCode() + " is GOOD!");
556-
}
557-
} catch (Exception e) {
558-
log.warn("Execution of ping query '" + poolPingQuery + "' failed: " + e.getMessage());
559-
try {
560-
conn.getRealConnection().close();
561-
} catch (Exception e2) {
562-
//ignore
563-
}
564-
result = false;
565-
if (log.isDebugEnabled()) {
566-
log.debug("Connection " + conn.getRealHashCode() + " is BAD: " + e.getMessage());
567-
}
568-
}
539+
if (result && poolPingEnabled && poolPingConnectionsNotUsedFor >= 0
540+
&& conn.getTimeElapsedSinceLastUse() > poolPingConnectionsNotUsedFor) {
541+
try {
542+
if (log.isDebugEnabled()) {
543+
log.debug("Testing connection " + conn.getRealHashCode() + " ...");
544+
}
545+
Connection realConn = conn.getRealConnection();
546+
try (Statement statement = realConn.createStatement()) {
547+
statement.executeQuery(poolPingQuery).close();
548+
}
549+
if (!realConn.getAutoCommit()) {
550+
realConn.rollback();
551+
}
552+
result = true;
553+
if (log.isDebugEnabled()) {
554+
log.debug("Connection " + conn.getRealHashCode() + " is GOOD!");
555+
}
556+
} catch (Exception e) {
557+
log.warn("Execution of ping query '" + poolPingQuery + "' failed: " + e.getMessage());
558+
try {
559+
conn.getRealConnection().close();
560+
} catch (Exception e2) {
561+
//ignore
562+
}
563+
result = false;
564+
if (log.isDebugEnabled()) {
565+
log.debug("Connection " + conn.getRealHashCode() + " is BAD: " + e.getMessage());
569566
}
570567
}
571568
}

0 commit comments

Comments
 (0)