gora-commits mailing list archives

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


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

Branch: refs/heads/master
Commit: b61eeaf0529f070ba19db904821b517a9e5528dc
Parents: c72f418
Author: nishadi <ndimeshi@gmail.com>
Authored: Mon Jun 26 19:07:07 2017 +0530
Committer: nishadi <ndimeshi@gmail.com>
Committed: Mon Jun 26 19:07:07 2017 +0530

----------------------------------------------------------------------
 .../gora/aerospike/store/AerospikeStore.java    | 49 ++++++++++++--------
 .../aerospike/store/TestAerospikeStore.java     |  2 +-
 2 files changed, 31 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/b61eeaf0/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 5a880d6..66de783 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
@@ -143,16 +143,9 @@ public class AerospikeStore<K, T extends PersistentBase> extends
DataStoreBase<K
   @Override
   public T get(K key, String[] fields) {
 
-    Value keyValue;
-    if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
-      keyValue = Value.get(key.toString());
-    } else {
-      keyValue = Value.get(key);
-    }
-
+    Key recordKey = getAerospikeKey(key);
     fields = getFieldsToQuery(fields);
-    Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
-            aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
+
     Record record = aerospikeClient
             .get(aerospikeParameters.getAerospikeMapping().getReadPolicy(), recordKey, fields);
     if (record == null) {
@@ -172,15 +165,7 @@ public class AerospikeStore<K, T extends PersistentBase> extends
DataStoreBase<K
   @Override
   public void put(K key, T persistent) {
 
-    Value keyValue;
-    if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
-      keyValue = Value.get(key.toString());
-    } else {
-      keyValue = Value.get(key);
-    }
-
-    Key recordKey = new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
-            aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
+    Key recordKey = getAerospikeKey(key);
 
     List<Field> fields = persistent.getSchema().getFields();
     for (int i = 0; i < fields.size(); i++) {
@@ -204,9 +189,17 @@ public class AerospikeStore<K, T extends PersistentBase> extends
DataStoreBase<K
     }
   }
 
+  /**
+   * {@inheritDoc}
+   *
+   * @param key the key of the object
+   * @return whether the object was successfully deleted
+   */
   @Override
   public boolean delete(K key) {
-    return true;
+    Key recordKey = getAerospikeKey(key);
+    return aerospikeClient
+            .delete(aerospikeParameters.getAerospikeMapping().getWritePolicy(), recordKey);
   }
 
   @Override
@@ -243,6 +236,24 @@ public class AerospikeStore<K, T extends PersistentBase> extends
DataStoreBase<K
   }
 
   /**
+   * Method to get the aerospike key from the provided K
+   *
+   * @param key persistent key
+   * @return aerospike key for the record
+   */
+  public Key getAerospikeKey(K key) {
+    Value keyValue;
+    if (keyClass.getSimpleName().equalsIgnoreCase("string")) {
+      keyValue = Value.get(key.toString());
+    } else {
+      keyValue = Value.get(key);
+    }
+
+    return new Key(aerospikeParameters.getAerospikeMapping().getNamespace(),
+            aerospikeParameters.getAerospikeMapping().getSet(), keyValue);
+  }
+
+  /**
    * Method to get the value serializable in database from the Avro persistent object
    *
    * @param object persistent object

http://git-wip-us.apache.org/repos/asf/gora/blob/b61eeaf0/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 8b63414..9e93fb0 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
@@ -134,7 +134,7 @@ public class TestAerospikeStore extends DataStoreTestBase {
   }
 
   @Test
-  @Ignore("To be implemented")
+  @Ignore("Functionality is to be implemented in the next iteration as this incurs query
execution")
   @Override
   public void testDelete() throws Exception {
     super.testDelete();


Mime
View raw message