mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
coverity 1315774: improvement of code to negate false positive
This commit is contained in:
parent
fa56b3f37e
commit
a3ae8e0645
@ -230,30 +230,26 @@ public class DbUtil {
|
||||
}
|
||||
|
||||
public static boolean releaseGlobalLock(String name) {
|
||||
Connection conn = getConnectionForGlobalLocks(name, false);
|
||||
if (conn == null) {
|
||||
s_logger.error("Unable to acquire DB connection for global lock system");
|
||||
assert (false);
|
||||
return false;
|
||||
}
|
||||
try (Connection conn = getConnectionForGlobalLocks(name, false);) {
|
||||
if (conn == null) {
|
||||
s_logger.error("Unable to acquire DB connection for global lock system");
|
||||
assert (false);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");
|
||||
pstmt.setString(1, name);
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs != null && rs.first())
|
||||
return rs.getInt(1) > 0;
|
||||
s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
|
||||
try (PreparedStatement pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");) {
|
||||
pstmt.setString(1, name);
|
||||
try (ResultSet rs = pstmt.executeQuery();) {
|
||||
if (rs != null && rs.first()) {
|
||||
return rs.getInt(1) > 0;
|
||||
}
|
||||
s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("RELEASE_LOCK() throws exception ", e);
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("RELEASE_LOCK() throws exception ", e);
|
||||
} finally {
|
||||
closeResultSet(rs);
|
||||
closeStatement(pstmt);
|
||||
closeConnection(conn);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user