Updated Branches: refs/heads/master-6-17-stable 7279491cc -> 6e160d333
CLOUDSTACK-2757. When configs are added the value of the property 'category' is not persisted. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6e160d33 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6e160d33 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6e160d33 Branch: refs/heads/master-6-17-stable Commit: 6e160d33361e2664f261fdc17d63e947b56105fe Parents: 7279491 Author: Likitha Shetty <[email protected]> Authored: Fri Jul 12 15:58:35 2013 +0530 Committer: Likitha Shetty <[email protected]> Committed: Fri Jul 12 16:53:08 2013 +0530 ---------------------------------------------------------------------- .../configuration/dao/ConfigurationDaoImpl.java | 64 +++++++------------- 1 file changed, 22 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6e160d33/engine/schema/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java b/engine/schema/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java index fe5f5ae..dadeb78 100644 --- a/engine/schema/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java +++ b/engine/schema/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java @@ -171,48 +171,28 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String @Override @DB public String getValueAndInitIfNotExist(String name, String category, String initValue) { - Transaction txn = Transaction.currentTxn(); - PreparedStatement stmt = null; - PreparedStatement stmtInsert = null; - String returnValue = initValue; - try { - txn.start(); - stmt = txn.prepareAutoCloseStatement("SELECT value FROM configuration WHERE name=?"); - stmt.setString(1, name); - ResultSet rs = stmt.executeQuery(); - if(rs != null && rs.next()) { - returnValue = rs.getString(1); - if(returnValue != null) { - txn.commit(); - if("Hidden".equals(category) || "Secure".equals(category)){ - return DBEncryptionUtil.decrypt(returnValue); - } else { - return returnValue; - } - } else { - // restore init value - returnValue = initValue; - } - } - stmt.close(); - - if("Hidden".equals(category) || "Secure".equals(category)){ - initValue = DBEncryptionUtil.encrypt(initValue); - } - stmtInsert = txn.prepareAutoCloseStatement( - "INSERT INTO configuration(instance, name, value, description) VALUES('DEFAULT', ?, ?, '') ON DUPLICATE KEY UPDATE value=?"); - stmtInsert.setString(1, name); - stmtInsert.setString(2, initValue); - stmtInsert.setString(3, initValue); - if(stmtInsert.executeUpdate() < 1) { - throw new CloudRuntimeException("Unable to init configuration variable: " + name); - } - txn.commit(); - return returnValue; - } catch (Exception e) { - s_logger.warn("Unable to update Configuration Value", e); - throw new CloudRuntimeException("Unable to init configuration variable: " + name); - } + String returnValue = initValue; + try { + ConfigurationVO config = findByName(name); + if (config != null) { + if (config.getValue() != null) { + returnValue = config.getValue(); + } else { + update(name, category, initValue); + } + } else { + if (category.equals("Hidden") || category.equals("Secure")) { + initValue = DBEncryptionUtil.encrypt(initValue); + } + ConfigurationVO newConfig = new ConfigurationVO(category, "DEFAULT", "management-server", name, initValue, ""); + persist(newConfig); + } + return returnValue; + } catch (Exception e) { + s_logger.warn("Unable to update Configuration Value", e); + throw new CloudRuntimeException("Unable to initialize configuration variable: " + name); + + } } @Override
