Allon Mureinik has uploaded a new change for review. Change subject: tools: don't rely on Connection.isValid() ......................................................................
tools: don't rely on Connection.isValid() Patch 9f856a6234566a2ab648ef580fa102192ec43b10 refactored StandaloneDataSource.checkConnection() to use Connection.isValid() in order to avoid a FindBugs warning on an unused function result. Apparently, this approach is problematic since the PostgreSQL JDBC driver we're using does not implement isValid(). This patch reverts 9f856a6234566a2ab648ef580fa102192ec43b10 and proposes a different way to avoid the FindBugs warning. Change-Id: Ic4f1fe6a9981c6fe8764a803eda4de5d51cc2b6e Signed-off-by: Allon Mureinik <[email protected]> --- M backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java 1 file changed, 21 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/12/12812/1 diff --git a/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java b/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java index 2fb4385..491c76e 100644 --- a/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java +++ b/backend/manager/tools/src/main/java/org/ovirt/engine/core/tools/common/db/StandaloneDataSource.java @@ -6,14 +6,16 @@ import java.lang.reflect.Proxy; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; +import java.sql.Statement; import javax.sql.DataSource; import org.apache.log4j.Logger; -import org.ovirt.engine.core.utils.crypt.EncryptionUtils; import org.ovirt.engine.core.utils.LocalConfig; +import org.ovirt.engine.core.utils.crypt.EncryptionUtils; public class StandaloneDataSource implements DataSource { // The log: @@ -108,9 +110,23 @@ wrapper = null; } - private void checkConnection () throws SQLException { - if (!connection.isValid(0)) { - throw new SQLException("The connection has been closed or invalid."); + @SuppressWarnings("resource") + private void checkConnection() throws SQLException { + Statement statement = null; + ResultSet rs = null; + try { + statement = connection.createStatement(); + rs = statement.executeQuery("select null"); + rs.next(); + } + finally { + if (rs != null) { + rs.close(); + } + + if (statement != null) { + statement.close(); + } } } @@ -162,6 +178,7 @@ throw new SQLFeatureNotSupportedException(); } + @Override public java.util.logging.Logger getParentLogger () throws SQLFeatureNotSupportedException { throw new SQLFeatureNotSupportedException(); } -- To view, visit http://gerrit.ovirt.org/12812 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic4f1fe6a9981c6fe8764a803eda4de5d51cc2b6e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Allon Mureinik <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
