Fix CID 1116741,1116742 Resource leak

This commit is contained in:
Hugo Trippaers 2013-11-07 16:15:34 +01:00
parent 3f5b8f7063
commit 5cb3cd64e5

View File

@ -17,6 +17,7 @@
package org.apache.cloudstack.framework.config.dao;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -26,9 +27,10 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import com.cloud.utils.component.ComponentLifecycle;
import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.db.DB;
@ -142,14 +144,21 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
@Deprecated
public boolean update(String name, String value) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement stmt = null;
try {
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
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;
}
@ -157,15 +166,22 @@ 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;
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
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;
}
@ -178,9 +194,9 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
@Override
public String getValueAndInitIfNotExist(String name, String category, String initValue) {
return getValueAndInitIfNotExist(name, category, initValue, "");
return getValueAndInitIfNotExist(name, category, initValue, "");
}
@Override
@DB
public String getValueAndInitIfNotExist(String name, String category, String initValue, String desc) {