You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by li...@apache.org on 2013/07/12 13:22:32 UTC

git commit: updated refs/heads/4.2 to 87df513

Updated Branches:
  refs/heads/4.2 483613431 -> 87df51356


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

Branch: refs/heads/4.2
Commit: 87df51356b8d3a00c1c7a8def753de052a471b3e
Parents: 4836134
Author: Likitha Shetty <li...@citrix.com>
Authored: Fri Jul 12 15:58:35 2013 +0530
Committer: Likitha Shetty <li...@citrix.com>
Committed: Fri Jul 12 16:48:40 2013 +0530

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


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