mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
CLOUDSTACK-8656: replace empty catch block on close by try-with-resource
This commit is contained in:
parent
f221b9a423
commit
87ae150159
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user