You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/06/16 18:11:46 UTC

[07/10] incubator-usergrid git commit: handle nulls

handle nulls


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9c89f2cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9c89f2cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9c89f2cb

Branch: refs/heads/two-dot-o-dev
Commit: 9c89f2cb8337b9d2cca56ee57e281c7ca6806443
Parents: 8138325
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Jun 15 17:15:42 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Jun 15 17:15:42 2015 -0600

----------------------------------------------------------------------
 .../cache/CachedEntityCollectionManager.java    |  1 +
 .../mvcc/entity/impl/MvccEntityImpl.java        |  2 +-
 .../MvccEntitySerializationStrategyV3Impl.java  | 25 ++++++++------------
 .../persistence/model/entity/EntityMap.java     |  3 ++-
 4 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9c89f2cb/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
index 7a04b8d..cb050c8 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
@@ -57,6 +57,7 @@ public class CachedEntityCollectionManager implements EntityCollectionManager {
     private Action1<Entity> cacheAdd = new Action1<Entity>() {
         @Override
         public void call( final Entity entity ) {
+
             entityCache.put( entity.getId(), entity );
         }
     };

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9c89f2cb/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
index 399d4f6..14889bd 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
@@ -45,7 +45,7 @@ public class MvccEntityImpl implements MvccEntity {
     }
 
 
-    public MvccEntityImpl( 
+    public MvccEntityImpl(
             final Id entityId, final UUID version, final Status status, final Optional<Entity> entity ) {
         Preconditions.checkNotNull( entityId, "entity id is required" );
         Preconditions.checkNotNull( version, "version id is required" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9c89f2cb/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
index f867cc4..52d2cbb 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
@@ -107,8 +107,9 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
         final Id entityId = entity.getId();
         final UUID version = entity.getVersion();
 
+        EntityMap map = entity.getEntity().isPresent() ?   EntityMap.fromEntity(entity.getEntity().get()) : null;
         return doWrite( applicationScope, entityId, version, colMutation -> colMutation.putColumn( COL_VALUE,
-                entitySerializer.toByteBuffer( new EntityWrapper( entity.getStatus(), entity.getVersion(), EntityMap.fromEntity( entity.getEntity() ),VERSION ) ) ) );
+                entitySerializer.toByteBuffer( new EntityWrapper( entity.getStatus(), entity.getVersion(),map,VERSION ) ) ) );
     }
 
 
@@ -182,7 +183,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
 
                     try {
                         return keyspace.prepareQuery( CF_ENTITY_DATA ).getKeySlice( rowKeys )
-                                       .withColumnSlice( COL_VALUE ).execute().getResult();
+                            .withColumnSlice( COL_VALUE ).execute().getResult();
                     }
                     catch ( ConnectionException e ) {
                         throw new CollectionRuntimeException( null, applicationScope,
@@ -384,13 +385,6 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
         public void setSerailizationVersion(int serailizationVersion) {
             this.serailizationVersion = serailizationVersion;
         }
-
-        @JsonIgnore
-        public Optional<Entity> getOptionalEntity() {
-            return this.getEntity() != null
-                ? Optional.of(Entity.fromMap(this.getEntity()))
-                : Optional.<Entity>absent();
-        }
     }
 
 
@@ -426,11 +420,12 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 //TODO fix this
                 return new MvccEntityImpl( id, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, Optional.<Entity>absent() );
             }
-
-            Optional<Entity> entity = deSerialized.getOptionalEntity();
+            EntityMap entityMap =  deSerialized.getEntity();
+            Optional<Entity> entity = Optional.absent();
             //Inject the id into it.
-            if ( entity.isPresent() ) {
-                EntityUtils.setId( entity.get(), id );
+            if ( entityMap!=null ) {
+                entity = Optional.of( Entity.fromMap(entityMap));
+                EntityUtils.setId(entity.get() , id );
             }
 
             return new MvccEntityImpl( id, deSerialized.getVersion(), deSerialized.getStatus(), entity );
@@ -473,7 +468,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
             wrapper.setSerailizationVersion(VERSION);
 
             //mark this version as empty
-            if ( !wrapper.getOptionalEntity().isPresent() ) {
+            if ( wrapper.getEntity() == null ) {
                 //we're empty
                 try {
                     return ByteBuffer.wrap(MAPPER.writeValueAsBytes(wrapper));
@@ -532,7 +527,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 }
 
                 // it's been deleted, remove it
-                if (!entityWrapper.getOptionalEntity().isPresent()) {
+                if ( entityWrapper.getEntity() == null) {
                     return new EntityWrapper( MvccEntity.Status.DELETED, entityWrapper.getVersion(), null,VERSION );
                 }
             }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9c89f2cb/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityMap.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityMap.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityMap.java
index c818de8..f65ce0b 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityMap.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityMap.java
@@ -57,7 +57,8 @@ public class EntityMap extends HashMap<String,Object> {
 
     public static EntityMap fromEntity(com.google.common.base.Optional<Entity> entity) {
         if(entity.isPresent()){
-            return fromEntity(entity.get());
+            EntityMap map =  fromEntity(entity.get());
+            return map;
         }else{
             return null;
         }