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/11 01:34:45 UTC

[2/4] incubator-usergrid git commit: fix edge deletes

fix edge deletes


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

Branch: refs/heads/two-dot-o-dev
Commit: bb865eb61ace6b54a7475f2f6bc421c0f083ea04
Parents: 412254a
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Jun 10 17:32:57 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Jun 10 17:32:57 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 23 ++++++++++----------
 .../corepersistence/util/CpNamingUtils.java     | 12 ++++++++++
 2 files changed, 24 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb865eb6/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 9e2c0bf..ca98685 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
@@ -259,16 +259,15 @@ public class CpRelationManager implements RelationManager {
 
         Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
 
-        String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
 
         logger.debug( "isConnectionMember(): Checking for edge type {} from {}:{} to {}:{}", new Object[] {
-            edgeType, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid()
+            connectionType, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid()
         } );
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         Observable<Edge> edges = gm.loadEdgeVersions(
-            new SimpleSearchByEdge( new SimpleId( headEntity.getUuid(), headEntity.getType() ), edgeType, entityId,
-                Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ) );
+           CpNamingUtils.createEdgeFromConnectionType(new SimpleId(headEntity.getUuid(), headEntity.getType()), connectionType, entityId)
+        );
 
         return edges.toBlocking().firstOrDefault( null ) != null;
     }
@@ -280,16 +279,15 @@ public class CpRelationManager implements RelationManager {
 
         Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
 
-        String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collectionName );
 
         logger.debug( "isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}", new Object[] {
-            edgeType, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid()
+            collectionName, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid()
         } );
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         Observable<Edge> edges = gm.loadEdgeVersions(
-            new SimpleSearchByEdge( new SimpleId( headEntity.getUuid(), headEntity.getType() ), edgeType, entityId,
-                Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent() ) );
+            CpNamingUtils.createEdgeFromCollectionName(new SimpleId(headEntity.getUuid(), headEntity.getType()), collectionName, entityId)
+         );
 
         return edges.toBlocking().firstOrDefault( null ) != null;
     }
@@ -520,9 +518,12 @@ public class CpRelationManager implements RelationManager {
 
 
         //run our delete
-        final Edge collectionToItemEdge =
-            createCollectionEdge( cpHeadEntity.getId(), collectionName, memberEntity.getId() );
-        gm.markEdge( collectionToItemEdge ).toBlocking().last();
+        gm.loadEdgeVersions(
+               CpNamingUtils.createEdgeFromCollectionName(cpHeadEntity.getId(), collectionName, memberEntity.getId())
+            )
+            .flatMap(edge -> gm.markEdge(edge))
+            .flatMap(edge -> gm.deleteEdge(edge))
+            .toBlocking().lastOrDefault(null);
 
 
         /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bb865eb6/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index 24fdbab..41631b3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -161,6 +161,18 @@ public class CpNamingUtils {
         return new SearchEdgeImpl( edge.getTargetNode(), edge.getType(), SearchEdge.NodeType.SOURCE );
     }
 
+    public static SearchByEdge createEdgeFromCollectionName(Id source, String connectionName, Id target) {
+        final String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(connectionName);
+
+        return new SimpleSearchByEdge(source, edgeType, target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent());
+    }
+
+    public static SearchByEdge createEdgeFromConnectionType(Id source, String connectionType, Id target) {
+        final String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType(connectionType);
+
+        return new SimpleSearchByEdge(source, edgeType, target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent());
+    }
+
 
     /**
      * TODO move sourceId to ApplicationScope