Use query parameters instead of string concat 29/78129/2
authorMohammad Salehe <salehe@cs.toronto.edu>
Fri, 8 Feb 2019 16:19:35 +0000 (11:19 -0500)
committerMohammad Salehe <salehe@cs.toronto.edu>
Mon, 25 Feb 2019 03:23:38 +0000 (22:23 -0500)
Change-Id: I477368dec2fe2ea994f02ed90822ee9dc6656945
Issue-ID: MUSIC-148
Signed-off-by: Mohammad Salehe <salehe@cs.toronto.edu>
src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java

index 58163a8..ec694dd 100644 (file)
@@ -269,21 +269,24 @@ public class CassaLockStore {
         * @throws MusicServiceException
         * @throws MusicQueryException
         */     
-       public void deQueueLockRef(String keyspace, String table, String key, String lockReference) throws MusicServiceException, MusicQueryException{
+       public void deQueueLockRef(String keyspace, String table, String key, String lockReference) throws MusicServiceException, MusicQueryException {
                TimeMeasureInstance.instance().enter("deQueueLockRef");
                try {
                           table = table_prepend_name+table; 
                        PreparedQueryObject queryObject = new PreparedQueryObject();
                        Long lockReferenceL = Long.parseLong(lockReference);
-                       String deleteQuery = "delete from "+keyspace+"."+table+" where key='"+key+"' AND lockReference ="+lockReferenceL+" IF EXISTS;";
+                       String deleteQuery = "delete from "+keyspace+"."+table+" where key=? AND lockReference =? IF EXISTS;";
                        queryObject.appendQueryString(deleteQuery);
-                       dsHandle.executePut(queryObject, "critical");
+                       queryObject.addValue(key);
+                       queryObject.addValue(lockReferenceL);
+                       boolean pResult = dsHandle.executePut(queryObject, "critical");
+                       if (pResult == false)
+                               throw new MusicServiceException("Could not destroy lock " + key + "  " + lockReferenceL);
                }
                finally {
                        TimeMeasureInstance.instance().exit();
                }
        }
-       
 
        public void updateLockAcquireTime(String keyspace, String table, String key, String lockReference) throws MusicServiceException, MusicQueryException{
         TimeMeasureInstance.instance().enter("updateLockAcquireTime");