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

[1/2] incubator-usergrid git commit: remove clear field for one case

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-751 9c89f2cb8 -> f0cc1b2b4


remove clear field for one case


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

Branch: refs/heads/USERGRID-751
Commit: d46884696cd7a7b32588abc5cafa0bfd61081824
Parents: 9c89f2c
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jun 16 06:56:06 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jun 16 06:56:06 2015 -0600

----------------------------------------------------------------------
 .../apache/usergrid/persistence/model/entity/EntityMap.java  | 2 ++
 .../persistence/model/entity/MapToEntityConverter.java       | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d4688469/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 f65ce0b..576987f 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
@@ -23,12 +23,14 @@ public class EntityMap extends HashMap<String,Object> {
         super();
     }
 
+    
     public EntityMap(Id id,UUID version){
         super();
         setId(id);
         setVersion( version );
     }
 
+
     @JsonIgnore
     public Id getId(){
         return containsKey(ID_KEY) ? new SimpleId((UUID)get(ID_KEY), (String)get(TYPE_KEY)):null;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d4688469/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
index a40023a..56e156f 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/MapToEntityConverter.java
@@ -20,7 +20,6 @@ public class MapToEntityConverter{
             EntityMap entityMap = (EntityMap) map;
             Id id = entityMap.getId();
             UUID version = entityMap.getVersion();
-            entityMap.clearFields();
             entity =  id!=null ? new Entity(id,version) : new Entity();
         }else{
             entity = new Entity();
@@ -33,6 +32,9 @@ public class MapToEntityConverter{
 
         for ( String fieldName : map.keySet() ) {
 
+            if(isReservedField(fieldName)){
+                continue;
+            }
             Object value = map.get(fieldName);
 
             if ( value instanceof String ) {
@@ -85,6 +87,10 @@ public class MapToEntityConverter{
         return entity;
     }
 
+    private boolean isReservedField(String fieldName) {
+        return fieldName.equals(EntityMap.ID_KEY) || fieldName.equals(EntityMap.TYPE_KEY)  || fieldName.equals(EntityMap.VERSION_KEY);
+    }
+
     private  ListField listToListField( String fieldName, List list ) {
 
         if (list.isEmpty()) {


[2/2] incubator-usergrid git commit: handle nulls

Posted by sf...@apache.org.
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/f0cc1b2b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/f0cc1b2b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/f0cc1b2b

Branch: refs/heads/USERGRID-751
Commit: f0cc1b2b46c228268b93cabfe966bb295fe51ef6
Parents: d468846
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jun 16 10:07:40 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jun 16 10:07:40 2015 -0600

----------------------------------------------------------------------
 .../MvccEntitySerializationStrategyV3Impl.java  | 164 +++++++++----------
 .../persistence/model/entity/Entity.java        |   2 +-
 2 files changed, 81 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f0cc1b2b/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 52d2cbb..c58598c 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,7 +107,7 @@ 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;
+        EntityMap map =  EntityMap.fromEntity(entity.getEntity());
         return doWrite( applicationScope, entityId, version, colMutation -> colMutation.putColumn( COL_VALUE,
                 entitySerializer.toByteBuffer( new EntityWrapper( entity.getStatus(), entity.getVersion(),map,VERSION ) ) ) );
     }
@@ -320,75 +320,6 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
 
 
     /**
-     * Simple callback to perform puts and deletes with a common row setup code
-     */
-    private static interface RowOp {
-
-        /**
-         * The operation to perform on the row
-         */
-        void doOp( ColumnListMutation<Boolean> colMutation );
-    }
-
-
-    /**
-     * Simple bean wrapper for state and entity
-     */
-    public static class EntityWrapper {
-        private MvccEntity.Status status;
-        private UUID version;
-        private EntityMap entity;
-        private int serailizationVersion;
-
-
-        public EntityWrapper( ) {
-        }
-        public EntityWrapper( final MvccEntity.Status status, final UUID version, final EntityMap entity, final int serailizationVersion ) {
-            this.setStatus(status);
-            this.setVersion( version);
-            this.setEntity(entity);
-            this.setSerailizationVersion(serailizationVersion);
-        }
-
-        @JsonSerialize()
-        public MvccEntity.Status getStatus() {
-            return status;
-        }
-
-        public void setStatus(MvccEntity.Status status) {
-            this.status = status;
-        }
-
-        @JsonSerialize()
-        public UUID getVersion() {
-            return version;
-        }
-
-        public void setVersion(UUID version){
-            this.version = version;
-        }
-
-        @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-        public EntityMap getEntity() {
-            return entity;
-        }
-
-        public void setEntity(EntityMap entity){
-            this.entity = entity;
-        }
-
-        @JsonSerialize()
-        public int getSerailizationVersion() {
-            return serailizationVersion;
-        }
-
-        public void setSerailizationVersion(int serailizationVersion) {
-            this.serailizationVersion = serailizationVersion;
-        }
-    }
-
-
-    /**
      * Converts raw columns the to MvccEntity representation
      */
     private static final class MvccColumnParser implements ColumnParser<Boolean, MvccEntity> {
@@ -410,6 +341,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
 
             try {
                 deSerialized = column.getValue( entityJsonSerializer );
+
             }
             catch ( DataCorruptionException e ) {
                 log.error(
@@ -420,19 +352,15 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 //TODO fix this
                 return new MvccEntityImpl( id, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, Optional.<Entity>absent() );
             }
-            EntityMap entityMap =  deSerialized.getEntity();
-            Optional<Entity> entity = Optional.absent();
+            Optional<Entity> entity = Optional.fromNullable(Entity.fromMap(deSerialized.getEntity()));
             //Inject the id into it.
-            if ( entityMap!=null ) {
-                entity = Optional.of( Entity.fromMap(entityMap));
+            if ( entity.isPresent() ) {
                 EntityUtils.setId(entity.get() , id );
             }
-
             return new MvccEntityImpl( id, deSerialized.getVersion(), deSerialized.getStatus(), entity );
         }
     }
 
-
     /**
      * We should only ever create this once, since this impl is a singleton
      */
@@ -447,9 +375,6 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
         private SerializationFig serializationFig;
 
 
-
-
-
         public EntitySerializer( final SerializationFig serializationFig ) {
             this.serializationFig = serializationFig;
 
@@ -477,7 +402,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 }
             }
 
-            //we have an entity
+            //we have an entity but status is not complete don't allow it
             if ( wrapper.getStatus() != MvccEntity.Status.COMPLETE ) {
                 throw new UnsupportedOperationException( "Only states " + MvccEntity.Status.DELETED + " and " + MvccEntity.Status.COMPLETE + " are supported" );
             }
@@ -526,10 +451,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                     throw new UnsupportedOperationException( "A version of type " + entityWrapper.getSerailizationVersion() + " is unsupported" );
                 }
 
-                // it's been deleted, remove it
-                if ( entityWrapper.getEntity() == null) {
-                    return new EntityWrapper( MvccEntity.Status.DELETED, entityWrapper.getVersion(), null,VERSION );
-                }
+
             }
             catch ( Exception e ) {
                 if( log.isDebugEnabled() ){
@@ -538,8 +460,82 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 throw new DataCorruptionException( "Unable to read entity data", e );
             }
 
+            // it's been deleted, remove it
+            if ( entityWrapper.getEntity() == null) {
+                return new EntityWrapper( MvccEntity.Status.DELETED, entityWrapper.getVersion(), null,VERSION );
+            }
+
+            entityWrapper.setStatus(MvccEntity.Status.COMPLETE);
+
             // it's partial by default
             return entityWrapper;
         }
     }
+
+    /**
+     * Simple bean wrapper for state and entity
+     */
+    public static class EntityWrapper {
+        private MvccEntity.Status status;
+        private UUID version;
+        private EntityMap entity;
+        private int serailizationVersion;
+
+
+        public EntityWrapper( ) {
+        }
+        public EntityWrapper( final MvccEntity.Status status, final UUID version, final EntityMap entity, final int serailizationVersion ) {
+            this.setStatus(status);
+            this.setVersion( version);
+            this.setEntity(entity);
+            this.setSerailizationVersion(serailizationVersion);
+        }
+
+        @JsonIgnore()
+        public MvccEntity.Status getStatus() {
+            return status;
+        }
+
+        public void setStatus(MvccEntity.Status status) {
+            this.status = status;
+        }
+
+        @JsonSerialize()
+        public UUID getVersion() {
+            return version;
+        }
+
+        public void setVersion(UUID version){
+            this.version = version;
+        }
+
+        @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+        public EntityMap getEntity() {
+            return entity;
+        }
+
+        public void setEntity(EntityMap entity){
+            this.entity = entity;
+        }
+
+        @JsonSerialize()
+        public int getSerailizationVersion() {
+            return serailizationVersion;
+        }
+
+        public void setSerailizationVersion(int serailizationVersion) {
+            this.serailizationVersion = serailizationVersion;
+        }
+    }
+
+    /**
+     * Simple callback to perform puts and deletes with a common row setup code
+     */
+    private static interface RowOp {
+
+        /**
+         * The operation to perform on the row
+         */
+        void doOp( ColumnListMutation<Boolean> colMutation );
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f0cc1b2b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
index ae8662f..cd75544 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
@@ -95,7 +95,7 @@ public class Entity extends EntityObject {
      * @param map
      */
     public static Entity fromMap(EntityMap map){
-        return mapToEntityConverter.fromMap(map,true);
+        return map != null ? mapToEntityConverter.fromMap(map,true) : null;
     }
 
     @JsonIgnore