diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-10-09 17:02:11 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-10-09 17:02:11 +0200 |
commit | 062ba55d6a9beb304e3bb454ce974884afbb52ef (patch) | |
tree | cef3c30a34dbbb397b5c2b736845d07c7f15cc79 /sonar-core/src | |
parent | 40d88787eaea9913b9817039d5535e9df01d4902 (diff) | |
download | sonarqube-062ba55d6a9beb304e3bb454ce974884afbb52ef.tar.gz sonarqube-062ba55d6a9beb304e3bb454ce974884afbb52ef.zip |
Fix quality flaw
Diffstat (limited to 'sonar-core/src')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterExecutor.java | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterExecutor.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterExecutor.java index b529f5a384a..c7dcc8eceb9 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterExecutor.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterExecutor.java @@ -20,11 +20,13 @@ package org.sonar.core.measure; import org.apache.ibatis.session.SqlSession; +import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; import org.sonar.core.persistence.Database; import org.sonar.core.persistence.MyBatis; import org.sonar.core.resource.ResourceDao; +import javax.annotation.Nullable; import java.sql.Connection; import java.sql.SQLException; import java.util.Collections; @@ -45,6 +47,7 @@ public class MeasureFilterExecutor implements ServerComponent { public List<MeasureFilterRow> execute(MeasureFilter filter, MeasureFilterContext context) throws SQLException { List<MeasureFilterRow> rows; SqlSession session = null; + Connection connection = null; try { session = mybatis.openSession(); prepareContext(context, filter, session); @@ -52,18 +55,31 @@ public class MeasureFilterExecutor implements ServerComponent { if (isValid(filter, context)) { MeasureFilterSql sql = new MeasureFilterSql(database, filter, context); context.setSql(sql.sql()); - Connection connection = session.getConnection(); + connection = session.getConnection(); rows = sql.execute(connection); } else { rows = Collections.emptyList(); } } finally { MyBatis.closeQuietly(session); + // connection is supposed to be closed by the session + closeQuietly(connection); } return rows; } + private void closeQuietly(@Nullable Connection connection) { + if (connection != null) { + try { + connection.close(); + } catch (SQLException e) { + LoggerFactory.getLogger(MeasureFilterExecutor.class).warn("Fail to close connection", e); + // ignore + } + } + } + private void prepareContext(MeasureFilterContext context, MeasureFilter filter, SqlSession session) { if (filter.getBaseResourceKey() != null) { |