public void Run(string alias, int minNodeCount)
        {
            var  entityRepository = Factory.EntityRepository;
            var  factory          = new CloneEntityMemberRequestFactory(entityRepository);
            long typeId           = new EntityRef(alias).Id;

            EntityMemberRequest request = factory.CreateRequest(typeId);

            Assert.That(request, Is.Not.Null);

            long nodeCount = request.WalkNodes( ).Count( );

            Assert.That(nodeCount, Is.GreaterThan(minNodeCount));
            Assert.That(nodeCount, Is.LessThan(50));
        }
예제 #2
0
        /// <summary>
        /// Determine if we can process this request using the BulkRequest mechanism.
        /// </summary>
        /// <param name="request">The request</param>
        /// <returns>True if the BulkRequestRunner can process it, otherwise false.</returns>
        public static bool IsValidForBulkRequest(EntityMemberRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            // BulkRequests currently cannot support
            // - Load AllFields (must specify exact fields)
            // - Loading fields on relationships

            var nodes = request.WalkNodes();

            foreach (var node in nodes)
            {
                if (node.AllFields)
                {
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>
        /// Prepare the SQL to load in relationships of all applicable types, in one direction.
        /// </summary>
        private void ProcessRelationships(Direction relDirection)
        {
            // Creates a list of relationship transition rules, where each tuple contains (in order):
            // 1. the node that the relationship instruction applies to
            // 2. the relationship ID
            // 3. the node that the relationship points to

            var relRequests =
                from nodeInfo in _requestNodeMap.Values
                from relReq in nodeInfo.Request.Relationships
                where Entity.GetDirection(relReq.RelationshipTypeId, relReq.IsReverse) == relDirection
                select new { NodeInfo = nodeInfo, RelRequest = relReq };

            var dt = TableValuedParameter.Create(TableValuedParameterType.BulkRelType);

            //var relMap = new List<Tuple<int, long, int>>( );
            var map = new HashSet <Tuple <int, long, int> >( );

            foreach (var relReqInfo in relRequests)
            {
                if (relReqInfo.RelRequest.MetadataOnly)
                {
                    continue; // Don't load actual data
                }
                int nodeId  = relReqInfo.NodeInfo.Tag;
                var relReq  = relReqInfo.RelRequest;
                var mapRule = new Tuple <int, long, int>(nodeId, relReq.RelationshipTypeId.Id,
                                                         _requestNodeMap [relReq.RequestedMembers].Tag);

                if (!map.Contains(mapRule))
                {
                    map.Add(mapRule);

                    dt.Rows.Add(mapRule.Item1, mapRule.Item2, mapRule.Item3);
                }

                if (relReq.IsRecursive)
                {
                    var recursiveRule = new Tuple <int, long, int>(nodeId, relReq.RelationshipTypeId.Id, nodeId);

                    if (!map.Contains(recursiveRule))
                    {
                        map.Add(recursiveRule);

                        dt.Rows.Add(recursiveRule.Item1, recursiveRule.Item2, recursiveRule.Item3);
                    }
                }
            }

            if (map.Count == 0)
            {
                return;
            }

            string tblName = relDirection == Direction.Forward ? "@relFwd" : "@relRev";

            _result.TableValuedParameters [tblName] = dt;

            // Gather metadata for relationship requests
            var relReqs = from node in _request.WalkNodes( )
                          from relReq in node.Relationships
                          select relReq;

            foreach (var relReq in relReqs)
            {
                var relTypeId = relReq.RelationshipTypeId.Id;
                var relEntity = Entity.Get <Relationship>(relTypeId);
                if (relEntity == null)
                {
                    continue;
                }

                long key       = relTypeId;
                var  direction = Entity.GetDirection(relReq.RelationshipTypeId, relReq.IsReverse);
                if (direction == Direction.Reverse)
                {
                    key = -key;
                }

                _result.Relationships [key] = new RelationshipInfo
                {
                    CloneAction        = relEntity.CloneAction_Enum ?? CloneActionEnum_Enumeration.Drop,
                    ReverseCloneAction = relEntity.ReverseCloneAction_Enum ?? CloneActionEnum_Enumeration.Drop,
                    IsLookup           = relEntity.IsLookup(direction),
                    ImpliesSecurity    = (direction == Direction.Forward ? relEntity.SecuresTo : relEntity.SecuresFrom) ?? false ||
                                         (relReq.RelationshipTypeId.Alias == "isOfType" && relReq.RelationshipTypeId.Namespace == "core" && !relReq.IsReverse) // Allow types to be loaded implicitly, without granting write to the type.
                };
            }
        }