gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [1/6] gora git commit: GORA_447 NPE Fix
Date Thu, 26 May 2016 06:47:59 GMT
Repository: gora
Updated Branches:
  refs/heads/master c0c8c6135 -> 22f400d53


GORA_447 NPE Fix


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

Branch: refs/heads/master
Commit: b7fb9eea768a6daac93d1835726c737153f45ef4
Parents: 96e623b
Author: Kevin Ratnasekera <djkevincr@yahoo.com>
Authored: Mon Apr 25 18:51:58 2016 +0530
Committer: Kevin Ratnasekera <djkevincr@yahoo.com>
Committed: Mon Apr 25 18:51:58 2016 +0530

----------------------------------------------------------------------
 .../org/apache/gora/memory/store/MemStore.java  | 23 +++++++++++++++-----
 .../org/apache/gora/persistency/Persistent.java |  7 ++++++
 .../gora/persistency/impl/PersistentBase.java   | 11 ++++++++++
 .../apache/gora/memory/store/MemStoreTest.java  | 15 ++++++++-----
 .../gora/dynamodb/example/generated/Person.java |  2 ++
 .../dynamodb/example/generated/Webpage.java     |  2 ++
 .../dynamodb/compiler/GoraDynamoDBCompiler.java |  2 ++
 7 files changed, 50 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/b7fb9eea/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java b/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
index 81dc3b9..481b2a7 100644
--- a/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
+++ b/gora-core/src/main/java/org/apache/gora/memory/store/MemStore.java
@@ -106,13 +106,24 @@ public class MemStore<K, T extends PersistentBase> extends DataStoreBase<K,
T> {
 
   @Override
   public long deleteByQuery(Query<K, T> query) {
-    try{
+    try {
       long deletedRows = 0;
-      Result<K,T> result = query.execute();
-
-      while(result.next()) {
-        if(delete(result.getKey()))
-          deletedRows++;
+      Result<K, T> result = query.execute();
+
+      String[] fields = getFieldsToQuery(query.getFields());
+      boolean isAllFields = Arrays.equals(fields, getFields());
+
+      while (result.next()) {
+        if (isAllFields) {
+          if (delete(result.getKey())) {
+            deletedRows++;
+            continue;
+          }
+        }
+        for (String field : fields) {
+          result.get().clearField(field);
+        }
+        deletedRows++;
       }
       return deletedRows;
     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/gora/blob/b7fb9eea/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java b/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
index bd520a9..9d4b601 100644
--- a/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
+++ b/gora-core/src/main/java/org/apache/gora/persistency/Persistent.java
@@ -36,6 +36,13 @@ public interface Persistent extends Dirtyable {
   void clear();
 
   /**
+* Clears the inner state of the object based on field without any modification to the actual
+* data on the data store. This method should be called before re-using the existing fields
on
+* object to hold the data for another result.
+*/
+  void clearField(String Field);
+
+  /**
 * Returns whether the field has been modified.
 *
 * @param fieldIndex

http://git-wip-us.apache.org/repos/asf/gora/blob/b7fb9eea/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
----------------------------------------------------------------------
diff --git a/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
b/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
index 56c4816..d436d56 100644
--- a/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
+++ b/gora-core/src/main/java/org/apache/gora/persistency/impl/PersistentBase.java
@@ -197,6 +197,17 @@ public abstract class PersistentBase extends SpecificRecordBase implements
   }
 
   @Override
+  public void clearField(String field) {
+    Collection<Field> unmanagedFields = getUnmanagedFields();
+    Field specificField = getSchema().getField(field);
+    if (unmanagedFields.contains(specificField)) {
+      put(specificField.pos(), PersistentData.get().deepCopy(specificField.schema(),
+              PersistentData.get().getDefaultValue(specificField)));
+    }
+    clearDirynessIfFieldIsDirtyable(specificField.pos());
+  }
+
+  @Override
   public boolean equals(Object that) {
     if (that == this) {
       return true;

http://git-wip-us.apache.org/repos/asf/gora/blob/b7fb9eea/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java
----------------------------------------------------------------------
diff --git a/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java b/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java
index 0c56d8e..49db17a 100644
--- a/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java
+++ b/gora-core/src/test/java/org/apache/gora/memory/store/MemStoreTest.java
@@ -22,6 +22,8 @@ import java.io.IOException;
 import org.apache.gora.examples.WebPageDataCreator;
 import org.apache.gora.examples.generated.Employee;
 import org.apache.gora.examples.generated.WebPage;
+import org.apache.gora.persistency.BeanFactory;
+import org.apache.gora.persistency.impl.BeanFactoryImpl;
 import org.apache.gora.query.Query;
 import org.apache.gora.store.DataStore;
 import org.apache.gora.store.DataStoreFactory;
@@ -69,7 +71,7 @@ public class MemStoreTest extends DataStoreTestBase {
   @SuppressWarnings("unchecked")
   @Override
   protected DataStore<String, WebPage> createWebPageDataStore() throws IOException
{
-    return DataStoreFactory.getDataStore(MemStore.class, String.class, Employee.class, conf);
+    return DataStoreFactory.getDataStore(MemStore.class, String.class, WebPage.class, conf);
   }
 
   @Test
@@ -110,11 +112,12 @@ public class MemStoreTest extends DataStoreTestBase {
   @Test
   public void testGetWithFields() {}
 
-  @Ignore("GORA-447")
   @Test
   public void testMemStoreDeleteByQueryFields() throws Exception {
 
     DataStore<String, WebPage> store = new MemStore<>();
+    BeanFactory<String, WebPage> beanFactory = new BeanFactoryImpl<>(String.class,
WebPage.class);
+    store.setBeanFactory(beanFactory);
     Query<String, WebPage> query;
 
     //test 5 - delete all with some fields
@@ -124,9 +127,9 @@ public class MemStoreTest extends DataStoreTestBase {
     query.setFields("outlinks", "parsedContent", "content");
     
     Query<String, WebPage> newQuery = store.newQuery();
-    newQuery.setStartKey(URLS[0]);
-    newQuery.setEndKey(URLS[9]);
-    //newQuery.setFields("outlinks", "parsedContent", "content");
+    newQuery.setStartKey(SORTED_URLS[0]);
+    newQuery.setEndKey(SORTED_URLS[9]);
+    newQuery.setFields("outlinks", "parsedContent", "content");
 
     DataStoreTestUtil.assertNumResults(newQuery, URLS.length);
     store.deleteByQuery(query);
@@ -178,7 +181,7 @@ public class MemStoreTest extends DataStoreTestBase {
     for (int i = 0; i < URLS.length; i++) {
       WebPage page = store.get(URLS[i]);
       assertNotNull(page);
-      if( URLS[i].compareTo(startKey) < 0 || URLS[i].compareTo(endKey) >= 0) {
+      if( URLS[i].compareTo(startKey) < 0 || URLS[i].compareTo(endKey) > 0) {
         //not deleted
         DataStoreTestUtil.assertWebPage(page, i);
       } else {

http://git-wip-us.apache.org/repos/asf/gora/blob/b7fb9eea/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Person.java
----------------------------------------------------------------------
diff --git a/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Person.java
b/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Person.java
index 471fb59..f9c3ca6 100644
--- a/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Person.java
+++ b/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Person.java
@@ -51,6 +51,8 @@ public class Person implements Persistent {
     @Override
     public void clear() { }
     @Override
+    public void clearField(String Field) { }
+    @Override
     public Person clone() { return null; }
     @Override
     public boolean isDirty() { return false; }

http://git-wip-us.apache.org/repos/asf/gora/blob/b7fb9eea/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Webpage.java
----------------------------------------------------------------------
diff --git a/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Webpage.java
b/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Webpage.java
index df9eb80..e3b6024 100644
--- a/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Webpage.java
+++ b/gora-dynamodb/src/examples/java/org/apache/gora/dynamodb/example/generated/Webpage.java
@@ -44,6 +44,8 @@ public class Webpage implements Persistent {
     @Override
     public void clear() { }
     @Override
+    public void clearField(String Field) { }
+    @Override
     public Webpage clone() { return null; }
     @Override
     public boolean isDirty() { return false; }

http://git-wip-us.apache.org/repos/asf/gora/blob/b7fb9eea/gora-dynamodb/src/main/java/org/apache/gora/dynamodb/compiler/GoraDynamoDBCompiler.java
----------------------------------------------------------------------
diff --git a/gora-dynamodb/src/main/java/org/apache/gora/dynamodb/compiler/GoraDynamoDBCompiler.java
b/gora-dynamodb/src/main/java/org/apache/gora/dynamodb/compiler/GoraDynamoDBCompiler.java
index be38e36..906773b 100644
--- a/gora-dynamodb/src/main/java/org/apache/gora/dynamodb/compiler/GoraDynamoDBCompiler.java
+++ b/gora-dynamodb/src/main/java/org/apache/gora/dynamodb/compiler/GoraDynamoDBCompiler.java
@@ -291,6 +291,8 @@ public class GoraDynamoDBCompiler {
     line(pIden, "@Override");
     line(pIden, "public void clear() { }");
     line(pIden, "@Override");
+    line(pIden, "public void clearField(String Field) { }");
+    line(pIden, "@Override");
     line(pIden, "public " + tabName + " clone() { return null; }");
     line(pIden, "@Override");
     line(pIden, "public boolean isDirty() { return false; }");


Mime
View raw message