gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [3/6] gora git commit: GORA-447 NPE fix removed Persistant API change
Date Thu, 26 May 2016 06:48:01 GMT
GORA-447 NPE fix removed Persistant API change


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

Branch: refs/heads/master
Commit: b0d69051961c797200ec92b37a1557f1be1c2c58
Parents: 570662b
Author: Kevin Ratnasekera <djkevincr@yahoo.com>
Authored: Thu Apr 28 19:45:38 2016 +0530
Committer: Kevin Ratnasekera <djkevincr@yahoo.com>
Committed: Thu Apr 28 19:45:38 2016 +0530

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


http://git-wip-us.apache.org/repos/asf/gora/blob/b0d69051/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 481b2a7..19e3bc0 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
@@ -19,11 +19,7 @@
 package org.apache.gora.memory.store;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NavigableMap;
+import java.util.*;
 import java.util.concurrent.ConcurrentNavigableMap;
 import java.util.concurrent.ConcurrentSkipListMap;
 
@@ -117,13 +113,20 @@ public class MemStore<K, T extends PersistentBase> extends DataStoreBase<K,
T> {
         if (isAllFields) {
           if (delete(result.getKey())) {
             deletedRows++;
-            continue;
+          }
+        } else {
+          ArrayList<String> excludedFields = new ArrayList<>();
+          for (String field : getFields()){
+            if (!Arrays.asList(fields).contains(field)){
+              excludedFields.add(field);
+            }
+          }
+          T newClonedObj = getPersistent(result.get(),excludedFields.toArray(new String[excludedFields.size()]));
+          if (delete(result.getKey())) {
+            put(result.getKey(),newClonedObj);
+            deletedRows++;
           }
         }
-        for (String field : fields) {
-          result.get().clearField(field);
-        }
-        deletedRows++;
       }
       return deletedRows;
     } catch (Exception e) {
@@ -190,7 +193,9 @@ public class MemStore<K, T extends PersistentBase> extends DataStoreBase<K,
T> {
       return obj;
     }
     T newObj = AvroUtils.deepClonePersistent(obj);
-    for (Field otherField : otherFields) {
+    newObj.clear();
+    for (String field : fields) {
+      Field otherField = obj.getSchema().getField(field);
       int index = otherField.pos();
       newObj.put(index, obj.get(index));
     }

http://git-wip-us.apache.org/repos/asf/gora/blob/b0d69051/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 9d4b601..bd520a9 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,13 +36,6 @@ 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/b0d69051/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 d436d56..56c4816 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,17 +197,6 @@ 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/b0d69051/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 49db17a..8e94662 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
@@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
 
 import static org.apache.gora.examples.WebPageDataCreator.SORTED_URLS;
 import static org.apache.gora.examples.WebPageDataCreator.URLS;
+import static org.apache.gora.examples.WebPageDataCreator.URL_INDEXES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -52,7 +53,7 @@ import static org.junit.Assume.assumeTrue;
 public class MemStoreTest extends DataStoreTestBase {
 
   private static final Logger LOG = LoggerFactory.getLogger(MemStoreTest.class);
-  
+
   private static final int NUM_KEYS = 4;
 
   private Configuration conf;
@@ -108,9 +109,26 @@ public class MemStoreTest extends DataStoreTestBase {
   @Test
   public void testDeleteByQueryFields() {}
 
-  @Ignore("GORA-447")
   @Test
-  public void testGetWithFields() {}
+  public void testGetWithFields() throws Exception {
+
+    DataStore<String, WebPage> store = new MemStore<>();
+    BeanFactory<String, WebPage> beanFactory = new BeanFactoryImpl<>(String.class,
WebPage.class);
+    store.setBeanFactory(beanFactory);
+    WebPageDataCreator.createWebPageData(store);
+    String[] interestFields = new String[2];
+    interestFields[0] = "url";
+    interestFields[1] = "content";
+    WebPage page = store.get(URLS[1], interestFields);
+    assertNotNull(page);
+    assertNotNull(page.getUrl());
+    assertEquals(page.getUrl().toString(), URLS[1]);
+    assertNotNull(page.getContent());
+    assertEquals("Map of Outlinks should have a size of '0' as it is omitted at retrieval",
+            0, page.getOutlinks().size());
+    assertEquals("Map of Parsed Content should have a size of '0' as it is omitted at retrieval",
+            0, page.getParsedContent().size());
+  }
 
   @Test
   public void testMemStoreDeleteByQueryFields() throws Exception {
@@ -125,7 +143,7 @@ public class MemStoreTest extends DataStoreTestBase {
 
     query = store.newQuery();
     query.setFields("outlinks", "parsedContent", "content");
-    
+
     Query<String, WebPage> newQuery = store.newQuery();
     newQuery.setStartKey(SORTED_URLS[0]);
     newQuery.setEndKey(SORTED_URLS[9]);

http://git-wip-us.apache.org/repos/asf/gora/blob/b0d69051/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 f9c3ca6..471fb59 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,8 +51,6 @@ 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/b0d69051/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 e3b6024..df9eb80 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,8 +44,6 @@ 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/b0d69051/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 906773b..be38e36 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,8 +291,6 @@ 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