CLOUDSTACK-8656: replace empty catch block on close by try-with-resource

This commit is contained in:
Daan Hoogland 2015-08-03 19:42:47 +02:00
parent f221b9a423
commit 87ae150159

View File

@ -144,21 +144,13 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
@Deprecated
public boolean update(String name, String value) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement stmt = null;
try {
stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
try (PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);){
stmt.setString(1, value);
stmt.setString(2, name);
stmt.executeUpdate();
return true;
} catch (Exception e) {
s_logger.warn("Unable to update Configuration Value", e);
} finally {
try {
if (stmt != null)
stmt.close();
} catch (SQLException e) {
}
}
return false;
}
@ -166,22 +158,14 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
@Override
public boolean update(String name, String category, String value) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement stmt = null;
try {
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
try (PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);) {
stmt.setString(1, value);
stmt.setString(2, name);
stmt.executeUpdate();
return true;
} catch (Exception e) {
s_logger.warn("Unable to update Configuration Value", e);
} finally {
try {
if (stmt != null)
stmt.close();
} catch (SQLException e) {
}
}
return false;
}