gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djkevi...@apache.org
Subject [21/32] gora git commit: Add delete by query functionality to aerospike module
Date Thu, 27 Jul 2017 18:45:47 GMT
Add delete by query functionality to aerospike module


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

Branch: refs/heads/master
Commit: c485f5bed92b784a4dd915c6fe5d7b95a9990618
Parents: 2d667ed
Author: nishadi <ndimeshi@gmail.com>
Authored: Wed Jul 19 23:35:55 2017 +0530
Committer: nishadi <ndimeshi@gmail.com>
Committed: Wed Jul 19 23:35:55 2017 +0530

----------------------------------------------------------------------
 .../aerospike/query/AerospikeQueryResult.java   |  1 +
 .../gora/aerospike/store/AerospikeStore.java    | 20 ++++++++++++++++++-
 .../aerospike/store/TestAerospikeStore.java     | 21 ++++++++++++++++----
 3 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/c485f5be/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
index 8858f34..3ddca3c 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/query/AerospikeQueryResult.java
@@ -73,6 +73,7 @@ public class AerospikeQueryResult<K, T extends Persistent> extends
ResultBase<K,
     if (offset < 0 || offset > (resultRecords.size() - 1)) {
       return false;
     }
+    key = (K) resultRecords.get((int) this.offset).getKey().userKey;
     persistent = (T) getDataStore()
             .createPersistentInstance(resultRecords.get((int) this.offset).getRecord(), fields);
     return true;

http://git-wip-us.apache.org/repos/asf/gora/blob/c485f5be/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 7fe7573..dfa8ed9 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -211,9 +211,27 @@ public class AerospikeStore<K, T extends PersistentBase> extends
DataStoreBase<K
             .delete(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey);
   }
 
+  /**
+   * {@inheritDoc}
+   *
+   * @param query matching records to this query will be deleted
+   * @return the number of deleted records
+   */
   @Override
   public long deleteByQuery(Query<K, T> query) {
-    return 0;
+    Result<K, T> result = query.execute();
+    int deleteCount = 0;
+    try {
+      while(result.next()) {
+        if(aerospikeClient.delete(null,getAerospikeKey(result.getKey()))){
+          deleteCount++;
+        }
+      }
+      return deleteCount;
+    } catch (Exception e) {
+      LOG.error(e.getMessage(), e);
+      return -1;
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/gora/blob/c485f5be/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 317fb12..d88ea1a 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -19,12 +19,17 @@
 package org.apache.gora.aerospike.store;
 
 import org.apache.gora.aerospike.GoraAerospikeTestDriver;
+import org.apache.gora.examples.WebPageDataCreator;
+import org.apache.gora.examples.generated.WebPage;
+import org.apache.gora.query.Query;
 import org.apache.gora.store.DataStoreTestBase;
 import org.junit.ClassRule;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.testcontainers.containers.GenericContainer;
 
+import static org.apache.gora.examples.WebPageDataCreator.URLS;
+
 /**
  * Test case for AerospikeStore.
  */
@@ -85,11 +90,14 @@ public class TestAerospikeStore extends DataStoreTestBase {
   }
 
   @Test
-  @Ignore("Functionality is to be implemented in the next iteration")
   @Override
   public void testQuery() throws Exception {
-    //done
-    //ToDo: clear the data before executing
+    // Clearing the test data in the database
+    Query<String, WebPage> query;
+    WebPageDataCreator.createWebPageData(webPageStore);
+    query = webPageStore.newQuery();
+    webPageStore.deleteByQuery(query);
+
     super.testQuery();
   }
 
@@ -115,9 +123,14 @@ public class TestAerospikeStore extends DataStoreTestBase {
   }
 
   @Test
-  @Ignore("Functionality is to be implemented in the next iteration as this incurs query
execution")
   @Override
   public void testDelete() throws Exception {
+    // Clearing the test data in the database
+    Query<String, WebPage> query;
+    WebPageDataCreator.createWebPageData(webPageStore);
+    query = webPageStore.newQuery();
+    webPageStore.deleteByQuery(query);
+
     super.testDelete();
   }
 


Mime
View raw message