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/10/30 04:39:46 UTC

[20/45] git commit: Restoring some semblance of my original formatting, take it easy with that auto-formatter folks!

Restoring some semblance of my original formatting, take it easy with that auto-formatter folks!


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

Branch: refs/heads/key-row-sharding
Commit: 3771e3f933f4d13963b16507389a750c08024c90
Parents: 960ce6b
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Oct 28 11:21:05 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Oct 28 11:21:05 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 889 ++++++++++++-------
 1 file changed, 555 insertions(+), 334 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3771e3f9/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 96f0e1e..8c0d886 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
@@ -189,8 +189,11 @@ public class CpRelationManager implements RelationManager {
     public CpRelationManager() {}
 
 
-    public CpRelationManager init( EntityManager em, CpEntityManagerFactory emf, UUID applicationId,
-                                   EntityRef headEntity, IndexBucketLocator indexBucketLocator ) {
+    public CpRelationManager init( EntityManager em,
+            CpEntityManagerFactory emf,
+            UUID applicationId,
+            EntityRef headEntity, 
+            IndexBucketLocator indexBucketLocator ) {
 
         Assert.notNull( em, "Entity manager cannot be null" );
         Assert.notNull( emf, "Entity manager factory cannot be null" );
@@ -212,21 +215,25 @@ public class CpRelationManager implements RelationManager {
         this.indexBucketLocator = indexBucketLocator; // TODO: this also
 
         // load the Core Persistence version of the head entity as well
-        this.headEntityScope =
-                new CollectionScopeImpl( this.applicationScope.getApplication(), this.applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
+        this.headEntityScope = new CollectionScopeImpl( 
+            this.applicationScope.getApplication(), 
+            this.applicationScope.getApplication(),
+            CpNamingUtils.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
 
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( headEntityScope );
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Loading head entity {}:{} from scope\n   app {}\n   owner {}\n   name {}", new Object[] {
-                            headEntity.getType(), headEntity.getUuid(), headEntityScope.getApplication(),
-                            headEntityScope.getOwner(), headEntityScope.getName()
-                    } );
+            logger.debug( "Loading head entity {}:{} from scope\n   app {}\n   owner {}\n   name {}",
+                new Object[] { headEntity.getType(),
+                    headEntity.getUuid(),
+                    headEntityScope.getApplication(),
+                    headEntityScope.getOwner(),
+                    headEntityScope.getName()
+                } );
         }
 
         //TODO PERFORMANCE why are we loading this again here?
-        this.cpHeadEntity = ecm.load( new SimpleId( headEntity.getUuid(), headEntity.getType() ) ).toBlocking()
-                               .lastOrDefault( null );
+        this.cpHeadEntity = ecm.load( new SimpleId( 
+                headEntity.getUuid(), headEntity.getType() ) ).toBlocking() .lastOrDefault( null );
 
         // commented out because it is possible that CP entity has not been created yet
         Assert.notNull( cpHeadEntity, "cpHeadEntity cannot be null" );
@@ -245,12 +252,14 @@ public class CpRelationManager implements RelationManager {
 
         String edgeTypePrefix = CpNamingUtils.getEdgeTypeFromCollectionName( collectionName );
 
-        logger.debug( "getCollectionIndexes(): Searching for edge type prefix {} to target {}:{}", new Object[] {
-                        edgeTypePrefix, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid()
-                } );
+        logger.debug( "getCollectionIndexes(): Searching for edge type prefix {} to target {}:{}",
+            new Object[] { edgeTypePrefix,
+                cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid() 
+            } ); 
 
-        Observable<String> types =
-                gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeTypePrefix, null ) );
+        Observable<String> types = gm.getEdgeTypesFromSource( 
+            new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeTypePrefix, null ) );
 
         Iterator<String> iter = types.toBlockingObservable().getIterator();
         while ( iter.hasNext() ) {
@@ -267,7 +276,8 @@ public class CpRelationManager implements RelationManager {
         //Map<EntityRef, Set<String>> containerEntities = getContainers(-1, "owns", null);
         Map<EntityRef, Set<String>> containerEntities = getContainers();
 
-        Map<String, Map<UUID, Set<String>>> owners = new LinkedHashMap<String, Map<UUID, Set<String>>>();
+        Map<String, Map<UUID, Set<String>>> owners = 
+                new LinkedHashMap<String, Map<UUID, Set<String>>>();
 
         for ( EntityRef owner : containerEntities.keySet() ) {
             Set<String> collections = containerEntities.get( owner );
@@ -298,35 +308,38 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Iterator<String> edgeTypes =
-                gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeType, null ) ).toBlocking()
-                  .getIterator();
+        Iterator<String> edgeTypes = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( 
+                cpHeadEntity.getId(), edgeType, null ) ).toBlocking() .getIterator();
 
-        logger.debug(
-                "getContainers(): " + "Searched for edges of type {}\n   to target {}:{}\n   in scope {}\n   found: {}",
-                new Object[] {
-                        edgeType, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid(),
-                        applicationScope.getApplication(), edgeTypes.hasNext()
-                } );
+        logger.debug( "getContainers(): "
+                + "Searched for edges of type {}\n   to target {}:{}\n   in scope {}\n   found: {}",
+            new Object[] { edgeType,
+                cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid(),
+                applicationScope.getApplication(),
+                edgeTypes.hasNext() 
+            } );
 
         while ( edgeTypes.hasNext() ) {
 
             String etype = edgeTypes.next();
 
-            Observable<Edge> edges = gm.loadEdgesToTarget(
-                    new SimpleSearchByEdgeType( cpHeadEntity.getId(), etype, Long.MAX_VALUE,
-                            SearchByEdgeType.Order.DESCENDING, null ) );
+            Observable<Edge> edges = gm.loadEdgesToTarget( new SimpleSearchByEdgeType( 
+                cpHeadEntity.getId(), etype, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null ) );
 
             Iterator<Edge> iter = edges.toBlockingObservable().getIterator();
             while ( iter.hasNext() ) {
                 Edge edge = iter.next();
 
-                if ( fromEntityType != null && !fromEntityType.equals( edge.getSourceNode().getType() ) ) {
-                    logger.debug( "Ignoring edge from entity type {}", edge.getSourceNode().getType() );
+                if (     fromEntityType != null 
+                     && !fromEntityType.equals( edge.getSourceNode().getType() ) ) {
+                    logger.debug( "Ignoring edge from entity type {}", 
+                            edge.getSourceNode().getType() );
                     continue;
                 }
 
-                EntityRef eref = new SimpleEntityRef( edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
+                EntityRef eref = new SimpleEntityRef( 
+                        edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
 
                 String name = null;
                 if ( CpNamingUtils.isConnectionEdgeType( edge.getType() ) ) {
@@ -353,11 +366,11 @@ public class CpRelationManager implements RelationManager {
 
         final GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        logger.debug( "updateContainingCollectionsAndCollections(): "
-                        + "Searched for edges to target {}:{}\n   in scope {}\n   found: {}", new Object[] {
-                        cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid(),
-                        applicationScope.getApplication()
-                } );
+        logger.debug( "updateContainingCollectionsAndCollections(): " + "Searched for edges to target {}:{}\n   in scope {}\n   found: {}",
+            new Object[] { cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid(),
+                applicationScope.getApplication() 
+            } );
 
         // loop through all types of edge to target
 
@@ -367,25 +380,25 @@ public class CpRelationManager implements RelationManager {
         final EntityIndexBatch entityIndexBatch = ei.createBatch();
 
         final int count = gm.getEdgeTypesToTarget(
-                new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) )
-                //for each edge type, emit all the edges of that type
-                            .flatMap( new Func1<String, Observable<Edge>>() {
-                                @Override
-                                public Observable<Edge> call( final String etype ) {
-                                    return gm.loadEdgesToTarget(
-                                            new SimpleSearchByEdgeType( cpHeadEntity.getId(), etype, Long.MAX_VALUE,
-                                                    SearchByEdgeType.Order.DESCENDING, null ) );
-                                }
-                            } )
-
-                            //for each edge we receive index and add to the batch
-                            .doOnNext( new Action1<Edge>() {
+            new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) )
+
+                // for each edge type, emit all the edges of that type
+                .flatMap( new Func1<String, Observable<Edge>>() {
                     @Override
-                    public void call( final Edge edge ) {
+                    public Observable<Edge> call( final String etype ) {
+                        return gm.loadEdgesToTarget( new SimpleSearchByEdgeType( 
+                            cpHeadEntity.getId(), etype, Long.MAX_VALUE, 
+                            SearchByEdgeType.Order.DESCENDING, null ) );
+                    }
+                } )
 
+                //for each edge we receive index and add to the batch
+                .doOnNext( new Action1<Edge>() {
+                    @Override
+                    public void call( final Edge edge ) {
 
-                        EntityRef sourceEntity =
-                                new SimpleEntityRef( edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
+                        EntityRef sourceEntity = new SimpleEntityRef( 
+                                edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
 
                         // reindex the entity in the source entity's collection or connection index
 
@@ -393,29 +406,29 @@ public class CpRelationManager implements RelationManager {
                         if ( CpNamingUtils.isCollectionEdgeType( edge.getType() ) ) {
 
                             String collName = CpNamingUtils.getCollectionName( edge.getType() );
-                            indexScope =
-                                    new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
-                                            CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );
+                            indexScope = new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(),
+                                sourceEntity.getType() ),
+                                CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
                         }
                         else {
 
                             String connName = CpNamingUtils.getCollectionName( edge.getType() );
-                            indexScope =
-                                    new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
-                                            CpNamingUtils.getConnectionScopeName( cpEntity.getId().getType(),
-                                                    connName ) );
+                            indexScope = new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(),
+                                sourceEntity.getType() ),
+                                CpNamingUtils.getConnectionScopeName( cpEntity.getId().getType(),
+                                connName ) );
                         }
 
                         entityIndexBatch.index( indexScope, cpEntity );
 
                         // reindex the entity in the source entity's all-types index
 
-                        indexScope = new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
-                                CpNamingUtils.ALL_TYPES );
+                        indexScope = new IndexScopeImpl( new SimpleId( 
+                            sourceEntity.getUuid(), sourceEntity.getType() ), CpNamingUtils.ALL_TYPES );
 
                         entityIndexBatch.index( indexScope, cpEntity );
                     }
-                } ).count().toBlocking().lastOrDefault( 0 );
+            } ).count().toBlocking().lastOrDefault( 0 );
 
 
         entityIndexBatch.execute();
@@ -431,14 +444,22 @@ public class CpRelationManager implements RelationManager {
 
         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()
-                } );
+        logger.debug( "isConnectionMember(): Checking for edge type {} from {}:{} to {}:{}",
+            new Object[] { 
+                edgeType,
+                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, null ) );
+        Observable<Edge> edges = gm.loadEdgeVersions( new SimpleSearchByEdge( 
+            new SimpleId( headEntity.getUuid(), headEntity.getType() ), 
+            edgeType,
+            entityId,
+            Long.MAX_VALUE,
+            SearchByEdgeType.Order.DESCENDING, 
+            null ) );
 
         return edges.toBlockingObservable().firstOrDefault( null ) != null;
     }
@@ -453,14 +474,22 @@ public class CpRelationManager implements RelationManager {
 
         String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collName );
 
-        logger.debug( "isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}", new Object[] {
-                        edgeType, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid()
-                } );
+        logger.debug( "isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}",
+            new Object[] { 
+                edgeType,
+                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, null ) );
+        Observable<Edge> edges = gm.loadEdgeVersions( new SimpleSearchByEdge( 
+            new SimpleId( headEntity.getUuid(), headEntity.getType() ), 
+            edgeType,
+            entityId,
+            Long.MAX_VALUE,
+            SearchByEdgeType.Order.DESCENDING,
+            null ) );
 
         return edges.toBlockingObservable().firstOrDefault( null ) != null;
     }
@@ -472,9 +501,12 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Observable<Edge> edgesToTarget = gm.loadEdgesToTarget(
-                new SimpleSearchByEdgeType( targetId, CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
-                        System.currentTimeMillis(), SearchByEdgeType.Order.DESCENDING, null ) ); // last
+        Observable<Edge> edgesToTarget = gm.loadEdgesToTarget( new SimpleSearchByEdgeType( 
+            targetId,
+            CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
+            System.currentTimeMillis(),
+            SearchByEdgeType.Order.DESCENDING, 
+            null ) ); // last
 
         Iterator<Edge> iterator = edgesToTarget.toBlockingObservable().getIterator();
         int count = 0;
@@ -494,9 +526,12 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Observable<Edge> edgesFromSource = gm.loadEdgesFromSource(
-                new SimpleSearchByEdgeType( sourceId, CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
-                        System.currentTimeMillis(), SearchByEdgeType.Order.DESCENDING, null ) ); // last
+        Observable<Edge> edgesFromSource = gm.loadEdgesFromSource( new SimpleSearchByEdgeType( 
+            sourceId,
+            CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
+            System.currentTimeMillis(),
+            SearchByEdgeType.Order.DESCENDING,
+            null ) ); // last
 
         int count = edgesFromSource.take( 2 ).count().toBlocking().last();
 
@@ -511,8 +546,8 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Observable<String> str =
-                gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) );
+        Observable<String> str = gm.getEdgeTypesFromSource( 
+                new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) );
 
         Iterator<String> iter = str.toBlockingObservable().getIterator();
         while ( iter.hasNext() ) {
@@ -525,8 +560,11 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public Results getCollection( String collectionName, UUID startResult, int count, Level resultsLevel,
-                                  boolean reversed ) throws Exception {
+    public Results getCollection( String collectionName,
+            UUID startResult,
+            int count,
+            Level resultsLevel,
+            boolean reversed ) throws Exception {
 
         Query query = Query.fromQL( "select *" );
         query.setLimit( count );
@@ -551,12 +589,14 @@ public class CpRelationManager implements RelationManager {
     @Override
     public Entity addToCollection( String collName, EntityRef itemRef ) throws Exception {
 
-        CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collName );
+        CollectionInfo collection = 
+                getDefaultSchema().getCollection( headEntity.getType(), collName );
         if ( ( collection != null ) && !collection.getType().equals( itemRef.getType() ) ) {
             return null;
         }
 
-        return addToCollection( collName, itemRef, ( collection != null && collection.getLinkedCollection() != null ) );
+        return addToCollection( collName, itemRef, 
+                ( collection != null && collection.getLinkedCollection() != null ) );
     }
 
 
@@ -581,15 +621,16 @@ public class CpRelationManager implements RelationManager {
         }
 
         // 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() ) );
+        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
-        org.apache.usergrid.persistence.model.entity.Entity memberEntity =
-                memberMgr.load( new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlocking().last();
+        org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load( 
+                new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlocking().last();
 
         if ( memberEntity == null ) {
             throw new RuntimeException(
@@ -597,18 +638,23 @@ public class CpRelationManager implements RelationManager {
         }
 
         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 )
-                    } );
+            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 && UUIDUtils.isTimeBased( memberEntity.getId().getUuid() ) ?
-                memberEntity.getId().getUuid() : UUIDUtils.newTimeUUID();
+        UUID timeStampUuid = memberEntity.getId().getUuid() != null 
+                && UUIDUtils.isTimeBased( memberEntity.getId().getUuid() ) 
+                ?  memberEntity.getId().getUuid() : UUIDUtils.newTimeUUID();
 
         long uuidHash = UUIDUtils.getUUIDLong( timeStampUuid );
 
@@ -617,10 +663,15 @@ public class CpRelationManager implements RelationManager {
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         gm.writeEdge( edge ).toBlockingObservable().last();
 
-        logger.debug( "Wrote edgeType {}\n   from {}:{}\n   to {}:{}\n   scope {}:{}", new Object[] {
-                edgeType, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid(),
-                memberEntity.getId().getType(), memberEntity.getId().getUuid(),
-                applicationScope.getApplication().getType(), applicationScope.getApplication().getUuid()
+        logger.debug( "Wrote edgeType {}\n   from {}:{}\n   to {}:{}\n   scope {}:{}", 
+            new Object[] { 
+                edgeType,
+                cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid(),
+                memberEntity.getId().getType(),
+                memberEntity.getId().getUuid(),
+                applicationScope.getApplication().getType(),
+                applicationScope.getApplication().getUuid()
         } );
 
         ( ( CpEntityManager ) em ).indexEntityIntoCollection( cpHeadEntity, memberEntity, collName );
@@ -635,7 +686,8 @@ public class CpRelationManager implements RelationManager {
         //            headEntityScope.getName()});
 
         if ( connectBack && collection != null && collection.getLinkedCollection() != null ) {
-            getRelationManager( itemEntity ).addToCollection( collection.getLinkedCollection(), headEntity, false );
+            getRelationManager( itemEntity ).addToCollection( 
+                    collection.getLinkedCollection(), headEntity, false );
         }
 
         return itemEntity;
@@ -656,7 +708,8 @@ public class CpRelationManager implements RelationManager {
 
     @Override
     @Metered( group = "core", name = "RelationManager_createItemInCollection" )
-    public Entity createItemInCollection( String collName, String itemType, Map<String, Object> properties )
+    public Entity createItemInCollection( 
+            String collName, String itemType, Map<String, Object> properties )
             throws Exception {
 
         if ( headEntity.getUuid().equals( applicationId ) ) {
@@ -675,7 +728,9 @@ public class CpRelationManager implements RelationManager {
             return em.create( itemType, properties );
         }
 
-        else if ( headEntity.getType().equals( Group.ENTITY_TYPE ) && ( collName.equals( COLLECTION_ROLES ) ) ) {
+        else if ( headEntity.getType().equals( Group.ENTITY_TYPE ) 
+                && ( collName.equals( COLLECTION_ROLES ) ) ) {
+
             UUID groupId = headEntity.getUuid();
             String roleName = ( String ) properties.get( PROPERTY_NAME );
             return em.createGroupRole( groupId, roleName, ( Long ) properties.get( PROPERTY_INACTIVITY ) );
@@ -695,7 +750,8 @@ public class CpRelationManager implements RelationManager {
             addToCollection( collName, itemEntity );
 
             if ( collection != null && collection.getLinkedCollection() != null ) {
-                getRelationManager( getHeadEntity() ).addToCollection( collection.getLinkedCollection(), itemEntity );
+                getRelationManager( getHeadEntity() )
+                        .addToCollection( collection.getLinkedCollection(), itemEntity );
             }
         }
 
@@ -723,21 +779,26 @@ public class CpRelationManager implements RelationManager {
         }
 
         // load the entity to be removed to the collection
-        CollectionScope memberScope =
-                new CollectionScopeImpl( this.applicationScope.getApplication(), this.applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
+        CollectionScope memberScope = new CollectionScopeImpl( 
+                this.applicationScope.getApplication(),
+                this.applicationScope.getApplication(),
+                CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
         EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager( memberScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Loading entity to remove from collection "
-                            + "{}:{} from scope\n   app {}\n   owner {}\n   name {}", new Object[] {
-                            itemRef.getType(), itemRef.getUuid(), memberScope.getApplication(), memberScope.getOwner(),
-                            memberScope.getName()
-                    } );
+            logger.debug( "Loading entity to remove from collection " 
+                + "{}:{} from scope\n   app {}\n   owner {}\n   name {}", 
+                new Object[] {
+                    itemRef.getType(),
+                    itemRef.getUuid(),
+                    memberScope.getApplication(),
+                    memberScope.getOwner(),
+                    memberScope.getName()
+               });
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity memberEntity =
-                memberMgr.load( new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlockingObservable().last();
+        org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load( 
+            new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlockingObservable().last();
 
         final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         final EntityIndexBatch batch = ei.createBatch();
@@ -760,15 +821,20 @@ public class CpRelationManager implements RelationManager {
 
         // remove edge from collection to item 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
-        Edge collectionToItemEdge =
-                new SimpleEdge( cpHeadEntity.getId(), CpNamingUtils.getEdgeTypeFromCollectionName( collName ),
-                        memberEntity.getId(), UUIDUtils.getUUIDLong( memberEntity.getId().getUuid() ) );
+        Edge collectionToItemEdge = new SimpleEdge( 
+                cpHeadEntity.getId(), 
+                CpNamingUtils.getEdgeTypeFromCollectionName( collName ), 
+                memberEntity.getId(), UUIDUtils.getUUIDLong( memberEntity.getId().getUuid() ) );
         gm.deleteEdge( collectionToItemEdge ).toBlockingObservable().last();
 
         // remove edge from item to collection
-        Edge itemToCollectionEdge = new SimpleEdge( memberEntity.getId(), CpNamingUtils
-                .getEdgeTypeFromCollectionName( Schema.defaultCollectionName( cpHeadEntity.getId().getType() ) ),
-                cpHeadEntity.getId(), UUIDUtils.getUUIDLong( cpHeadEntity.getId().getUuid() ) );
+        Edge itemToCollectionEdge = new SimpleEdge( 
+                memberEntity.getId(), 
+                CpNamingUtils.getEdgeTypeFromCollectionName( 
+                    Schema.defaultCollectionName( cpHeadEntity.getId().getType() ) ), 
+                cpHeadEntity.getId(), 
+                UUIDUtils.getUUIDLong( cpHeadEntity.getId().getUuid() ) );
+
         gm.deleteEdge( itemToCollectionEdge ).toBlockingObservable().last();
 
         // special handling for roles collection of a group
@@ -797,9 +863,11 @@ public class CpRelationManager implements RelationManager {
         headEntity = em.validate( headEntity );
         dstEntityRef = em.validate( dstEntityRef );
 
-        CollectionInfo srcCollection = getDefaultSchema().getCollection( headEntity.getType(), srcRelationName );
+        CollectionInfo srcCollection = 
+                getDefaultSchema().getCollection( headEntity.getType(), srcRelationName );
 
-        CollectionInfo dstCollection = getDefaultSchema().getCollection( dstEntityRef.getType(), dstRelationName );
+        CollectionInfo dstCollection = 
+                getDefaultSchema().getCollection( dstEntityRef.getType(), dstRelationName );
 
         Results results = null;
         do {
@@ -838,9 +906,8 @@ public class CpRelationManager implements RelationManager {
         CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collName );
 
         if ( collection == null ) {
-            throw new RuntimeException(
-                    "Cannot find collection-info for '" + collName + "' of " + headEntity.getType() + ":" + headEntity
-                            .getUuid() );
+            throw new RuntimeException( "Cannot find collection-info for '" + collName 
+                    + "' of " + headEntity.getType() + ":" + headEntity .getUuid() );
         }
 
         IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(),
@@ -922,29 +989,39 @@ public class CpRelationManager implements RelationManager {
 
         ConnectionRefImpl connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef );
 
-        CollectionScope targetScope =
-                new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
+        CollectionScope targetScope = new CollectionScopeImpl( 
+            applicationScope.getApplication(), 
+            applicationScope.getApplication(),
+            CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
 
         EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager( targetScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "createConnection(): " + "Indexing connection type '{}'\n   from source {}:{}]\n"
-                            + "   to target {}:{}\n   from scope\n   app {}\n   owner {}\n   name {}", new Object[] {
-                            connectionType, headEntity.getType(), headEntity.getUuid(), connectedEntityRef.getType(),
-                            connectedEntityRef.getUuid(), targetScope.getApplication(), targetScope.getOwner(),
-                            targetScope.getName()
-                    } );
+            logger.debug( "createConnection(): " 
+                + "Indexing connection type '{}'\n   from source {}:{}]\n"
+                + "   to target {}:{}\n   from scope\n   app {}\n   owner {}\n   name {}", 
+                new Object[] {
+                    connectionType,
+                    headEntity.getType(),
+                    headEntity.getUuid(),
+                    connectedEntityRef.getType(),
+                    connectedEntityRef.getUuid(),
+                    targetScope.getApplication(), 
+                    targetScope.getOwner(), 
+                    targetScope.getName()
+                } );
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity =
-                targetEcm.load( new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
-                         .toBlockingObservable().last();
+        org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load( 
+            new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
+                .toBlockingObservable().last();
 
         String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
 
         // create graph edge connection from head entity to member entity
-        Edge edge = new SimpleEdge( cpHeadEntity.getId(), edgeType, targetEntity.getId(), System.currentTimeMillis() );
+        Edge edge = new SimpleEdge( 
+                cpHeadEntity.getId(), edgeType, targetEntity.getId(), System.currentTimeMillis() );
+
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         gm.writeEdge( edge ).toBlockingObservable().last();
 
@@ -975,14 +1052,16 @@ public class CpRelationManager implements RelationManager {
 
     @SuppressWarnings( "unchecked" )
     @Metered( group = "core", name = "CpRelationManager_batchUpdateEntityConnection" )
-    public Mutator<ByteBuffer> batchUpdateEntityConnection( Mutator<ByteBuffer> batch, boolean disconnect,
-                                                            ConnectionRefImpl connection, UUID timestampUuid )
-            throws Exception {
+    public Mutator<ByteBuffer> batchUpdateEntityConnection( 
+            Mutator<ByteBuffer> batch, 
+            boolean disconnect, 
+            ConnectionRefImpl conn, 
+            UUID timestampUuid ) throws Exception {
 
         long timestamp = getTimestampInMicros( timestampUuid );
 
-        Entity connectedEntity =
-                em.get( new SimpleEntityRef( connection.getConnectedEntityType(), connection.getConnectedEntityId() ) );
+        Entity connectedEntity = em.get(new SimpleEntityRef( 
+                conn.getConnectedEntityType(), conn.getConnectedEntityId() ) );
 
         if ( connectedEntity == null ) {
             return batch;
@@ -992,59 +1071,59 @@ public class CpRelationManager implements RelationManager {
 
         if ( disconnect ) {
 
-            addDeleteToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectedEntityId(), connection.getConnectedEntityType() ), timestamp );
+            addDeleteToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
+                        conn.getConnectionType() ),
+                asList(conn.getConnectedEntityId(), conn.getConnectedEntityType() ), timestamp );
 
-            addDeleteToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectingEntityId(), connection.getConnectingEntityType() ), timestamp );
+            addDeleteToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
+                        conn.getConnectionType() ),
+                asList(conn.getConnectingEntityId(), conn.getConnectingEntityType() ), timestamp );
 
             // delete the connection path if there will be no connections left
 
             // check out outbound edges of the given type.  If we have more than the 1 specified,
             // we shouldn't delete the connection types from our outbound index
-            if ( !moreThanOneOutboundConnection( connection.getConnectingEntity(), connection.getConnectionType() ) ) {
+            if ( !moreThanOneOutboundConnection(conn.getConnectingEntity(), conn.getConnectionType() ) ) {
 
-                addDeleteToMutator( batch, ENTITY_DICTIONARIES,
-                        key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
-                        connection.getConnectionType(), timestamp );
+                addDeleteToMutator(batch, ENTITY_DICTIONARIES,
+                        key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
+                        conn.getConnectionType(), timestamp );
             }
 
             //check out inbound edges of the given type.  If we have more than the 1 specified,
             // we shouldn't delete the connection types from our outbound index
-            if ( !moreThanOneInboundConnection( connection.getConnectingEntity(), connection.getConnectionType() ) ) {
+            if ( !moreThanOneInboundConnection(conn.getConnectingEntity(), conn.getConnectionType() ) ) {
 
-                addDeleteToMutator( batch, ENTITY_DICTIONARIES,
-                        key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
-                        connection.getConnectionType(), timestamp );
-            }
+                addDeleteToMutator(batch, ENTITY_DICTIONARIES,
+                    key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
+                    conn.getConnectionType(), timestamp );
+        }
         }
         else {
 
-            addInsertToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectedEntityId(), connection.getConnectedEntityType() ), timestamp,
+            addInsertToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                    key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
+                            conn.getConnectionType() ),
+                    asList(conn.getConnectedEntityId(), conn.getConnectedEntityType() ), timestamp,
                     timestamp );
 
-            addInsertToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectingEntityId(), connection.getConnectingEntityType() ), timestamp,
+            addInsertToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                    key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
+                            conn.getConnectionType() ),
+                    asList(conn.getConnectingEntityId(), conn.getConnectingEntityType() ), timestamp,
                     timestamp );
 
             // Add connection type to connections set
-            addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
-                    connection.getConnectionType(), null, timestamp );
+            addInsertToMutator(batch, ENTITY_DICTIONARIES,
+                    key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
+                    conn.getConnectionType(), null, timestamp );
 
             // Add connection type to connections set
-            addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
-                    connection.getConnectionType(), null, timestamp );
+            addInsertToMutator(batch, ENTITY_DICTIONARIES,
+                    key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
+                    conn.getConnectionType(), null, timestamp );
         }
 
         // Add indexes for the connected entity's list properties
@@ -1058,17 +1137,20 @@ public class CpRelationManager implements RelationManager {
         Schema schema = getDefaultSchema();
 
         for ( String dictionaryName : dictionaryNames ) {
-            boolean has_dictionary = schema.hasDictionary( connectedEntity.getType(), dictionaryName );
-            boolean dictionary_indexed =
-                    schema.isDictionaryIndexedInConnections( connectedEntity.getType(), dictionaryName );
+
+            boolean has_dictionary = schema.hasDictionary( 
+                    connectedEntity.getType(), dictionaryName );
+
+            boolean dictionary_indexed = schema.isDictionaryIndexedInConnections( 
+                    connectedEntity.getType(), dictionaryName );
 
             if ( dictionary_indexed || !has_dictionary ) {
                 Set<Object> elementValues = em.getDictionaryAsSet( connectedEntity, dictionaryName );
                 for ( Object elementValue : elementValues ) {
-                    IndexUpdate indexUpdate =
-                            batchStartIndexUpdate( batch, connectedEntity, dictionaryName, elementValue, timestampUuid,
-                                    has_dictionary, true, disconnect, false );
-                    batchUpdateConnectionIndex( indexUpdate, connection );
+                    IndexUpdate indexUpdate = batchStartIndexUpdate( 
+                            batch, connectedEntity, dictionaryName, elementValue, 
+                            timestampUuid, has_dictionary, true, disconnect, false );
+                    batchUpdateConnectionIndex(indexUpdate, conn );
                 }
             }
         }
@@ -1079,8 +1161,11 @@ public class CpRelationManager implements RelationManager {
 
     @Override
     @Metered( group = "core", name = "RelationManager_createConnection_paired_connection_type" )
-    public ConnectionRef createConnection( String pairedConnectionType, EntityRef pairedEntity, String connectionType,
-                                           EntityRef connectedEntityRef ) throws Exception {
+    public ConnectionRef createConnection( 
+            String pairedConnectionType,
+            EntityRef pairedEntity,
+            String connectionType,
+            EntityRef connectedEntityRef ) throws Exception {
 
         throw new UnsupportedOperationException( "Paired connections not supported" );
     }
@@ -1095,7 +1180,8 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public ConnectionRef connectionRef( String connectionType, EntityRef connectedEntityRef ) throws Exception {
+    public ConnectionRef connectionRef( 
+            String connectionType, EntityRef connectedEntityRef ) throws Exception {
 
         ConnectionRef connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef );
 
@@ -1104,8 +1190,11 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public ConnectionRef connectionRef( String pairedConnectionType, EntityRef pairedEntity, String connectionType,
-                                        EntityRef connectedEntityRef ) throws Exception {
+    public ConnectionRef connectionRef( 
+            String pairedConnectionType,
+            EntityRef pairedEntity,
+            String connectionType,
+            EntityRef connectedEntityRef ) throws Exception {
 
         throw new UnsupportedOperationException( "Paired connections not supported" );
     }
@@ -1124,7 +1213,8 @@ public class CpRelationManager implements RelationManager {
         // First, clean up the dictionary records of the connection
         Keyspace ko = cass.getApplicationKeyspace( applicationId );
         Mutator<ByteBuffer> m = createMutator( ko, be );
-        batchUpdateEntityConnection( m, true, ( ConnectionRefImpl ) connectionRef, UUIDGenerator.newTimeUUID() );
+        batchUpdateEntityConnection( 
+                m, true, ( ConnectionRefImpl ) connectionRef, UUIDGenerator.newTimeUUID() );
         batchExecute( m, CassandraService.RETRY_COUNT );
 
         EntityRef connectingEntityRef = connectionRef.getConnectingEntity();  // source
@@ -1132,26 +1222,36 @@ public class CpRelationManager implements RelationManager {
 
         String connectionType = connectionRef.getConnectedEntity().getConnectionType();
 
-        CollectionScope targetScope =
-                new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
+        CollectionScope targetScope = new CollectionScopeImpl( 
+                applicationScope.getApplication(),
+                applicationScope.getApplication(),
+                CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType()) );
 
         EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager( targetScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Deleting connection '{}' from source {}:{} \n   to target {}:{}", new Object[] {
-                            connectionType, connectingEntityRef.getType(), connectingEntityRef.getUuid(),
-                            connectedEntityRef.getType(), connectedEntityRef.getUuid()
+            logger.debug( "Deleting connection '{}' from source {}:{} \n   to target {}:{}", 
+                new Object[] {
+                    connectionType,
+                    connectingEntityRef.getType(),
+                    connectingEntityRef.getUuid(),
+                    connectedEntityRef.getType(),
+                    connectedEntityRef.getUuid()
                     } );
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity =
-                targetEcm.load( new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
-                         .toBlockingObservable().last();
+        org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load( 
+            new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) ) 
+                .toBlockingObservable().last();
 
         // Delete graph edge connection from head entity to member entity
-        Edge edge = new SimpleEdge( new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
-                connectionType, targetEntity.getId(), System.currentTimeMillis() );
+        Edge edge = new SimpleEdge( 
+            new SimpleId( connectingEntityRef.getUuid(),
+                connectingEntityRef.getType() ),
+                connectionType,
+                targetEntity.getId(),
+                System.currentTimeMillis() );
+
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         gm.deleteEdge( edge ).toBlockingObservable().last();
 
@@ -1159,15 +1259,18 @@ public class CpRelationManager implements RelationManager {
         final EntityIndexBatch batch = ei.createBatch();
 
         // Deindex the connection in app|source|type context
-        IndexScope indexScope =
-                new IndexScopeImpl( new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
-                        CpNamingUtils.getConnectionScopeName( targetEntity.getId().getType(), connectionType ) );
+        IndexScope indexScope = new IndexScopeImpl( 
+            new SimpleId( connectingEntityRef.getUuid(),
+                connectingEntityRef.getType() ),
+                CpNamingUtils.getConnectionScopeName( targetEntity.getId().getType(),
+                connectionType ) );
         batch.deindex( indexScope, targetEntity );
 
         // Deindex the connection in app|source|type context
-        IndexScope allTypesIndexScope =
-                new IndexScopeImpl( new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
-                        CpNamingUtils.ALL_TYPES );
+        IndexScope allTypesIndexScope = new IndexScopeImpl( 
+            new SimpleId( connectingEntityRef.getUuid(),
+                connectingEntityRef.getType() ),
+                CpNamingUtils.ALL_TYPES );
 
         batch.deindex( allTypesIndexScope, targetEntity );
 
@@ -1189,7 +1292,8 @@ public class CpRelationManager implements RelationManager {
 
     @Override
     public Set<String> getConnectionTypes( boolean filterConnection ) throws Exception {
-        Set<String> connections = cast( em.getDictionaryAsSet( headEntity, Schema.DICTIONARY_CONNECTED_TYPES ) );
+        Set<String> connections = cast( 
+                em.getDictionaryAsSet( headEntity, Schema.DICTIONARY_CONNECTED_TYPES ) );
 
         if ( connections == null ) {
             return null;
@@ -1202,8 +1306,8 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public Results getConnectedEntities( String connectionType, String connectedEntityType, Level level )
-            throws Exception {
+    public Results getConnectedEntities( 
+            String connectionType, String connectedEntityType, Level level ) throws Exception {
 
         Results raw = null;
 
@@ -1231,8 +1335,8 @@ public class CpRelationManager implements RelationManager {
             final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
 
-            logger.debug( "Searching connected entities from scope {}:{}", indexScope.getOwner().toString(),
-                    indexScope.getName() );
+            logger.debug( "Searching connected entities from scope {}:{}", 
+                    indexScope.getOwner().toString(), indexScope.getName() );
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search( indexScope, query );
@@ -1260,16 +1364,16 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public Results getConnectingEntities( String connType, String fromEntityType, Level resultsLevel )
-            throws Exception {
+    public Results getConnectingEntities( 
+            String connType, String fromEntityType, Level resultsLevel ) throws Exception {
 
         return getConnectingEntities( connType, fromEntityType, resultsLevel, -1 );
     }
 
 
     @Override
-    public Results getConnectingEntities( String connType, String fromEntityType, Level level, int count )
-            throws Exception {
+    public Results getConnectingEntities( 
+            String connType, String fromEntityType, Level level, int count ) throws Exception {
 
         // looking for edges to the head entity
         String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connType );
@@ -1312,12 +1416,14 @@ public class CpRelationManager implements RelationManager {
         if ( query.getEntityType() == null ) {
 
             // search across all types of collections of the head-entity
-            IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(), CpNamingUtils.ALL_TYPES );
+            IndexScope indexScope = new IndexScopeImpl( 
+                cpHeadEntity.getId(), 
+                CpNamingUtils.ALL_TYPES );
 
             EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
-            logger.debug( "Searching connections from the all-types scope {}:{}", indexScope.getOwner().toString(),
-                    indexScope.getName() );
+            logger.debug( "Searching connections from the all-types scope {}:{}", 
+                    indexScope.getOwner().toString(), indexScope.getName() );
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search( indexScope, query );
@@ -1325,12 +1431,14 @@ public class CpRelationManager implements RelationManager {
             return buildConnectionResults( query, crs, query.getConnectionType() );
         }
 
-        IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(),
-                CpNamingUtils.getConnectionScopeName( query.getEntityType(), query.getConnectionType() ) );
+        IndexScope indexScope = new IndexScopeImpl( 
+            cpHeadEntity.getId(), 
+            CpNamingUtils.getConnectionScopeName( query.getEntityType(), 
+            query.getConnectionType() ) );
         EntityIndex ei = managerCache.getEntityIndex( applicationScope );
-
-        logger.debug( "Searching connections from the scope {}:{}", indexScope.getOwner().toString(),
-                indexScope.getName() );
+        
+        logger.debug( "Searching connections from the scope {}:{}", 
+                indexScope.getOwner().toString(), indexScope.getName() );
 
         query = adjustQuery( query );
         CandidateResults crs = ei.search( indexScope, query );
@@ -1353,29 +1461,31 @@ public class CpRelationManager implements RelationManager {
                 // This is fulgy to put here, but required.
                 if ( query.getEntityType().equals( User.ENTITY_TYPE ) && ident.isEmail() ) {
 
-                    Query newQuery =
-                            Query.fromQL( "select * where email='" + query.getSingleNameOrEmailIdentifier() + "'" );
+                    Query newQuery = Query.fromQL( "select * where email='" 
+                            + query.getSingleNameOrEmailIdentifier() + "'" );
                     query.setRootOperand( newQuery.getRootOperand() );
                 }
 
                 // use the ident with the default alias. could be an email
                 else {
 
-                    Query newQuery =
-                            Query.fromQL( "select * where name='" + query.getSingleNameOrEmailIdentifier() + "'" );
+                    Query newQuery = Query.fromQL( "select * where name='" 
+                            + query.getSingleNameOrEmailIdentifier() + "'" );
                     query.setRootOperand( newQuery.getRootOperand() );
                 }
             }
             else if ( query.containsSingleUuidIdentifier() ) {
 
-                Query newQuery = Query.fromQL( "select * where uuid='" + query.getSingleUuidIdentifier() + "'" );
+                Query newQuery = Query.fromQL( 
+                        "select * where uuid='" + query.getSingleUuidIdentifier() + "'" );
                 query.setRootOperand( newQuery.getRootOperand() );
             }
         }
 
         if ( query.isReversed() ) {
 
-            Query.SortPredicate desc = new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.DESCENDING );
+            Query.SortPredicate desc = 
+                new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.DESCENDING );
 
             try {
                 query.addSort( desc );
@@ -1387,8 +1497,8 @@ public class CpRelationManager implements RelationManager {
 
         if ( query.getSortPredicates().isEmpty() ) {
 
-            //TODO, should this be descending?
-            Query.SortPredicate asc = new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.ASCENDING );
+            Query.SortPredicate asc = 
+                new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.DESCENDING);
 
             query.addSort( asc );
         }
@@ -1424,7 +1534,8 @@ public class CpRelationManager implements RelationManager {
     }
 
 
-    private Results buildConnectionResults( Query query, CandidateResults crs, String connectionType ) {
+    private Results buildConnectionResults( 
+            Query query, CandidateResults crs, String connectionType ) {
 
         if ( query.getLevel().equals( Level.ALL_PROPERTIES ) ) {
             return buildResults( query, crs, connectionType );
@@ -1436,9 +1547,11 @@ public class CpRelationManager implements RelationManager {
 
         for ( CandidateResult cr : crs ) {
 
-            SimpleEntityRef targetRef = new SimpleEntityRef( cr.getId().getType(), cr.getId().getUuid() );
+            SimpleEntityRef targetRef = 
+                    new SimpleEntityRef( cr.getId().getType(), cr.getId().getUuid() );
 
-            final ConnectionRef ref = new ConnectionRefImpl( sourceRef, connectionType, targetRef );
+            final ConnectionRef ref = 
+                    new ConnectionRefImpl( sourceRef, connectionType, targetRef );
 
             refs.add( ref );
         }
@@ -1459,8 +1572,8 @@ public class CpRelationManager implements RelationManager {
         logger.debug( "buildResults() for {} from {} candidates", collName, crs.size() );
 
         //get an instance of our results loader
-        final ResultsLoader resultsLoader =
-                this.resultsLoaderFactory.getLoader( applicationScope, this.headEntity, query.getResultsLevel() );
+        final ResultsLoader resultsLoader = this.resultsLoaderFactory.getLoader( 
+                applicationScope, this.headEntity, query.getResultsLevel() );
 
         //load the results
         final Results results = resultsLoader.loadResults( crs );
@@ -1484,11 +1597,11 @@ public class CpRelationManager implements RelationManager {
 
         Entity entity = getHeadEntity();
 
-        elementValue = getDefaultSchema().validateEntitySetValue( entity.getType(), setName, elementValue );
+        elementValue = getDefaultSchema()
+                .validateEntitySetValue( entity.getType(), setName, elementValue );
 
-        IndexUpdate indexUpdate =
-                batchStartIndexUpdate( batch, entity, setName, elementValue, timestampUuid, true, true, removeFromSet,
-                        false );
+        IndexUpdate indexUpdate = batchStartIndexUpdate( batch, entity, setName, elementValue, 
+                timestampUuid, true, true, removeFromSet, false );
 
         // Update collections 
 
@@ -1498,8 +1611,8 @@ public class CpRelationManager implements RelationManager {
         if ( containers != null ) {
             Map<EntityRef, Set<String>> containerEntities = getContainers();
             for ( EntityRef containerEntity : containerEntities.keySet() ) {
-                if ( containerEntity.getType().equals( TYPE_APPLICATION ) && Schema
-                        .isAssociatedEntityType( entity.getType() ) ) {
+                if ( containerEntity.getType().equals( TYPE_APPLICATION ) 
+                        && Schema.isAssociatedEntityType( entity.getType() ) ) {
                     logger.debug( "Extended properties for {} not indexed by application", entity.getType() );
                     continue;
                 }
@@ -1525,25 +1638,28 @@ public class CpRelationManager implements RelationManager {
      * Batch update collection index.
      *
      * @param indexUpdate The update to apply
-     * @param owner The entity that is the owner context of this entity update. Can either be an application, or another
-     * entity
+     * @param owner The entity that is the owner context of this entity update. Can either be an 
+     * application, or another * entity
      * @param collectionName the collection name
-     *
+     * 
      * @return The indexUpdate with batch mutations
-     *
      * @throws Exception the exception
      */
     @Metered( group = "core", name = "RelationManager_batchUpdateCollectionIndex" )
-    public IndexUpdate batchUpdateCollectionIndex( IndexUpdate indexUpdate, EntityRef owner, String collectionName )
+    public IndexUpdate batchUpdateCollectionIndex( 
+            IndexUpdate indexUpdate, EntityRef owner, String collectionName )
             throws Exception {
 
         logger.debug( "batchUpdateCollectionIndex" );
 
         Entity indexedEntity = indexUpdate.getEntity();
 
-        String bucketId = indexBucketLocator
-                .getBucket( applicationId, IndexBucketLocator.IndexType.COLLECTION, indexedEntity.getUuid(),
-                        indexedEntity.getType(), indexUpdate.getEntryName() );
+        String bucketId = indexBucketLocator.getBucket( 
+                applicationId, 
+                IndexBucketLocator.IndexType.COLLECTION, 
+                indexedEntity.getUuid(),
+                indexedEntity.getType(), 
+                indexUpdate.getEntryName() );
 
         // the root name without the bucket
         // entity_id,collection_name,prop_name,
@@ -1561,14 +1677,14 @@ public class CpRelationManager implements RelationManager {
 
                 index_key = key( index_name, bucketId );
 
-                addDeleteToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, entry.getIndexComposite(),
-                        indexUpdate.getTimestamp() );
+                addDeleteToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, 
+                        entry.getIndexComposite(), indexUpdate.getTimestamp() );
 
                 if ( "location.coordinates".equals( entry.getPath() ) ) {
-                    EntityLocationRef loc = new EntityLocationRef( indexUpdate.getEntity(), entry.getTimestampUuid(),
-                            entry.getValue().toString() );
-                    batchRemoveLocationFromCollectionIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_name, loc );
+                    EntityLocationRef loc = new EntityLocationRef( indexUpdate.getEntity(), 
+                            entry.getTimestampUuid(), entry.getValue().toString() );
+                    batchRemoveLocationFromCollectionIndex( indexUpdate.getBatch(), 
+                            indexBucketLocator, applicationId, index_name, loc );
                 }
             }
             else {
@@ -1576,8 +1692,9 @@ public class CpRelationManager implements RelationManager {
             }
         }
 
-        if ( ( indexUpdate.getNewEntries().size() > 0 ) && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue()
-                && !indexUpdate.isRemoveListEntry() ) ) ) {
+        if ( ( indexUpdate.getNewEntries().size() > 0 ) 
+                && ( !indexUpdate.isMultiValue() 
+                || ( indexUpdate.isMultiValue() && !indexUpdate.isRemoveListEntry() ) ) ) {
 
             for ( IndexUpdate.IndexEntry indexEntry : indexUpdate.getNewEntries() ) {
 
@@ -1589,15 +1706,21 @@ public class CpRelationManager implements RelationManager {
 
                 // int i = 0;
 
-                addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, indexEntry.getIndexComposite(),
-                        null, indexUpdate.getTimestamp() );
+                addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, 
+                        indexEntry.getIndexComposite(), null, indexUpdate.getTimestamp() );
 
                 if ( "location.coordinates".equals( indexEntry.getPath() ) ) {
-                    EntityLocationRef loc =
-                            new EntityLocationRef( indexUpdate.getEntity(), indexEntry.getTimestampUuid(),
-                                    indexEntry.getValue().toString() );
-                    batchStoreLocationInCollectionIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_name, indexedEntity.getUuid(), loc );
+                    EntityLocationRef loc = new EntityLocationRef( 
+                            indexUpdate.getEntity(), 
+                            indexEntry.getTimestampUuid(), 
+                            indexEntry.getValue().toString() );
+                    batchStoreLocationInCollectionIndex( 
+                            indexUpdate.getBatch(),
+                            indexBucketLocator,
+                            applicationId,
+                            index_name,
+                            indexedEntity.getUuid(),
+                            loc );
                 }
 
                 // i++;
@@ -1614,26 +1737,56 @@ public class CpRelationManager implements RelationManager {
     }
 
 
-    public IndexUpdate batchStartIndexUpdate( Mutator<ByteBuffer> batch, Entity entity, String entryName,
-                                              Object entryValue, UUID timestampUuid, boolean schemaHasProperty,
-                                              boolean isMultiValue, boolean removeListEntry, boolean fulltextIndexed )
+    public IndexUpdate batchStartIndexUpdate( 
+            Mutator<ByteBuffer> batch,
+            Entity entity,
+            String entryName,
+            Object entryValue,
+            UUID timestampUuid,
+            boolean schemaHasProperty,
+            boolean isMultiValue,
+            boolean removeListEntry,
+            boolean fulltextIndexed )
             throws Exception {
-        return batchStartIndexUpdate( batch, entity, entryName, entryValue, timestampUuid, schemaHasProperty,
-                isMultiValue, removeListEntry, fulltextIndexed, false );
+
+        return batchStartIndexUpdate( 
+                batch,
+                entity,
+                entryName,
+                entryValue,
+                timestampUuid,
+                schemaHasProperty,
+                isMultiValue,
+                removeListEntry,
+                fulltextIndexed,
+                false );
     }
 
 
     @Metered( group = "core", name = "RelationManager_batchStartIndexUpdate" )
-    public IndexUpdate batchStartIndexUpdate( Mutator<ByteBuffer> batch, Entity entity, String entryName,
-                                              Object entryValue, UUID timestampUuid, boolean schemaHasProperty,
-                                              boolean isMultiValue, boolean removeListEntry, boolean fulltextIndexed,
-                                              boolean skipRead ) throws Exception {
+    public IndexUpdate batchStartIndexUpdate( 
+            Mutator<ByteBuffer> batch,
+            Entity entity,
+            String entryName,
+            Object entryValue,
+            UUID timestampUuid,
+            boolean schemaHasProperty,
+            boolean isMultiValue,
+            boolean removeListEntry,
+            boolean fulltextIndexed,
+            boolean skipRead ) throws Exception {
 
         long timestamp = getTimestampInMicros( timestampUuid );
 
-        IndexUpdate indexUpdate =
-                new IndexUpdate( batch, entity, entryName, entryValue, schemaHasProperty, isMultiValue, removeListEntry,
-                        timestampUuid );
+        IndexUpdate indexUpdate = new IndexUpdate( 
+                batch,
+                entity,
+                entryName,
+                entryValue,
+                schemaHasProperty,
+                isMultiValue,
+                removeListEntry,
+                timestampUuid );
 
         // entryName = entryName.toLowerCase();
 
@@ -1644,17 +1797,30 @@ public class CpRelationManager implements RelationManager {
             List<HColumn<ByteBuffer, ByteBuffer>> entries = null;
 
             if ( isMultiValue && validIndexableValue( entryValue ) ) {
-                entries = cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_INDEX_ENTRIES,
+                entries = cass.getColumns( 
+                    cass.getApplicationKeyspace( applicationId ), 
+                        ENTITY_INDEX_ENTRIES,
                         entity.getUuid(),
-                        new DynamicComposite( entryName, indexValueCode( entryValue ), toIndexableValue( entryValue ) ),
-                        setGreaterThanEqualityFlag( new DynamicComposite( entryName, indexValueCode( entryValue ),
-                                        toIndexableValue( entryValue ) ) ), INDEX_ENTRY_LIST_COUNT, false );
+                        new DynamicComposite( 
+                            entryName, 
+                            indexValueCode( entryValue ), 
+                            toIndexableValue( entryValue ) ),
+                        setGreaterThanEqualityFlag( 
+                            new DynamicComposite( 
+                                entryName, indexValueCode( entryValue ),
+                                toIndexableValue( entryValue ) ) ), 
+                        INDEX_ENTRY_LIST_COUNT, 
+                        false );
             }
             else {
-                entries = cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_INDEX_ENTRIES,
-                        entity.getUuid(), new DynamicComposite( entryName ),
-                        setGreaterThanEqualityFlag( new DynamicComposite( entryName ) ), INDEX_ENTRY_LIST_COUNT,
-                        false );
+                entries = cass.getColumns( 
+                    cass.getApplicationKeyspace( applicationId ), 
+                    ENTITY_INDEX_ENTRIES, 
+                    entity.getUuid(), 
+                    new DynamicComposite( entryName ), 
+                    setGreaterThanEqualityFlag( new DynamicComposite( entryName ) ), 
+                    INDEX_ENTRY_LIST_COUNT, 
+                    false );
             }
 
             if ( logger.isDebugEnabled() ) {
@@ -1672,7 +1838,8 @@ public class CpRelationManager implements RelationManager {
                 // new format:
                 // composite(entryName,
                 // value_code,prev_value,prev_timestamp,prev_obj_path) = null
-                DynamicComposite composite = DynamicComposite.fromByteBuffer( entry.getName().duplicate() );
+                DynamicComposite composite = 
+                        DynamicComposite.fromByteBuffer( entry.getName().duplicate() );
                 prev_value = composite.get( 2 );
                 prev_timestamp = ( UUID ) composite.get( 3 );
                 if ( composite.size() > 4 ) {
@@ -1686,7 +1853,8 @@ public class CpRelationManager implements RelationManager {
                         entryPath = entryName + "." + prev_obj_path;
                     }
 
-                    indexUpdate.addPrevEntry( entryPath, prev_value, prev_timestamp, entry.getName().duplicate() );
+                    indexUpdate.addPrevEntry( 
+                            entryPath, prev_value, prev_timestamp, entry.getName().duplicate() );
 
                     // composite(property_value,connected_entity_id,entry_timestamp)
                     // addDeleteToMutator(batch, ENTITY_INDEX_ENTRIES,
@@ -1701,7 +1869,8 @@ public class CpRelationManager implements RelationManager {
 
         if ( !isMultiValue || ( isMultiValue && !removeListEntry ) ) {
 
-            List<Map.Entry<String, Object>> list = IndexUtils.getKeyValueList( entryName, entryValue, fulltextIndexed );
+            List<Map.Entry<String, Object>> list = 
+                    IndexUtils.getKeyValueList( entryName, entryValue, fulltextIndexed );
 
             if ( entryName.equalsIgnoreCase( "location" ) && ( entryValue instanceof Map ) ) {
                 @SuppressWarnings( "rawtypes" ) double latitude =
@@ -1715,14 +1884,15 @@ public class CpRelationManager implements RelationManager {
             for ( Map.Entry<String, Object> indexEntry : list ) {
 
                 if ( validIndexableValue( indexEntry.getValue() ) ) {
-                    indexUpdate.addNewEntry( indexEntry.getKey(), toIndexableValue( indexEntry.getValue() ) );
+                    indexUpdate.addNewEntry( 
+                            indexEntry.getKey(), toIndexableValue( indexEntry.getValue() ) );
                 }
             }
 
             if ( isMultiValue ) {
                 addInsertToMutator( batch, ENTITY_INDEX_ENTRIES, entity.getUuid(),
-                        asList( entryName, indexValueCode( entryValue ), toIndexableValue( entryValue ),
-                                indexUpdate.getTimestampUuid() ), null, timestamp );
+                    asList( entryName, indexValueCode( entryValue ), 
+                    toIndexableValue( entryValue ), indexUpdate.getTimestampUuid() ), null, timestamp );
             }
             else {
                 // int i = 0;
@@ -1740,7 +1910,8 @@ public class CpRelationManager implements RelationManager {
                     byte code = indexValueCode( indexEntry.getValue() );
                     Object val = toIndexableValue( indexEntry.getValue() );
                     addInsertToMutator( batch, ENTITY_INDEX_ENTRIES, entity.getUuid(),
-                            asList( entryName, code, val, indexUpdate.getTimestampUuid(), name ), null, timestamp );
+                            asList( entryName, code, val, indexUpdate.getTimestampUuid(), name ), 
+                            null, timestamp );
 
                     indexUpdate.addIndex( indexEntry.getKey() );
                 }
@@ -1844,10 +2015,17 @@ public class CpRelationManager implements RelationManager {
                 batchDeleteConnectionIndexEntries( indexUpdate, entry, connection, index_keys );
 
                 if ( "location.coordinates".equals( entry.getPath() ) ) {
-                    EntityLocationRef loc = new EntityLocationRef( indexUpdate.getEntity(), entry.getTimestampUuid(),
-                            entry.getValue().toString() );
-                    batchDeleteLocationInConnectionsIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_keys, entry.getPath(), loc );
+                    EntityLocationRef loc = new EntityLocationRef( 
+                        indexUpdate.getEntity(),
+                        entry.getTimestampUuid(),
+                        entry.getValue().toString() );
+                    batchDeleteLocationInConnectionsIndex( 
+                        indexUpdate.getBatch(),
+                        indexBucketLocator,
+                        applicationId,
+                        index_keys,
+                        entry.getPath(),
+                        loc );
                 }
             }
             else {
@@ -1855,19 +2033,25 @@ public class CpRelationManager implements RelationManager {
             }
         }
 
-        if ( ( indexUpdate.getNewEntries().size() > 0 ) && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue()
-                && !indexUpdate.isRemoveListEntry() ) ) ) {
+        if ( ( indexUpdate.getNewEntries().size() > 0 ) 
+                && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue() && !indexUpdate.isRemoveListEntry() ) ) ) {
 
             for ( IndexUpdate.IndexEntry indexEntry : indexUpdate.getNewEntries() ) {
 
                 batchAddConnectionIndexEntries( indexUpdate, indexEntry, connection, index_keys );
 
                 if ( "location.coordinates".equals( indexEntry.getPath() ) ) {
-                    EntityLocationRef loc =
-                            new EntityLocationRef( indexUpdate.getEntity(), indexEntry.getTimestampUuid(),
-                                    indexEntry.getValue().toString() );
-                    batchStoreLocationInConnectionsIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_keys, indexEntry.getPath(), loc );
+                    EntityLocationRef loc = new EntityLocationRef( 
+                        indexUpdate.getEntity(),
+                        indexEntry.getTimestampUuid(),
+                        indexEntry.getValue().toString() );
+                    batchStoreLocationInConnectionsIndex( 
+                        indexUpdate.getBatch(),
+                            indexBucketLocator,
+                            applicationId,
+                            index_keys,
+                            indexEntry.getPath(),
+                            loc );
                 }
             }
 
@@ -1897,10 +2081,11 @@ public class CpRelationManager implements RelationManager {
      *
      * @return connectionType The name of the edges to search
      */
-    private PagingResultsIterator getReversedConnectionsIterator( EntityRef targetEntity, String connectionType )
-            throws Exception {
+    private PagingResultsIterator getReversedConnectionsIterator( 
+            EntityRef targetEntity, String connectionType ) throws Exception {
 
-        return new PagingResultsIterator( getConnectingEntities( targetEntity, connectionType, null, Level.REFS ) );
+        return new PagingResultsIterator( 
+                getConnectingEntities( targetEntity, connectionType, null, Level.REFS ) );
     }
 
 
@@ -1912,8 +2097,11 @@ public class CpRelationManager implements RelationManager {
      * @param connectedEntityType The connected entity type, if not specified all types are returned
      * @param resultsLevel The results level to return
      */
-    private Results getConnectingEntities( EntityRef targetEntity, String connectionType, String connectedEntityType,
-                                           Level resultsLevel ) throws Exception {
+    private Results getConnectingEntities( 
+        EntityRef targetEntity,
+            String connectionType,
+            String connectedEntityType,
+            Level resultsLevel ) throws Exception {
 
         return getConnectingEntities( targetEntity, connectionType, connectedEntityType, resultsLevel, 0 );
     }
@@ -1927,16 +2115,21 @@ public class CpRelationManager implements RelationManager {
      * @param connectedEntityType The connected entity type, if not specified all types are returned
      * @param count result limit
      */
-    private Results getConnectingEntities( EntityRef targetEntity, String connectionType, String connectedEntityType,
-                                           Level level, int count ) throws Exception {
+    private Results getConnectingEntities( 
+            EntityRef targetEntity,
+            String connectionType,
+            String connectedEntityType,
+            Level level,
+            int count ) throws Exception {
 
         Query query = new Query();
         query.setResultsLevel( level );
         query.setLimit( count );
 
-        final ConnectionRefImpl connectionRef =
-                new ConnectionRefImpl( new SimpleEntityRef( connectedEntityType, null ), connectionType, targetEntity );
-        final ConnectionResultsLoaderFactory factory = new ConnectionResultsLoaderFactory( connectionRef );
+        final ConnectionRefImpl connectionRef = new ConnectionRefImpl( 
+                new SimpleEntityRef( connectedEntityType, null ), connectionType, targetEntity );
+        final ConnectionResultsLoaderFactory factory = 
+                new ConnectionResultsLoaderFactory( connectionRef );
 
         QueryProcessorImpl qp = new QueryProcessorImpl( query, null, em, factory );
         SearchConnectionVisitor visitor = new SearchConnectionVisitor( qp, connectionRef, false );
@@ -1946,9 +2139,11 @@ public class CpRelationManager implements RelationManager {
 
 
     @Metered( group = "core", name = "RelationManager_batchDeleteConnectionIndexEntries" )
-    public Mutator<ByteBuffer> batchDeleteConnectionIndexEntries( IndexUpdate indexUpdate, IndexUpdate.IndexEntry entry,
-                                                                  ConnectionRefImpl connection, UUID[] index_keys )
-            throws Exception {
+    public Mutator<ByteBuffer> batchDeleteConnectionIndexEntries( 
+            IndexUpdate indexUpdate,
+            IndexUpdate.IndexEntry entry,
+            ConnectionRefImpl connection,
+            UUID[] index_keys ) throws Exception {
 
         logger.debug( "batchDeleteConnectionIndexEntries" );
 
@@ -2059,15 +2254,16 @@ public class CpRelationManager implements RelationManager {
 
         private final ConnectionRefImpl connection;
 
-        /** True if we should search from source->target edges.  False if we should search from target<-source edges */
+        /** True if we should search from source->target edges.  
+         * False if we should search from target<-source edges */
         private final boolean outgoing;
 
 
         /**
          * @param queryProcessor They query processor to use
          * @param connection The connection refernce
-         * @param outgoing The direction to search.  True if we should search from source->target edges.  False if we
-         * should search from target<-source edges
+         * @param outgoing The direction to search.  True if we should search from source->target 
+         * edges.  False if we * should search from target<-source edges
          */
         public SearchConnectionVisitor( QueryProcessorImpl queryProcessor, ConnectionRefImpl connection,
                                         boolean outgoing ) {
@@ -2085,8 +2281,12 @@ public class CpRelationManager implements RelationManager {
         @Override
         protected IndexScanner secondaryIndexScan( QueryNode node, QuerySlice slice ) throws Exception {
 
-            UUID id = ConnectionRefImpl.getIndexId( ConnectionRefImpl.BY_CONNECTION_AND_ENTITY_TYPE, headEntity,
-                    connection.getConnectionType(), connection.getConnectedEntityType(), new ConnectedEntityRef[0] );
+            UUID id = ConnectionRefImpl.getIndexId( 
+                    ConnectionRefImpl.BY_CONNECTION_AND_ENTITY_TYPE,
+                    headEntity,
+                    connection.getConnectionType(),
+                    connection.getConnectedEntityType(),
+                    new ConnectedEntityRef[0] );
 
             Object key = key( id, INDEX_CONNECTIONS );
 
@@ -2120,10 +2320,13 @@ public class CpRelationManager implements RelationManager {
 
             queryProcessor.applyCursorAndSort( slice );
 
-            GeoIterator itr =
-                    new GeoIterator( new ConnectionGeoSearch( em, indexBucketLocator, cass, connection.getIndexId() ),
-                            query.getLimit(), slice, node.getPropertyName(),
-                            new Point( node.getLattitude(), node.getLongitude() ), node.getDistance() );
+            GeoIterator itr = new GeoIterator( 
+                new ConnectionGeoSearch( em, indexBucketLocator, cass, connection.getIndexId() ), 
+                query.getLimit(),
+                slice,
+                node.getPropertyName(),
+                new Point( node.getLattitude(), node.getLongitude() ),
+                node.getDistance() );
 
             results.push( itr );
         }
@@ -2181,12 +2384,20 @@ public class CpRelationManager implements RelationManager {
 
             //we need to iterate all connection types
             else {
-                connectionTypes = new ConnectionTypesIterator( cass, applicationId, entityIdToUse, outgoing, size );
+                connectionTypes = new ConnectionTypesIterator( 
+                        cass, applicationId, entityIdToUse, outgoing, size );
             }
 
-            IndexScanner connectionScanner =
-                    new ConnectedIndexScanner( cass, dictionaryType, applicationId, entityIdToUse, connectionTypes,
-                            start, slice.isReversed(), size, skipFirst );
+            IndexScanner connectionScanner = new ConnectedIndexScanner( 
+                    cass,
+                    dictionaryType,
+                    applicationId,
+                    entityIdToUse,
+                    connectionTypes,
+                    start,
+                    slice.isReversed(),
+                    size,
+                    skipFirst );
 
             this.results.push( new SliceIterator( slice, connectionScanner, connectionParser ) );
         }
@@ -2214,9 +2425,19 @@ public class CpRelationManager implements RelationManager {
 
         Object keyPrefix = key( indexKey, slice.getPropertyName() );
 
-        IndexScanner scanner = new IndexBucketScanner( cass, indexBucketLocator, ENTITY_INDEX, applicationId,
-                IndexBucketLocator.IndexType.CONNECTION, keyPrefix, range[0], range[1], slice.isReversed(), pageSize,
-                slice.hasCursor(), slice.getPropertyName() );
+        IndexScanner scanner = new IndexBucketScanner( 
+                cass,
+                indexBucketLocator,
+                ENTITY_INDEX,
+                applicationId,
+                IndexBucketLocator.IndexType.CONNECTION,
+                keyPrefix,
+                range[0],
+                range[1],
+                slice.isReversed(),
+                pageSize,
+                slice.hasCursor(),
+                slice.getPropertyName() );
 
         return scanner;
     }