コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldComputeDegreeWithoutType() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldComputeDegreeWithoutType()
        {
            // GIVEN
            long node;

            using (Transaction tx = Transaction())
            {
                Write write = tx.DataWrite();
                node = write.NodeCreate();
                write.RelationshipCreate(node, tx.TokenWrite().relationshipTypeGetOrCreateForName("R1"), write.NodeCreate());
                write.RelationshipCreate(node, tx.TokenWrite().relationshipTypeGetOrCreateForName("R2"), write.NodeCreate());
                write.RelationshipCreate(write.NodeCreate(), tx.TokenWrite().relationshipTypeGetOrCreateForName("R3"), node);
                write.RelationshipCreate(node, tx.TokenWrite().relationshipTypeGetOrCreateForName("R4"), node);

                tx.Success();
            }

            using (Transaction tx = Transaction())
            {
                Read          read    = tx.DataRead();
                CursorFactory cursors = tx.Cursors();
                using (NodeCursor nodes = cursors.AllocateNodeCursor())
                {
                    assertThat(CompiledExpandUtils.NodeGetDegreeIfDense(read, node, nodes, cursors, OUTGOING), equalTo(3));
                    assertThat(CompiledExpandUtils.NodeGetDegreeIfDense(read, node, nodes, cursors, INCOMING), equalTo(2));
                    assertThat(CompiledExpandUtils.NodeGetDegreeIfDense(read, node, nodes, cursors, BOTH), equalTo(4));
                }
            }
        }
コード例 #2
0
        public static RelationshipSelectionCursor ConnectingRelationships(Read read, CursorFactory cursors, NodeCursor nodeCursor, long fromNode, Direction direction, long toNode, int[] relTypes)
        {
            //Check from
            int fromDegree = CalculateTotalDegreeIfDense(read, fromNode, nodeCursor, direction, relTypes, cursors);

            if (fromDegree == 0)
            {
                return(Org.Neo4j.@internal.Kernel.Api.helpers.RelationshipSelectionCursor_EMPTY);
            }
            bool fromNodeIsDense = fromDegree != NOT_DENSE_DEGREE;

            //Check to
            read.SingleNode(toNode, nodeCursor);
            if (!nodeCursor.Next())
            {
                return(Org.Neo4j.@internal.Kernel.Api.helpers.RelationshipSelectionCursor_EMPTY);
            }
            bool toNodeIsDense = nodeCursor.Dense;

            //Both are dense, start with the one with the lesser degree
            if (fromNodeIsDense && toNodeIsDense)
            {
                //Note that we have already position the cursor at toNode
                int       toDegree = CalculateTotalDegree(nodeCursor, direction, relTypes, cursors);
                long      startNode;
                long      endNode;
                Direction relDirection;
                if (fromDegree < toDegree)
                {
                    startNode    = fromNode;
                    endNode      = toNode;
                    relDirection = direction;
                }
                else
                {
                    startNode    = toNode;
                    endNode      = fromNode;
                    relDirection = direction.reverse();
                }

                return(ConnectingRelationshipsIterator(CompiledCursorUtils.NodeGetRelationships(read, cursors, nodeCursor, startNode, relDirection, relTypes), endNode));
            }
            else if (fromNodeIsDense)
            {
                return(ConnectingRelationshipsIterator(CompiledCursorUtils.NodeGetRelationships(read, cursors, nodeCursor, toNode, direction.reverse(), relTypes), fromNode));
            }
            else
            {               //either only toNode is dense or none of them, just go with what we got
                return(ConnectingRelationshipsIterator(CompiledCursorUtils.NodeGetRelationships(read, cursors, nodeCursor, fromNode, direction, relTypes), toNode));
            }
        }
コード例 #3
0
        private static int NodeGetDegree(NodeCursor nodeCursor, CursorFactory cursors, Direction direction, int type)
        {
            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(countOutgoing(nodeCursor, cursors, type));

            case Direction.InnerEnum.INCOMING:
                return(countIncoming(nodeCursor, cursors, type));

            case Direction.InnerEnum.BOTH:
                return(countAll(nodeCursor, cursors, type));

            default:
                throw new System.InvalidOperationException("Unknown direction " + direction);
            }
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldComputeDegreeWithType() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldComputeDegreeWithType()
        {
            // GIVEN
            long node;
            int  @in, @out, loop;

            using (Transaction tx = Transaction())
            {
                Write write = tx.DataWrite();
                node = write.NodeCreate();
                TokenWrite tokenWrite = tx.TokenWrite();
                @out = tokenWrite.RelationshipTypeGetOrCreateForName("OUT");
                @in  = tokenWrite.RelationshipTypeGetOrCreateForName("IN");
                loop = tokenWrite.RelationshipTypeGetOrCreateForName("LOOP");
                write.RelationshipCreate(node, @out, write.NodeCreate());
                write.RelationshipCreate(node, @out, write.NodeCreate());
                write.RelationshipCreate(write.NodeCreate(), @in, node);
                write.RelationshipCreate(node, loop, node);

                tx.Success();
            }

            using (Transaction tx = Transaction())
            {
                Read          read    = tx.DataRead();
                CursorFactory cursors = tx.Cursors();
                using (NodeCursor nodes = cursors.AllocateNodeCursor())
                {
                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, OUTGOING, @out), equalTo(2));
                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, OUTGOING, @in), equalTo(0));
                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, OUTGOING, loop), equalTo(1));

                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, INCOMING, @out), equalTo(0));
                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, INCOMING, @in), equalTo(1));
                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, INCOMING, loop), equalTo(1));

                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, BOTH, @out), equalTo(2));
                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, BOTH, @in), equalTo(1));
                    assertThat(nodeGetDegreeIfDense(read, node, nodes, cursors, BOTH, loop), equalTo(1));
                }
            }
        }
コード例 #5
0
        public static RelationshipSelectionCursor NodeGetRelationships(Read read, CursorFactory cursors, NodeCursor node, long nodeId, Direction direction, int[] types)
        {
            read.SingleNode(nodeId, node);
            if (!node.Next())
            {
                return(Org.Neo4j.@internal.Kernel.Api.helpers.RelationshipSelectionCursor_EMPTY);
            }
            switch (direction.innerEnumValue)
            {
            case Direction.InnerEnum.OUTGOING:
                return(RelationshipSelections.outgoingCursor(cursors, node, types));

            case Direction.InnerEnum.INCOMING:
                return(RelationshipSelections.incomingCursor(cursors, node, types));

            case Direction.InnerEnum.BOTH:
                return(RelationshipSelections.allCursor(cursors, node, types));

            default:
                throw new System.InvalidOperationException("Unknown direction " + direction);
            }
        }
コード例 #6
0
 public abstract TxStateVisitor DecorateTxStateVisitor(StorageReader storageReader, Read read, CursorFactory cursorFactory, ReadableTransactionState state, TxStateVisitor visitor);
コード例 #7
0
 public static RelationshipSelectionCursor NodeGetRelationships(Read read, CursorFactory cursors, NodeCursor node, long nodeId, Direction direction)
 {
     return(NodeGetRelationships(read, cursors, node, nodeId, direction, null));
 }
コード例 #8
0
 public override TxStateVisitor DecorateTxStateVisitor(StorageReader storageReader, Read read, CursorFactory cursorFactory, ReadableTransactionState state, TxStateVisitor visitor)
 {
     return(visitor);
 }
コード例 #9
0
        private static int CalculateTotalDegree(NodeCursor nodeCursor, Direction direction, int[] relTypes, CursorFactory cursors)
        {
            int degree = 0;

            foreach (int relType in relTypes)
            {
                degree += NodeGetDegree(nodeCursor, cursors, direction, relType);
            }

            return(degree);
        }
コード例 #10
0
 private static int CalculateTotalDegreeIfDense(Read read, long node, NodeCursor nodeCursor, Direction direction, int[] relTypes, CursorFactory cursors)
 {
     read.SingleNode(node, nodeCursor);
     if (!nodeCursor.Next())
     {
         return(0);
     }
     if (!nodeCursor.Dense)
     {
         return(NOT_DENSE_DEGREE);
     }
     return(CalculateTotalDegree(nodeCursor, direction, relTypes, cursors));
 }
コード例 #11
0
        internal static int NodeGetDegreeIfDense(Read read, long node, NodeCursor nodeCursor, CursorFactory cursors, Direction direction, int type)
        {
            read.SingleNode(node, nodeCursor);
            if (!nodeCursor.Next())
            {
                return(0);
            }
            if (!nodeCursor.Dense)
            {
                return(NOT_DENSE_DEGREE);
            }

            return(NodeGetDegree(nodeCursor, cursors, direction, type));
        }
コード例 #12
0
 public override TxStateVisitor DecorateTxStateVisitor(StorageReader storageReader, Read read, CursorFactory cursorFactory, ReadableTransactionState txState, TxStateVisitor visitor)
 {
     if (!txState.HasDataChanges())
     {
         // If there are no data changes, there is no need to enforce constraints. Since there is no need to
         // enforce constraints, there is no need to build up the state required to be able to enforce constraints.
         // In fact, it might even be counter productive to build up that state, since if there are no data changes
         // there would be schema changes instead, and in that case we would throw away the schema-dependant state
         // we just built when the schema changing transaction commits.
         return(visitor);
     }
     return(getOrCreatePropertyExistenceEnforcerFrom(storageReader).decorate(visitor, read, cursorFactory));
 }