@@ -230,30 +230,26 @@ public static Class<?> getEntityBeanType(GenericDao<?, Long> dao) {
230230 }
231231
232232 public static boolean releaseGlobalLock (String name ) {
233- Connection conn = getConnectionForGlobalLocks (name , false );
234- if (conn == null ) {
235- s_logger .error ("Unable to acquire DB connection for global lock system" );
236- assert (false );
237- return false ;
238- }
233+ try ( Connection conn = getConnectionForGlobalLocks (name , false );) {
234+ if (conn == null ) {
235+ s_logger .error ("Unable to acquire DB connection for global lock system" );
236+ assert (false );
237+ return false ;
238+ }
239239
240- PreparedStatement pstmt = null ;
241- ResultSet rs = null ;
242- try {
243- pstmt = conn . prepareStatement ( "SELECT COALESCE(RELEASE_LOCK(?), 0)" );
244- pstmt . setString ( 1 , name ) ;
245- rs = pstmt . executeQuery ();
246- if ( rs != null && rs . first ())
247- return rs . getInt ( 1 ) > 0 ;
248- s_logger . error ( "releaseGlobalLock:RELEASE_LOCK() returns unexpected result" );
240+ try ( PreparedStatement pstmt = conn . prepareStatement ( "SELECT COALESCE(RELEASE_LOCK(?), 0)" );) {
241+ pstmt . setString ( 1 , name ) ;
242+ try ( ResultSet rs = pstmt . executeQuery ();) {
243+ if ( rs != null && rs . first ()) {
244+ return rs . getInt ( 1 ) > 0 ;
245+ }
246+ s_logger . error ( "releaseGlobalLock:RELEASE_LOCK() returns unexpected result" );
247+ }
248+ }
249249 } catch (SQLException e ) {
250250 s_logger .error ("RELEASE_LOCK() throws exception " , e );
251251 } catch (Throwable e ) {
252252 s_logger .error ("RELEASE_LOCK() throws exception " , e );
253- } finally {
254- closeResultSet (rs );
255- closeStatement (pstmt );
256- closeConnection (conn );
257253 }
258254 return false ;
259255 }
0 commit comments