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 21:19:04 UTC
[1/2] incubator-usergrid git commit: remove default map properties
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o-dev 918d7cd52 -> ee3a1da56
remove default map properties
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/25f2e7e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/25f2e7e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/25f2e7e0
Branch: refs/heads/two-dot-o-dev
Commit: 25f2e7e0544ba8b2f4ac6e84e3f5727c68c3e922
Parents: 918d7cd
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jun 16 11:37:33 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jun 16 11:37:33 2015 -0600
----------------------------------------------------------------------
.../MvccEntitySerializationStrategyV3Impl.java | 60 ++++++++++---------
.../MvccEntitySerializationStrategyV2Test.java | 5 ++
.../persistence/model/entity/EntityMap.java | 62 ++++----------------
.../model/entity/EntityToMapConverter.java | 11 +---
.../model/entity/MapToEntityConverter.java | 17 +-----
.../index/impl/EntityToMapConverter.java | 6 --
6 files changed, 53 insertions(+), 108 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25f2e7e0/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 91a6457..1ebe59b 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,9 +107,9 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
final Id entityId = entity.getId();
final UUID version = entity.getVersion();
- EntityMap map = EntityMap.fromEntity(entity.getEntity());
+ Optional<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 ) ) ) );
+ entitySerializer.toByteBuffer( new EntityWrapper(entityId,entity.getVersion(), entity.getStatus(), VERSION, map.isPresent() ? map.get() : null ) ) ) );
}
@@ -264,7 +264,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
return doWrite( applicationScope, entityId, version, colMutation -> colMutation.putColumn( COL_VALUE, entitySerializer.toByteBuffer(
- new EntityWrapper( MvccEntity.Status.COMPLETE, version, null,VERSION ) ) ) );
+ new EntityWrapper(entityId, version, MvccEntity.Status.COMPLETE,VERSION, null ) ) ) );
}
@@ -341,7 +341,6 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
try {
deSerialized = column.getValue( entityJsonSerializer );
-
}
catch ( DataCorruptionException e ) {
log.error(
@@ -352,11 +351,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
//TODO fix this
return new MvccEntityImpl( id, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, Optional.<Entity>absent() );
}
- Optional<Entity> entity = Optional.fromNullable(Entity.fromMap(deSerialized.getEntity()));
- //Inject the id into it.
- if ( entity.isPresent() ) {
- EntityUtils.setId(entity.get() , id );
- }
+ Optional<Entity> entity = deSerialized.getOptionalEntity() ;
return new MvccEntityImpl( id, deSerialized.getVersion(), deSerialized.getStatus(), entity );
}
}
@@ -393,7 +388,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
wrapper.setSerailizationVersion(VERSION);
//mark this version as empty
- if ( wrapper.getEntity() == null ) {
+ if ( wrapper.getEntityMap() == null ) {
//we're empty
try {
return ByteBuffer.wrap(MAPPER.writeValueAsBytes(wrapper));
@@ -417,7 +412,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
final int maxEntrySize = serializationFig.getMaxEntitySize();
if (wrapperBytes.length > maxEntrySize) {
- throw new EntityTooLargeException(Entity.fromMap(wrapper.getEntity()), maxEntrySize, wrapperBytes.length,
+ throw new EntityTooLargeException(Entity.fromMap(wrapper.getEntityMap()), maxEntrySize, wrapperBytes.length,
"Your entity cannot exceed " + maxEntrySize + " bytes. The entity you tried to save was "
+ wrapperBytes.length + " bytes");
}
@@ -451,7 +446,6 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
throw new UnsupportedOperationException( "A version of type " + entityWrapper.getSerailizationVersion() + " is unsupported" );
}
-
}
catch ( Exception e ) {
if( log.isDebugEnabled() ){
@@ -461,8 +455,8 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
}
// it's been deleted, remove it
- if ( entityWrapper.getEntity() == null) {
- return new EntityWrapper( MvccEntity.Status.DELETED, entityWrapper.getVersion(), null,VERSION );
+ if ( entityWrapper.getEntityMap() == null) {
+ return new EntityWrapper( entityWrapper.getId(), entityWrapper.getVersion(),MvccEntity.Status.DELETED, VERSION,null );
}
entityWrapper.setStatus(MvccEntity.Status.COMPLETE);
@@ -476,18 +470,20 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
* Simple bean wrapper for state and entity
*/
public static class EntityWrapper {
+ private Id id;
private MvccEntity.Status status;
private UUID version;
- private EntityMap entity;
+ private EntityMap entityMap;
private int serailizationVersion;
public EntityWrapper( ) {
}
- public EntityWrapper( final MvccEntity.Status status, final UUID version, final EntityMap entity, final int serailizationVersion ) {
+ public EntityWrapper( final Id id , final UUID version, final MvccEntity.Status status, final int serailizationVersion, final EntityMap entity ) {
this.setStatus(status);
- this.setVersion( version);
- this.setEntity(entity);
+ this.version= version;
+ this.entityMap = entity;
+ this.id = id;
this.setSerailizationVersion(serailizationVersion);
}
@@ -505,21 +501,19 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
}
@JsonSerialize()
+ public Id getId() {
+ return id;
+ }
+
+ @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;
+ public EntityMap getEntityMap() {
+ return entityMap;
}
@JsonSerialize()
@@ -530,6 +524,18 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
public void setSerailizationVersion(int serailizationVersion) {
this.serailizationVersion = serailizationVersion;
}
+
+ @JsonIgnore
+ public Optional<Entity> getOptionalEntity() {
+ Optional<Entity> entityReturn = Optional.fromNullable(Entity.fromMap(getEntityMap()));
+ //Inject the id into it.
+ if (entityReturn.isPresent()) {
+ EntityUtils.setId(entityReturn.get(), getId());
+ EntityUtils.setVersion(entityReturn.get(), getVersion());
+ }
+ ;
+ return entityReturn;
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25f2e7e0/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Test.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Test.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Test.java
index 1ed1668..f8b65d9 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Test.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV2Test.java
@@ -25,6 +25,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import org.apache.usergrid.persistence.model.util.EntityUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -100,6 +101,8 @@ public abstract class MvccEntitySerializationStrategyV2Test extends MvccEntitySe
final Id id = entity.getId();
ValidationUtils.verifyIdentity( id );
final UUID version = UUIDGenerator.newTimeUUID();
+ EntityUtils.setVersion(entity,version);
+
final MvccEntity.Status status = MvccEntity.Status.COMPLETE;
final MvccEntity mvccEntity = new MvccEntityImpl( id, version, status, entity );
@@ -187,6 +190,8 @@ public abstract class MvccEntitySerializationStrategyV2Test extends MvccEntitySe
final Id id = entity.getId();
ValidationUtils.verifyIdentity( id );
final UUID version = UUIDGenerator.newTimeUUID();
+ EntityUtils.setVersion(entity,version);
+
final MvccEntity.Status status = MvccEntity.Status.COMPLETE;
final MvccEntity mvccEntity = new MvccEntityImpl( id, version, status, entity );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25f2e7e0/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 576987f..84b6d35 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
@@ -7,86 +7,48 @@ import org.apache.usergrid.persistence.model.field.*;
import org.apache.usergrid.persistence.model.field.value.EntityObject;
import java.io.IOException;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
/**
* Core persistence Entity Map structure to persist to
*/
public class EntityMap extends HashMap<String,Object> {
private static EntityToMapConverter entityToMapConverter = new EntityToMapConverter();
- public static final String VERSION_KEY = "__VERSION__";
- public static final String ID_KEY = "__ID__";
- public static final String TYPE_KEY = "__TYPE__";
- public EntityMap(){
- super();
- }
-
- public EntityMap(Id id,UUID version){
+ public EntityMap(){
super();
- setId(id);
- setVersion( version );
}
- @JsonIgnore
- public Id getId(){
- return containsKey(ID_KEY) ? new SimpleId((UUID)get(ID_KEY), (String)get(TYPE_KEY)):null;
- }
-
- @JsonIgnore
- public void setId(Id id){
- if(id!=null) {
- put(ID_KEY, id.getUuid());
- put(TYPE_KEY, id.getType());
- }
-
- }
-
- @JsonIgnore
- public UUID getVersion(){
- return containsKey(VERSION_KEY) ? (UUID) get(VERSION_KEY):null;
- }
-
- @JsonIgnore
- public void setVersion(UUID version){
- if(version!=null) {
- put(VERSION_KEY, version);
- }
- }
-
- public static EntityMap fromEntity(com.google.common.base.Optional<Entity> entity) {
+ public static Optional<EntityMap> fromEntity(Optional<Entity> entity) {
if(entity.isPresent()){
EntityMap map = fromEntity(entity.get());
- return map;
+ return Optional.fromNullable(map);
}else{
- return null;
+ return Optional.absent();
}
}
public static EntityMap fromEntity(Entity entity) {
- return entityToMapConverter.toMap(entity);
+ EntityMap map = entityToMapConverter.toMap(entity);
+ return map;
}
-
/**
* Return true if the value is a location field
* @param fieldValue
* @return
*/
- public static boolean isLocationField(Map<String, ?> fieldValue){
- if(fieldValue.size() != 2){
+ public static boolean isLocationField(Map<String, ?> fieldValue) {
+ if (fieldValue.size() != 2) {
return false;
}
- return fieldValue.containsKey( EntityToMapConverter.LAT ) && fieldValue.containsKey( EntityToMapConverter.LON );
+ return fieldValue.containsKey(EntityToMapConverter.LAT) && fieldValue.containsKey(EntityToMapConverter.LON);
}
- public void clearFields() {
- this.remove(ID_KEY);
- this.remove(TYPE_KEY);
- this.remove(VERSION_KEY);
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25f2e7e0/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
index 16915e2..c7bd90b 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/EntityToMapConverter.java
@@ -58,15 +58,8 @@ public class EntityToMapConverter {
*/
public EntityMap toMap( EntityObject entityObject ) {
- EntityMap map = null;
- if ( entityObject instanceof Entity ) {
- Entity entity = ( Entity ) entityObject;
- map = new EntityMap( entity.getId(), entity.getVersion() );
- }
- else {
- map = new EntityMap();
- }
- return toMap( entityObject, map );
+ EntityMap map = new EntityMap();
+ return toMap(entityObject, map);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25f2e7e0/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 56e156f..6bd6cb6 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
@@ -15,16 +15,7 @@ public class MapToEntityConverter{
public Entity fromMap( Map<String, Object> map, boolean topLevel ) {
- Entity entity ;
- if(map instanceof EntityMap){
- EntityMap entityMap = (EntityMap) map;
- Id id = entityMap.getId();
- UUID version = entityMap.getVersion();
- entity = id!=null ? new Entity(id,version) : new Entity();
- }else{
- entity = new Entity();
- }
-
+ Entity entity = new Entity();
return fromMap( entity, map, topLevel );
}
@@ -32,9 +23,6 @@ public class MapToEntityConverter{
for ( String fieldName : map.keySet() ) {
- if(isReservedField(fieldName)){
- continue;
- }
Object value = map.get(fieldName);
if ( value instanceof String ) {
@@ -87,9 +75,6 @@ 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 ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/25f2e7e0/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
index cced80f..567068c 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
@@ -73,7 +73,6 @@ public class EntityToMapConverter {
outputEntity.put( ENTITY_TYPE_FIELDNAME, getType( applicationScope, entityId ) );
-
outputEntity.put( APPLICATION_ID_FIELDNAME, applicationId( applicationScope.getApplication() ) );
outputEntity.put( EDGE_NODE_ID_FIELDNAME, nodeId( indexEdge.getNodeId() ) );
@@ -84,18 +83,13 @@ public class EntityToMapConverter {
outputEntity.put( EDGE_TIMESTAMP_FIELDNAME, indexEdge.getTimestamp() );
-
//add the context for filtering later
outputEntity.put( EDGE_SEARCH_FIELDNAME, IndexingUtils.createContextName( applicationScope, indexEdge ) );
-
-
//migrate the entity to map since we're ultimately going to use maps once we get rid of the Field objects
final EntityMap entityMap = EntityMap.fromEntity( entity );
- entityMap.clearFields();
//now visit our entity
-
final FieldParser parser = new EntityMappingParser();
final List<EntityField> fieldsToIndex = parser.parse( entityMap );
[2/2] incubator-usergrid git commit: change to deleted
Posted by sf...@apache.org.
change to deleted
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/ee3a1da5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/ee3a1da5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/ee3a1da5
Branch: refs/heads/two-dot-o-dev
Commit: ee3a1da564cf0986f9d3cc98125c6b21a99511e2
Parents: 25f2e7e
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jun 16 11:48:51 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jun 16 11:48:51 2015 -0600
----------------------------------------------------------------------
.../impl/MvccEntitySerializationStrategyV3Impl.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ee3a1da5/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 1ebe59b..766dc74 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
@@ -258,13 +258,16 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
@Override
public MutationBatch mark( final ApplicationScope applicationScope, final Id entityId, final UUID version ) {
- Preconditions.checkNotNull( applicationScope, "applicationScope is required" );
- Preconditions.checkNotNull( entityId, "entity id is required" );
- Preconditions.checkNotNull( version, "version is required" );
+ Preconditions.checkNotNull(applicationScope, "applicationScope is required");
+ Preconditions.checkNotNull(entityId, "entity id is required");
+ Preconditions.checkNotNull(version, "version is required");
- return doWrite( applicationScope, entityId, version, colMutation -> colMutation.putColumn( COL_VALUE, entitySerializer.toByteBuffer(
- new EntityWrapper(entityId, version, MvccEntity.Status.COMPLETE,VERSION, null ) ) ) );
+ return doWrite(applicationScope, entityId, version, colMutation ->
+ colMutation.putColumn(COL_VALUE,
+ entitySerializer.toByteBuffer(new EntityWrapper(entityId, version, MvccEntity.Status.DELETED, VERSION, null))
+ )
+ );
}