Updated Branches:
  refs/heads/master 9d857c036 -> aaaf168f5

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/aaaf168f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/aaaf168f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/aaaf168f

Branch: refs/heads/master
Commit: aaaf168f5a38294ef098bdf9c60657711f6655bf
Parents: 9d857c0
Author: Likitha Shetty <[email protected]>
Authored: Fri Jul 12 15:58:35 2013 +0530
Committer: Likitha Shetty <[email protected]>
Committed: Fri Jul 12 16:50:30 2013 +0530

----------------------------------------------------------------------
 .../configuration/dao/ConfigurationDaoImpl.java | 64 +++++++-------------
 1 file changed, 22 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aaaf168f/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

Reply via email to