You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2015/06/19 23:26:13 UTC

[1/2] git commit: updated refs/heads/master to 6e06855

Repository: cloudstack
Updated Branches:
  refs/heads/master e3407a393 -> 6e068551d


findbugs: use a prepared statement as prepared statement

Signed-off-by: Daan Hoogland <da...@onecht.net>

This closes #492


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6e068551
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6e068551
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6e068551

Branch: refs/heads/master
Commit: 6e068551d60b68288dd69e8248bcc5043e8e97e8
Parents: e713ed3
Author: Daan Hoogland <da...@onecht.net>
Authored: Fri Jun 19 15:08:23 2015 +0200
Committer: Daan Hoogland <da...@onecht.net>
Committed: Fri Jun 19 23:26:00 2015 +0200

----------------------------------------------------------------------
 server/src/com/cloud/test/PodZoneConfig.java | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6e068551/server/src/com/cloud/test/PodZoneConfig.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/test/PodZoneConfig.java b/server/src/com/cloud/test/PodZoneConfig.java
index 4846fdf..16bc0a0 100644
--- a/server/src/com/cloud/test/PodZoneConfig.java
+++ b/server/src/com/cloud/test/PodZoneConfig.java
@@ -247,8 +247,17 @@ public class PodZoneConfig {
             saveVlan(zoneId, podId, vlanId, vlanGateway, vlanNetmask, vlanType, ipRange, networkId, physicalNetworkDbId);
             if (podId != null) {
                 long vlanDbId = getVlanDbId(zone, vlanId);
-                String sql = "INSERT INTO `cloud`.`pod_vlan_map` (pod_id, vlan_db_id) " + "VALUES ('" + podId + "','" + vlanDbId + "')";
-                DatabaseConfig.saveSQL(sql, "Failed to save pod_vlan_map due to exception vlanDbId=" + vlanDbId + ", podId=" + podId + ". Please contact Cloud Support.");
+                String sql = "INSERT INTO `cloud`.`pod_vlan_map` (pod_id, vlan_db_id) " + "VALUES (?,?)";
+                String errorMsg =  "Failed to save pod_vlan_map due to exception vlanDbId=" + vlanDbId + ", podId=" + podId + ". Please contact Cloud Support.";
+                TransactionLegacy txn = TransactionLegacy.open("saveSQL");
+                try ( PreparedStatement stmt = txn.prepareAutoCloseStatement(sql); ) {
+                        stmt.setString(1, podId.toString());
+                        stmt.setString(2, String.valueOf(vlanDbId));
+                        stmt.executeUpdate();
+                    } catch (SQLException ex) {
+                        System.out.println("SQL Exception: " + ex.getMessage());
+                        printError(errorMsg);
+                    }
             }
 
             return genReturnList("true", "Successfully added VLAN.");


[2/2] git commit: updated refs/heads/master to 6e06855

Posted by da...@apache.org.
findbugs: prepared statements don't make sense if these are not actually prepared

Signed-off-by: Daan Hoogland <da...@onecht.net>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e713ed3b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e713ed3b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e713ed3b

Branch: refs/heads/master
Commit: e713ed3b11bad0a4705d07e65f174a31034e23f0
Parents: e3407a3
Author: Daan Hoogland <da...@onecht.net>
Authored: Fri Jun 19 14:43:13 2015 +0200
Committer: Daan Hoogland <da...@onecht.net>
Committed: Fri Jun 19 23:26:00 2015 +0200

----------------------------------------------------------------------
 server/src/com/cloud/test/DatabaseConfig.java | 37 ++++++++++++++--------
 1 file changed, 23 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e713ed3b/server/src/com/cloud/test/DatabaseConfig.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java
index 097fb99..13dab55 100644
--- a/server/src/com/cloud/test/DatabaseConfig.java
+++ b/server/src/com/cloud/test/DatabaseConfig.java
@@ -1138,22 +1138,22 @@ public class DatabaseConfig {
     @DB
     protected void saveUser() {
         // insert system account
-        String insertSql = "INSERT INTO `cloud`.`account` (id, account_name, type, domain_id) VALUES (1, 'system', '1', '1')";
+        final String insertSystemAccount = "INSERT INTO `cloud`.`account` (id, account_name, type, domain_id) VALUES (1, 'system', '1', '1')";
         TransactionLegacy txn = TransactionLegacy.currentTxn();
         try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSystemAccount);
             stmt.executeUpdate();
         } catch (SQLException ex) {
             s_logger.error("error creating system account", ex);
         }
 
         // insert system user
-        insertSql =
+        final String insertSystemUser =
             "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, created)"
                 + " VALUES (1, 'system', RAND(), 1, 'system', 'cloud', now())";
         txn = TransactionLegacy.currentTxn();
         try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSystemUser);
             stmt.executeUpdate();
         } catch (SQLException ex) {
             s_logger.error("error creating system user", ex);
@@ -1189,10 +1189,10 @@ public class DatabaseConfig {
         sb.append(pwStr);
 
         // create an account for the admin user first
-        insertSql = "INSERT INTO `cloud`.`account` (id, account_name, type, domain_id) VALUES (?, ?, '1', '1')";
+        final String insertAdminAccount = "INSERT INTO `cloud`.`account` (id, account_name, type, domain_id) VALUES (?, ?, '1', '1')";
         txn = TransactionLegacy.currentTxn();
         try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertAdminAccount);
             stmt.setLong(1, id);
             stmt.setString(2, username);
             stmt.executeUpdate();
@@ -1201,13 +1201,17 @@ public class DatabaseConfig {
         }
 
         // now insert the user
-        insertSql =
-            "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, email, created) " + "VALUES (" + id + ",'" + username + "','" +
-                sb.toString() + "', 2, '" + firstname + "','" + lastname + "','" + email + "',now())";
-
+        final String insertUser =
+                "INSERT INTO `cloud`.`user` (id, username, password, account_id, firstname, lastname, email, created) " + "VALUES (?,?,?, 2, ?,?,?,now())";
         txn = TransactionLegacy.currentTxn();
         try {
-            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
+            PreparedStatement stmt = txn.prepareAutoCloseStatement(insertUser);
+            stmt.setLong(1, id);
+            stmt.setString(2, username);
+            stmt.setString(3, sb.toString());
+            stmt.setString(4, firstname);
+            stmt.setString(5, lastname);
+            stmt.setString(6, email);
             stmt.executeUpdate();
         } catch (SQLException ex) {
             s_logger.error("error creating user", ex);
@@ -1257,9 +1261,8 @@ public class DatabaseConfig {
         }
 
         String insertSql =
-            "INSERT INTO `cloud`.`configuration` (instance, component, name, value, description, category) " + "VALUES ('" + instance + "','" + component + "','" + name +
-                "','" + value + "','" + description + "','" + category + "')";
-
+                "INSERT INTO `cloud`.`configuration` (instance, component, name, value, description, category) " +
+                "VALUES (?,?,?,?,?,?)";
         String selectSql = "SELECT name FROM cloud.configuration WHERE name = ?";
 
         TransactionLegacy txn = TransactionLegacy.currentTxn();
@@ -1270,6 +1273,12 @@ public class DatabaseConfig {
             Boolean hasRow = result.next();
             if (!hasRow) {
                 stmt = txn.prepareAutoCloseStatement(insertSql);
+                stmt.setString(1, instance);
+                stmt.setString(2, component);
+                stmt.setString(3, name);
+                stmt.setString(4, value);
+                stmt.setString(5, description);
+                stmt.setString(6, category);
                 stmt.executeUpdate();
             }
         } catch (SQLException ex) {