From e13f4914cfb1ae2916a978aa2dd194966f0a0578 Mon Sep 17 00:00:00 2001 From: Rafael da Fonseca Date: Wed, 17 Jun 2015 20:59:43 +0200 Subject: [PATCH] Fix 2 findbugs SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING warnings in ConfigurationManagerImpl.java --- .../configuration/ConfigurationManagerImpl.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 445ffde1e538..315fa8c9cb21 100644 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -926,7 +926,7 @@ protected void checkIfPodIsDeletable(final long podId) { dbName = "cloud"; } - String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; + String selectSql = "SELECT * FROM `?`.`?` WHERE ? = ?"; if(tableName.equals("vm_instance")) { selectSql += " AND state != '" + VirtualMachine.State.Expunging.toString() + "' AND removed IS NULL"; @@ -939,7 +939,10 @@ protected void checkIfPodIsDeletable(final long podId) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql); - stmt.setLong(1, podId); + stmt.setString(1,dbName); + stmt.setString(2,tableName); + stmt.setString(3,column); + stmt.setLong(4, podId); final ResultSet rs = stmt.executeQuery(); if (rs != null && rs.next()) { throw new CloudRuntimeException("The pod cannot be deleted because " + errorMsg); @@ -1385,7 +1388,7 @@ protected void checkIfZoneIsDeletable(final long zoneId) { final String dbName = "cloud"; - String selectSql = "SELECT * FROM `" + dbName + "`.`" + tableName + "` WHERE " + column + " = ?"; + String selectSql = "SELECT * FROM `?`.`?` WHERE ? = ?"; if (tableName.equals("op_dc_vnet_alloc")) { selectSql += " AND taken IS NOT NULL"; @@ -1410,7 +1413,10 @@ protected void checkIfZoneIsDeletable(final long zoneId) { final TransactionLegacy txn = TransactionLegacy.currentTxn(); try { final PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql); - stmt.setLong(1, zoneId); + stmt.setString(1,dbName); + stmt.setString(2,tableName); + stmt.setString(3,column); + stmt.setLong(4, zoneId); final ResultSet rs = stmt.executeQuery(); if (rs != null && rs.next()) { throw new CloudRuntimeException("The zone is not deletable because " + errorMsg);