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 2014/11/11 00:21:51 UTC

[26/42] incubator-usergrid git commit: Pass new entity from batchCreate() to addToCollections().

Pass new entity from batchCreate() to addToCollections().


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

Branch: refs/heads/es-type-updates
Commit: 02c9f42151ddf68d84974a1344f36e97dfcf5773
Parents: 5285f3d
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Nov 7 08:32:47 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Nov 7 08:32:47 2014 -0500

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  5 +-
 .../corepersistence/CpRelationManager.java      | 52 ++++++++------------
 2 files changed, 24 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c9f421/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index daa046c..ae88641 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -2656,6 +2656,8 @@ public class CpEntityManager implements EntityManager {
 
             logger.debug("Wrote {}:{} version {}", new Object[] { 
                 cpEntity.getId().getType(), cpEntity.getId().getUuid(), cpEntity.getVersion() });
+
+            entityCache.put( new EntityScope( collectionScope, cpEntity.getId() ), cpEntity);
         }
         catch ( WriteUniqueVerifyException wuve ) {
             handleWriteUniqueVerifyException( entity, wuve );
@@ -2685,7 +2687,8 @@ public class CpEntityManager implements EntityManager {
         if ( !is_application ) {
 
             String collectionName = Schema.defaultCollectionName( eType );
-            getRelationManager( getApplication() ).addToCollection( collectionName, entity );
+            CpRelationManager cpr = (CpRelationManager)getRelationManager( getApplication() ); 
+            cpr.addToCollection( collectionName, entity, cpEntity, false );
 
             // Invoke counters
             incrementEntityCollection( collectionName, timestamp );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/02c9f421/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 1e8dcc3..a47ce8c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -601,7 +601,25 @@ public class CpRelationManager implements RelationManager {
     }
 
 
-    public Entity addToCollection( String collName, EntityRef itemRef, boolean connectBack ) throws Exception {
+    public Entity addToCollection( String collName, EntityRef itemRef, boolean connectBack ) 
+            throws Exception {
+
+        CollectionScope memberScope = new CollectionScopeImpl( 
+            applicationScope.getApplication(),
+            applicationScope.getApplication(),
+            CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
+
+        Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() ); 
+        org.apache.usergrid.persistence.model.entity.Entity memberEntity = 
+            ((CpEntityManager)em).load( new CpEntityManager.EntityScope( memberScope, entityId));
+
+        return addToCollection(collName, itemRef, memberEntity, connectBack);
+    }
+
+
+    public Entity addToCollection( String collName, EntityRef itemRef,
+            org.apache.usergrid.persistence.model.entity.Entity memberEntity, boolean connectBack ) 
+        throws Exception {
 
         // don't fetch entity if we've already got one
         final Entity itemEntity;
@@ -621,36 +639,6 @@ public class CpRelationManager implements RelationManager {
             return null;
         }
 
-        // load the new member entity to be added to the collection from its default scope
-        CollectionScope memberScope = new CollectionScopeImpl( 
-                applicationScope.getApplication(),
-                applicationScope.getApplication(),
-                CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
-        EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager( memberScope );
-
-        //TODO, this double load should disappear once events are in
-        Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() ); 
-        org.apache.usergrid.persistence.model.entity.Entity memberEntity = 
-            ((CpEntityManager)em).load( new CpEntityManager.EntityScope( memberScope, entityId));
-
-        if ( memberEntity == null ) {
-            throw new RuntimeException(
-                    "Unable to load entity uuid=" + itemRef.getUuid() + " type=" + itemRef.getType() );
-        }
-
-        if ( logger.isDebugEnabled() ) {
-            logger.debug( "Loaded member entity {}:{} from scope\n   app {}\n   " 
-                + "owner {}\n   name {} data {}",
-                new Object[] {
-                    itemRef.getType(),
-                    itemRef.getUuid(),
-                    memberScope.getApplication(),
-                    memberScope.getOwner(),
-                    memberScope.getName(),
-                    CpEntityMapUtils.toMap( memberEntity )
-                } );
-        }
-
         String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collName );
 
         UUID timeStampUuid = memberEntity.getId().getUuid() != null 
@@ -688,7 +676,7 @@ public class CpRelationManager implements RelationManager {
 
         if ( connectBack && collection != null && collection.getLinkedCollection() != null ) {
             getRelationManager( itemEntity ).addToCollection( 
-                    collection.getLinkedCollection(), headEntity, false );
+                    collection.getLinkedCollection(), headEntity, cpHeadEntity, false );
         }
 
         return itemEntity;