changeset 1171:d04860739261

Fix prepared queries (String Keys were missing quotes). Reviewed-by: ebaron Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-July/007492.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 16 Jul 2013 14:56:10 +0200
parents 0a210b878276
children c792f093228c
files numa/common/src/main/java/com/redhat/thermostat/numa/common/internal/NumaDAOImpl.java numa/common/src/test/java/com/redhat/thermostat/numa/common/internal/NumaDAOImplTest.java storage/core/src/main/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetter.java storage/core/src/main/java/com/redhat/thermostat/storage/core/StatementDescriptor.java storage/core/src/main/java/com/redhat/thermostat/storage/core/VmLatestPojoListGetter.java storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/AgentInfoDAOImpl.java storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/BackendInfoDAOImpl.java storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/HostInfoDAOImpl.java storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/NetworkInterfaceInfoDAOImpl.java storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/VmInfoDAOImpl.java storage/core/src/test/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetterTest.java storage/core/src/test/java/com/redhat/thermostat/storage/core/StatementDescriptorTest.java storage/core/src/test/java/com/redhat/thermostat/storage/core/VmLatestPojoListGetterTest.java storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/AgentInfoDAOTest.java storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/BackendInfoDAOTest.java storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/HostInfoDAOTest.java storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/NetworkInterfaceInfoDAOTest.java storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/VmInfoDAOTest.java thread/collector/src/main/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImpl.java thread/collector/src/test/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImplTest.java vm-heap-analysis/common/src/main/java/com/redhat/thermostat/vm/heap/analysis/common/internal/HeapDAOImpl.java vm-heap-analysis/common/src/test/java/com/redhat/thermostat/vm/heap/analysis/common/internal/HeapDAOTest.java vm-jmx/common/src/main/java/com/redhat/thermostat/vm/jmx/common/internal/JmxNotificationDAOImpl.java vm-jmx/common/src/test/java/com/redhat/thermostat/vm/jmx/common/internal/JmxNotificationDAOImplTest.java vm-memory/common/src/main/java/com/redhat/thermostat/vm/memory/common/internal/VmMemoryStatDAOImpl.java vm-memory/common/src/test/java/com/redhat/thermostat/vm/memory/common/internal/VmMemoryStatDAOTest.java
diffstat 26 files changed, 264 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/numa/common/src/main/java/com/redhat/thermostat/numa/common/internal/NumaDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/numa/common/src/main/java/com/redhat/thermostat/numa/common/internal/NumaDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -59,9 +59,9 @@
 public class NumaDAOImpl implements NumaDAO {
 
     private static final Logger logger = LoggingUtils.getLogger(NumaDAOImpl.class);
-    private static final String QUERY_NUMA_INFO = "QUERY "
-            + numaHostCategory.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s LIMIT 1";
+    static final String QUERY_NUMA_INFO = "QUERY "
+            + numaHostCategory.getName() + " WHERE '" 
+            + Key.AGENT_ID.getName() + "' = ?s LIMIT 1";
     
     private final Storage storage;
     private final HostLatestPojoListGetter<NumaStat> getter;
--- a/numa/common/src/test/java/com/redhat/thermostat/numa/common/internal/NumaDAOImplTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/numa/common/src/test/java/com/redhat/thermostat/numa/common/internal/NumaDAOImplTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -55,7 +55,6 @@
 import com.redhat.thermostat.storage.core.Cursor;
 import com.redhat.thermostat.storage.core.DescriptorParsingException;
 import com.redhat.thermostat.storage.core.HostRef;
-import com.redhat.thermostat.storage.core.Key;
 import com.redhat.thermostat.storage.core.PreparedStatement;
 import com.redhat.thermostat.storage.core.StatementDescriptor;
 import com.redhat.thermostat.storage.core.StatementExecutionException;
@@ -77,6 +76,12 @@
         numaDAO = null;
         storage = null;
     }
+    
+    @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedQueryNumaInfo = "QUERY numa-host-info WHERE 'agentId' = ?s LIMIT 1";
+        assertEquals(expectedQueryNumaInfo, NumaDAOImpl.QUERY_NUMA_INFO);
+    }
 
     @Test
     public void testRegisterCategory() {
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetter.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetter.java	Tue Jul 16 14:56:10 2013 +0200
@@ -56,10 +56,10 @@
     public HostLatestPojoListGetter(Storage storage, Category<T> cat) {
         this.storage = storage;
         this.cat = cat;
-        this.queryLatest = "QUERY " + cat.getName() + " WHERE "
-                + Key.AGENT_ID.getName() + " = ?s AND "
-                + Key.TIMESTAMP.getName() + " > ?l SORT "
-                + Key.TIMESTAMP.getName() + " DSC";
+        this.queryLatest = "QUERY " + cat.getName() + " WHERE '"
+                + Key.AGENT_ID.getName() + "' = ?s AND '"
+                + Key.TIMESTAMP.getName() + "' > ?l SORT '"
+                + Key.TIMESTAMP.getName() + "' DSC";
     }
 
     public List<T> getLatest(HostRef hostRef, long since) {
@@ -100,5 +100,10 @@
         }
         return stmt;
     }
+    
+    // package private for testing
+    String getQueryLatestDesc() {
+        return queryLatest;
+    }
 }
 
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/StatementDescriptor.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/core/StatementDescriptor.java	Tue Jul 16 14:56:10 2013 +0200
@@ -4,8 +4,8 @@
 
 public class StatementDescriptor<T extends Pojo> {
     
-    private Category<T> category;
-    private String desc;
+    private final Category<T> category;
+    private final String desc;
     
     public StatementDescriptor(Category<T> category, String desc) {
         this.category = category;
@@ -16,7 +16,7 @@
      * Describes this statement for preparation. For example:
      * 
      * <pre>
-     * Query host-info where agentId = ?
+     * QUERY host-info WHERE 'agentId' = ?s LIMIT 1
      * </pre>
      * 
      * @return The statement descriptor.
@@ -29,4 +29,9 @@
         return category;
     }
     
+    @Override
+    public String toString() {
+        return desc;
+    }
+    
 }
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/core/VmLatestPojoListGetter.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/core/VmLatestPojoListGetter.java	Tue Jul 16 14:56:10 2013 +0200
@@ -56,11 +56,11 @@
     public VmLatestPojoListGetter(Storage storage, Category<T> cat) {
         this.storage = storage;
         this.cat = cat;
-        this.queryLatest = "QUERY " + cat.getName() + " WHERE "
-                + Key.AGENT_ID.getName() + " = ?s AND "
-                + Key.VM_ID.getName() + " = ?i AND " 
-                + Key.TIMESTAMP.getName() + " > ?l SORT "
-                + Key.TIMESTAMP.getName() + " DSC";
+        this.queryLatest = "QUERY " + cat.getName() + " WHERE '"
+                + Key.AGENT_ID.getName() + "' = ?s AND '"
+                + Key.VM_ID.getName() + "' = ?i AND '" 
+                + Key.TIMESTAMP.getName() + "' > ?l SORT '"
+                + Key.TIMESTAMP.getName() + "' DSC";
     }
 
     public List<T> getLatest(VmRef vmRef, long since) {
@@ -103,6 +103,11 @@
         }
         return stmt;
     }
+    
+    // package private for tests
+    String getQueryLatestDesc() {
+        return queryLatest;
+    }
 
 }
 
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/AgentInfoDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/AgentInfoDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -62,14 +62,14 @@
 public class AgentInfoDAOImpl implements AgentInfoDAO {
 
     private static final Logger logger = LoggingUtils.getLogger(AgentInfoDAOImpl.class);
-    private static final String QUERY_AGENT_INFO = "QUERY "
-            + CATEGORY.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s";
-    private static final String QUERY_ALL_AGENTS = "QUERY "
+    static final String QUERY_AGENT_INFO = "QUERY "
+            + CATEGORY.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s";
+    static final String QUERY_ALL_AGENTS = "QUERY "
             + CATEGORY.getName();
-    private static final String QUERY_ALIVE_AGENTS = "QUERY "
-            + CATEGORY.getName() + " WHERE " 
-            + ALIVE_KEY.getName() + " = ?b";
+    static final String QUERY_ALIVE_AGENTS = "QUERY "
+            + CATEGORY.getName() + " WHERE '" 
+            + ALIVE_KEY.getName() + "' = ?b";
     
     private final Storage storage;
     private final ExpressionFactory factory;
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/BackendInfoDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/BackendInfoDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -62,9 +62,9 @@
 public class BackendInfoDAOImpl implements BackendInfoDAO {
     
     private static final Logger logger = LoggingUtils.getLogger(BackendInfoDAOImpl.class);
-    private static final String QUERY_BACKEND_INFO = "QUERY "
-            + CATEGORY.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s";
+    static final String QUERY_BACKEND_INFO = "QUERY "
+            + CATEGORY.getName() + " WHERE '" 
+            + Key.AGENT_ID.getName() + "' = ?s";
 
     private final Storage storage;
     private final ExpressionFactory factory;
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/HostInfoDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/HostInfoDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -61,10 +61,10 @@
 public class HostInfoDAOImpl implements HostInfoDAO {
     
     private static final Logger logger = LoggingUtils.getLogger(HostInfoDAOImpl.class);
-    private static final String QUERY_HOST_INFO = "QUERY "
-            + hostInfoCategory.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s LIMIT 1";
-    private static final String QUERY_ALL_HOSTS = "QUERY " + hostInfoCategory.getName();
+    static final String QUERY_HOST_INFO = "QUERY "
+            + hostInfoCategory.getName() + " WHERE '" 
+            + Key.AGENT_ID.getName() + "' = ?s LIMIT 1";
+    static final String QUERY_ALL_HOSTS = "QUERY " + hostInfoCategory.getName();
 
     private final Storage storage;
     private final AgentInfoDAO agentInfoDao;
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/NetworkInterfaceInfoDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/NetworkInterfaceInfoDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -58,9 +58,9 @@
 public class NetworkInterfaceInfoDAOImpl implements NetworkInterfaceInfoDAO {
 
     private static final Logger logger = LoggingUtils.getLogger(NetworkInterfaceInfoDAOImpl.class);
-    private static final String QUERY_NETWORK_INFO = "QUERY "
-            + networkInfoCategory.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s";
+    static final String QUERY_NETWORK_INFO = "QUERY "
+            + networkInfoCategory.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s";
 
     private Storage storage;
 
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/VmInfoDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/VmInfoDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -64,13 +64,13 @@
 public class VmInfoDAOImpl implements VmInfoDAO {
     
     private final Logger logger = LoggingUtils.getLogger(VmInfoDAOImpl.class);
-    private final String QUERY_VM_INFO = "QUERY " 
-            + vmInfoCategory.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s AND "
-            + Key.VM_ID.getName() + " = ?i LIMIT 1";
-    private final String QUERY_ALL_VMS = "QUERY " 
-            + vmInfoCategory.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s";
+    static final String QUERY_VM_INFO = "QUERY " 
+            + vmInfoCategory.getName() + " WHERE '" 
+            + Key.AGENT_ID.getName() + "' = ?s AND '"
+            + Key.VM_ID.getName() + "' = ?i LIMIT 1";
+    static final String QUERY_ALL_VMS = "QUERY " 
+            + vmInfoCategory.getName() + " WHERE '" 
+            + Key.AGENT_ID.getName() + "' = ?s";
     
     private final Storage storage;
     private final ExpressionFactory factory;
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetterTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/core/HostLatestPojoListGetterTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -97,6 +97,16 @@
         when(result3.getTimeStamp()).thenReturn(t3);
         when(result3.getData()).thenReturn(d3);
     }
+    
+    @Test
+    public void verifyQueryDescriptorIsSane() {
+        Storage storage = mock(Storage.class);
+        HostLatestPojoListGetter<TestPojo> getter = new HostLatestPojoListGetter<>(storage, cat);
+        String actualDesc = getter.getQueryLatestDesc();
+        String expected = "QUERY hostcategory WHERE 'agentId' = ?s AND " +
+         "'timeStamp' > ?l SORT 'timeStamp' DSC";
+        assertEquals(expected, actualDesc);
+    }
 
     @Test
     public void testBuildQuery() throws DescriptorParsingException {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/core/StatementDescriptorTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2012, 2013 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.storage.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import org.junit.Test;
+
+public class StatementDescriptorTest {
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testToString() {
+        String desc = "QUERY agent-config WHERE 'agentId' = ?s";
+        Category cat = mock(Category.class);
+        StatementDescriptor stmtDesc = new StatementDescriptor(cat, desc);
+        // toString is used extensively for logging.
+        assertEquals(desc, stmtDesc.toString());
+    }
+    
+}
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/core/VmLatestPojoListGetterTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/core/VmLatestPojoListGetterTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -88,6 +88,16 @@
         when(result3.getTimeStamp()).thenReturn(t3);
         when(result3.getData()).thenReturn(lc3);
     }
+    
+    @Test
+    public void verifyQueryDescriptorIsSane() {
+        Storage storage = mock(Storage.class);
+        VmLatestPojoListGetter<TestPojo> getter = new VmLatestPojoListGetter<>(storage, cat);
+        String actualDesc = getter.getQueryLatestDesc();
+        String expected = "QUERY vmcategory WHERE 'agentId' = ?s AND " +
+         "'vmId' = ?i AND 'timeStamp' > ?l SORT 'timeStamp' DSC";
+        assertEquals(expected, actualDesc);
+    }
 
     @Test
     public void testBuildQuery() throws DescriptorParsingException {
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/AgentInfoDAOTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/AgentInfoDAOTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -94,6 +94,16 @@
     }
 
     @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedAgentInfo = "QUERY agent-config WHERE 'agentId' = ?s";
+        assertEquals(expectedAgentInfo, AgentInfoDAOImpl.QUERY_AGENT_INFO);
+        String expectedAllAgents = "QUERY agent-config";
+        assertEquals(expectedAllAgents, AgentInfoDAOImpl.QUERY_ALL_AGENTS);
+        String expectedAliveAgents = "QUERY agent-config WHERE 'alive' = ?b";
+        assertEquals(expectedAliveAgents, AgentInfoDAOImpl.QUERY_ALIVE_AGENTS);
+    }
+    
+    @Test
     public void verifyCategoryName() {
         Category<AgentInformation> category = AgentInfoDAO.CATEGORY;
         assertEquals("agent-config", category.getName());
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/BackendInfoDAOTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/BackendInfoDAOTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -98,6 +98,12 @@
         
         factory = new ExpressionFactory();
     }
+    
+    @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedBackendInfo = "QUERY backend-info WHERE 'agentId' = ?s";
+        assertEquals(expectedBackendInfo, BackendInfoDAOImpl.QUERY_BACKEND_INFO);
+    }
 
     @Test
     public void verifyCategoryName() {
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/HostInfoDAOTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/HostInfoDAOTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -88,6 +88,14 @@
     private static final long MEMORY_TOTAL = 0xCAFEBABEl;
 
     @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedHostInfo = "QUERY host-info WHERE 'agentId' = ?s LIMIT 1";
+        assertEquals(expectedHostInfo, HostInfoDAOImpl.QUERY_HOST_INFO);
+        String expectedAllHosts = "QUERY host-info";
+        assertEquals(expectedAllHosts, HostInfoDAOImpl.QUERY_ALL_HOSTS);
+    }
+    
+    @Test
     public void testCategory() {
         assertEquals("host-info", HostInfoDAO.hostInfoCategory.getName());
         Collection<Key<?>> keys = HostInfoDAO.hostInfoCategory.getKeys();
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/NetworkInterfaceInfoDAOTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/NetworkInterfaceInfoDAOTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -80,6 +80,12 @@
         assertTrue(keys.contains(new Key<String>("ip6Addr", false)));
         assertEquals(4, keys.size());
     }
+    
+    @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedNetworkInfo = "QUERY network-info WHERE 'agentId' = ?s";
+        assertEquals(expectedNetworkInfo, NetworkInterfaceInfoDAOImpl.QUERY_NETWORK_INFO);
+    }
 
     @Test
     public void testGetNetworkInterfaces() throws DescriptorParsingException, StatementExecutionException {
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/VmInfoDAOTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/VmInfoDAOTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -108,6 +108,14 @@
         uid = 2000;
         username = "myUser";
     }
+    
+    @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedVmInfo = "QUERY vm-info WHERE 'agentId' = ?s AND 'vmId' = ?i LIMIT 1";
+        assertEquals(expectedVmInfo, VmInfoDAOImpl.QUERY_VM_INFO);
+        String expectedVmInfoAll = "QUERY vm-info WHERE 'agentId' = ?s";
+        assertEquals(expectedVmInfoAll, VmInfoDAOImpl.QUERY_ALL_VMS);
+    }
 
     @Test
     public void testCategory() {
--- a/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/thread/collector/src/main/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -66,37 +66,37 @@
     private static final Logger logger = LoggingUtils.getLogger(ThreadDaoImpl.class);
     
     // Queries
-    private static final String QUERY_THREAD_CAPS = "QUERY "
-            + THREAD_CAPABILITIES.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i LIMIT 1";
-    private static final String QUERY_LATEST_SUMMARY = "QUERY "
-            + THREAD_SUMMARY.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i SORT " 
-            + Key.TIMESTAMP.getName() + "DSC LIMIT 1";
-    private static final String QUERY_SUMMARY_SINCE = "QUERY "
-            + THREAD_SUMMARY.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i AND "
-            + Key.TIMESTAMP.getName() + " > ?l SORT "
-            + Key.TIMESTAMP.getName() + "DSC";
-    private static final String QUERY_LATEST_HARVESTING_STATUS = "QUERY "
-            + THREAD_HARVESTING_STATUS.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i SORT " 
-            + Key.TIMESTAMP.getName() + "DSC LIMIT 1";
-    private static final String QUERY_THREAD_INFO = "QUERY "
-            + THREAD_INFO.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i AND "
-            + Key.TIMESTAMP.getName() + " > ?l SORT "
-            + Key.TIMESTAMP.getName() + "DSC";
-    private static final String QUERY_LATEST_DEADLOCK_INFO = "QUERY "
-            + DEADLOCK_INFO.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i SORT " 
-            + Key.TIMESTAMP.getName() + "DSC LIMIT 1";
+    static final String QUERY_THREAD_CAPS = "QUERY "
+            + THREAD_CAPABILITIES.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i LIMIT 1";
+    static final String QUERY_LATEST_SUMMARY = "QUERY "
+            + THREAD_SUMMARY.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i SORT '" 
+            + Key.TIMESTAMP.getName() + "' DSC LIMIT 1";
+    static final String QUERY_SUMMARY_SINCE = "QUERY "
+            + THREAD_SUMMARY.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i AND '"
+            + Key.TIMESTAMP.getName() + "' > ?l SORT '"
+            + Key.TIMESTAMP.getName() + "' DSC";
+    static final String QUERY_LATEST_HARVESTING_STATUS = "QUERY "
+            + THREAD_HARVESTING_STATUS.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i SORT '" 
+            + Key.TIMESTAMP.getName() + "' DSC LIMIT 1";
+    static final String QUERY_THREAD_INFO = "QUERY "
+            + THREAD_INFO.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i AND '"
+            + Key.TIMESTAMP.getName() + "' > ?l SORT '"
+            + Key.TIMESTAMP.getName() + "' DSC";
+    static final String QUERY_LATEST_DEADLOCK_INFO = "QUERY "
+            + DEADLOCK_INFO.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i SORT '" 
+            + Key.TIMESTAMP.getName() + "' DSC LIMIT 1";
     
     private Storage storage;
     
--- a/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImplTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/thread/collector/src/test/java/com/redhat/thermostat/thread/dao/impl/ThreadDaoImplTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -70,6 +70,22 @@
 public class ThreadDaoImplTest {
 
     @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedQueryThreadCaps = "QUERY vm-thread-capabilities WHERE 'agentId' = ?s AND 'vmId' = ?i LIMIT 1";
+        assertEquals(expectedQueryThreadCaps, ThreadDaoImpl.QUERY_THREAD_CAPS);
+        String expectedQueryLatestSummary = "QUERY vm-thread-summary WHERE 'agentId' = ?s AND 'vmId' = ?i SORT 'timeStamp' DSC LIMIT 1";
+        assertEquals(expectedQueryLatestSummary, ThreadDaoImpl.QUERY_LATEST_SUMMARY);
+        String expectedQuerySummarySince = "QUERY vm-thread-summary WHERE 'agentId' = ?s AND 'vmId' = ?i AND 'timeStamp' > ?l SORT 'timeStamp' DSC";
+        assertEquals(expectedQuerySummarySince, ThreadDaoImpl.QUERY_SUMMARY_SINCE);
+        String expectedQueryLatestHarvestingStatus = "QUERY vm-thread-harvesting WHERE 'agentId' = ?s AND 'vmId' = ?i SORT 'timeStamp' DSC LIMIT 1";
+        assertEquals(expectedQueryLatestHarvestingStatus, ThreadDaoImpl.QUERY_LATEST_HARVESTING_STATUS);
+        String expectedQueryThreadInfo = "QUERY vm-thread-info WHERE 'agentId' = ?s AND 'vmId' = ?i AND 'timeStamp' > ?l SORT 'timeStamp' DSC";
+        assertEquals(expectedQueryThreadInfo, ThreadDaoImpl.QUERY_THREAD_INFO);
+        String expectedQueryThreadLatestDeadlockInfo = "QUERY vm-deadlock-data WHERE 'agentId' = ?s AND 'vmId' = ?i SORT 'timeStamp' DSC LIMIT 1";
+        assertEquals(expectedQueryThreadLatestDeadlockInfo, ThreadDaoImpl.QUERY_LATEST_DEADLOCK_INFO);
+    }
+    
+    @Test
     public void testThreadDaoCategoryRegistration() {
         Storage storage = mock(Storage.class);
         
--- a/vm-heap-analysis/common/src/main/java/com/redhat/thermostat/vm/heap/analysis/common/internal/HeapDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/vm-heap-analysis/common/src/main/java/com/redhat/thermostat/vm/heap/analysis/common/internal/HeapDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -68,13 +68,13 @@
 public class HeapDAOImpl implements HeapDAO {
 
     private static final Logger log = LoggingUtils.getLogger(HeapDAOImpl.class);
-    private static final String QUERY_ALL_HEAPS = "QUERY "
-            + heapInfoCategory.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i";
-    private static final String QUERY_HEAP_INFO = "QUERY "
-            + heapInfoCategory.getName() + " WHERE " 
-            + heapIdKey.getName() + " = ?s LIMIT 1";
+    static final String QUERY_ALL_HEAPS = "QUERY "
+            + heapInfoCategory.getName() + " WHERE '" 
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i";
+    static final String QUERY_HEAP_INFO = "QUERY "
+            + heapInfoCategory.getName() + " WHERE '" 
+            + heapIdKey.getName() + "' = ?s LIMIT 1";
 
     private final Storage storage;
 
--- a/vm-heap-analysis/common/src/test/java/com/redhat/thermostat/vm/heap/analysis/common/internal/HeapDAOTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/vm-heap-analysis/common/src/test/java/com/redhat/thermostat/vm/heap/analysis/common/internal/HeapDAOTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -183,6 +183,14 @@
         storage = null;
         add = null;
     }
+    
+    @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedQueryHeapInfo = "QUERY vm-heap-info WHERE 'heapId' = ?s LIMIT 1";
+        assertEquals(expectedQueryHeapInfo, HeapDAOImpl.QUERY_HEAP_INFO);
+        String expectedQueryAllHeaps = "QUERY vm-heap-info WHERE 'agentId' = ?s AND 'vmId' = ?i";
+        assertEquals(expectedQueryAllHeaps, HeapDAOImpl.QUERY_ALL_HEAPS);
+    }
 
     @Test
     public void testCategory() {
--- a/vm-jmx/common/src/main/java/com/redhat/thermostat/vm/jmx/common/internal/JmxNotificationDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/vm-jmx/common/src/main/java/com/redhat/thermostat/vm/jmx/common/internal/JmxNotificationDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -78,16 +78,16 @@
                     Key.AGENT_ID, Key.VM_ID, Key.TIMESTAMP,
                     SOURCE_BACKEND, SOURCE_DESCRPTION, CONTENTS);
 
-    private static final String QUERY_LATEST_NOTIFICATION_STATUS = "QUERY "
-            + NOTIFICATION_STATUS.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i SORT " 
-            + Key.TIMESTAMP.getName() + " DSC LIMIT 1";
-    private static final String QUERY_NOTIFICATIONS = "QUERY "
-            + NOTIFICATIONS.getName() + " WHERE " 
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i AND "
-            + Key.TIMESTAMP.getName() + " > ?l";
+    static final String QUERY_LATEST_NOTIFICATION_STATUS = "QUERY "
+            + NOTIFICATION_STATUS.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i SORT '" 
+            + Key.TIMESTAMP.getName() + "' DSC LIMIT 1";
+    static final String QUERY_NOTIFICATIONS = "QUERY "
+            + NOTIFICATIONS.getName() + " WHERE '" 
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i AND '"
+            + Key.TIMESTAMP.getName() + "' > ?l";
     
     private Storage storage;
 
--- a/vm-jmx/common/src/test/java/com/redhat/thermostat/vm/jmx/common/internal/JmxNotificationDAOImplTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/vm-jmx/common/src/test/java/com/redhat/thermostat/vm/jmx/common/internal/JmxNotificationDAOImplTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -87,6 +87,14 @@
 
         dao = new JmxNotificationDAOImpl(storage);
     }
+    
+    @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedQueryLatestNotificationStatus = "QUERY vm-jmx-notification-status WHERE 'agentId' = ?s AND 'vmId' = ?i SORT 'timeStamp' DSC LIMIT 1";
+        assertEquals(expectedQueryLatestNotificationStatus, JmxNotificationDAOImpl.QUERY_LATEST_NOTIFICATION_STATUS);
+        String expectedQueryNotifications = "QUERY vm-jmx-notification WHERE 'agentId' = ?s AND 'vmId' = ?i AND 'timeStamp' > ?l";
+        assertEquals(expectedQueryNotifications, JmxNotificationDAOImpl.QUERY_NOTIFICATIONS);
+    }
 
     @Test
     public void verifyAddNotificationStatus() {
--- a/vm-memory/common/src/main/java/com/redhat/thermostat/vm/memory/common/internal/VmMemoryStatDAOImpl.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/vm-memory/common/src/main/java/com/redhat/thermostat/vm/memory/common/internal/VmMemoryStatDAOImpl.java	Tue Jul 16 14:56:10 2013 +0200
@@ -57,11 +57,11 @@
 class VmMemoryStatDAOImpl implements VmMemoryStatDAO {
 
     private static final Logger logger = LoggingUtils.getLogger(VmMemoryStatDAOImpl.class);
-    private static final String QUERY_LATEST = "QUERY "
-            + vmMemoryStatsCategory.getName() + " WHERE "
-            + Key.AGENT_ID.getName() + " = ?s AND " 
-            + Key.VM_ID.getName() + " = ?i SORT " 
-            + Key.TIMESTAMP.getName() + " DSC LIMIT 1";
+    static final String QUERY_LATEST = "QUERY "
+            + vmMemoryStatsCategory.getName() + " WHERE '"
+            + Key.AGENT_ID.getName() + "' = ?s AND '" 
+            + Key.VM_ID.getName() + "' = ?i SORT '" 
+            + Key.TIMESTAMP.getName() + "' DSC LIMIT 1";
     
     private final Storage storage;
     private final VmLatestPojoListGetter<VmMemoryStat> getter;
--- a/vm-memory/common/src/test/java/com/redhat/thermostat/vm/memory/common/internal/VmMemoryStatDAOTest.java	Mon Jul 15 11:23:41 2013 +0200
+++ b/vm-memory/common/src/test/java/com/redhat/thermostat/vm/memory/common/internal/VmMemoryStatDAOTest.java	Tue Jul 16 14:56:10 2013 +0200
@@ -111,6 +111,12 @@
         cursor = null;
         storage = null;
     }
+    
+    @Test
+    public void preparedQueryDescriptorsAreSane() {
+        String expectedQueryThreadCaps = "QUERY vm-memory-stats WHERE 'agentId' = ?s AND 'vmId' = ?i SORT 'timeStamp' DSC LIMIT 1";
+        assertEquals(expectedQueryThreadCaps, VmMemoryStatDAOImpl.QUERY_LATEST);
+    }
 
     @Test
     public void testCategories() {