cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [2/2] git commit: updated refs/heads/master to 6e06855
Date Fri, 19 Jun 2015 21:26:14 GMT
findbugs: prepared statements don't make sense if these are not actually prepared

Signed-off-by: Daan Hoogland <daan@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 <daan@onecht.net>
Authored: Fri Jun 19 14:43:13 2015 +0200
Committer: Daan Hoogland <daan@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) {


Mime
View raw message