//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)); } } }
private void CollectAndSortNodeIds(long nodeId, Transaction transaction, NodeCursor nodes) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.eclipse.collections.api.set.primitive.MutableLongSet nodeIdSet = new org.eclipse.collections.impl.set.mutable.primitive.LongHashSet(); MutableLongSet nodeIdSet = new LongHashSet(); nodeIdSet.add(nodeId); [email protected] read = transaction.DataRead(); read.SingleNode(nodeId, nodes); if (!nodes.Next()) { this._sortedNodeIds = _empty; return; } using (RelationshipSelectionCursor rels = RelationshipSelections.allCursor(transaction.Cursors(), nodes, null)) { while (rels.Next()) { if (_firstRelId == NO_SUCH_RELATIONSHIP) { _firstRelId = rels.RelationshipReference(); } nodeIdSet.add(rels.SourceNodeReference()); nodeIdSet.add(rels.TargetNodeReference()); } } this._sortedNodeIds = nodeIdSet.toSortedArray(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void singleNode(org.neo4j.internal.kernel.api.Read read, org.neo4j.internal.kernel.api.NodeCursor nodeCursor, long node) throws org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException private static void SingleNode(Read read, NodeCursor nodeCursor, long node) { read.SingleNode(node, nodeCursor); if (!nodeCursor.Next()) { throw new EntityNotFoundException(EntityType.NODE, node); } }
/// <summary> /// Checks if given node has a given label. /// </summary> /// <param name="read"> The current Read instance </param> /// <param name="nodeCursor"> The node cursor to use </param> /// <param name="node"> The id of the node </param> /// <param name="label"> The id of the label </param> /// <returns> {@code true} if the node has the label, otherwise {@code false} </returns> /// <exception cref="EntityNotFoundException"> if the node is not there. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static boolean nodeHasLabel(org.neo4j.internal.kernel.api.Read read, org.neo4j.internal.kernel.api.NodeCursor nodeCursor, long node, int label) throws org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException public static bool NodeHasLabel(Read read, NodeCursor nodeCursor, long node, int label) { if (label == StatementConstants.NO_SUCH_LABEL) { return(false); } SingleNode(read, nodeCursor, node); return(nodeCursor.HasLabel(label)); }
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); }
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)); }
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)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void txReturnsCorrectIdWhenReadOnly() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void TxReturnsCorrectIdWhenReadOnly() { ExecuteDummyTxs(Db, 42); [email protected] tx = NewTransaction(); using (NodeCursor node = tx.Cursors().allocateNodeCursor()) { tx.DataRead().singleNode(1, node); node.Next(); } tx.Success(); assertEquals(KernelTransaction.READ_ONLY, tx.CloseTransaction()); assertFalse(tx.Open); }
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); } }
/// <summary> /// Fetches a given property from a node /// </summary> /// <param name="read"> The current Read instance </param> /// <param name="nodeCursor"> The node cursor to use </param> /// <param name="node"> The id of the node </param> /// <param name="propertyCursor"> The property cursor to use </param> /// <param name="prop"> The id of the property to find </param> /// <returns> The value of the given property </returns> /// <exception cref="EntityNotFoundException"> If the node cannot be find. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static org.neo4j.values.storable.Value nodeGetProperty(org.neo4j.internal.kernel.api.Read read, org.neo4j.internal.kernel.api.NodeCursor nodeCursor, long node, org.neo4j.internal.kernel.api.PropertyCursor propertyCursor, int prop) throws org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException public static Value NodeGetProperty(Read read, NodeCursor nodeCursor, long node, PropertyCursor propertyCursor, int prop) { if (prop == StatementConstants.NO_SUCH_PROPERTY_KEY) { return(Values.NO_VALUE); } SingleNode(read, nodeCursor, node); nodeCursor.Properties(propertyCursor); while (propertyCursor.Next()) { if (propertyCursor.PropertyKey() == prop) { return(propertyCursor.PropertyValue()); } } return(Values.NO_VALUE); }
//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)); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public abstract void validateNodePropertyExistenceConstraint(org.neo4j.internal.kernel.api.NodeLabelIndexCursor allNodes, org.neo4j.internal.kernel.api.NodeCursor nodeCursor, org.neo4j.internal.kernel.api.PropertyCursor propertyCursor, org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException; public abstract void ValidateNodePropertyExistenceConstraint(NodeLabelIndexCursor allNodes, NodeCursor nodeCursor, PropertyCursor propertyCursor, LabelSchemaDescriptor descriptor);
public static RelationshipSelectionCursor NodeGetRelationships(Read read, CursorFactory cursors, NodeCursor node, long nodeId, Direction direction) { return(NodeGetRelationships(read, cursors, node, nodeId, direction, null)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void validateNodeKeyConstraint(org.neo4j.internal.kernel.api.NodeLabelIndexCursor allNodes, org.neo4j.internal.kernel.api.NodeCursor nodeCursor, org.neo4j.internal.kernel.api.PropertyCursor propertyCursor, org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException public override void ValidateNodeKeyConstraint(NodeLabelIndexCursor allNodes, NodeCursor nodeCursor, PropertyCursor propertyCursor, LabelSchemaDescriptor descriptor) { ValidateNodePropertyExistenceConstraint(allNodes, nodeCursor, propertyCursor, descriptor); }
public override void Node(NodeCursor cursor) { _read.singleNode(_node, cursor); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: void lockAllNodesAndConsumeRelationships(long nodeId, final org.neo4j.internal.kernel.api.Transaction transaction, org.neo4j.internal.kernel.api.NodeCursor nodes) throws org.neo4j.internal.kernel.api.exceptions.KernelException //JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: internal virtual void LockAllNodesAndConsumeRelationships(long nodeId, Transaction transaction, NodeCursor nodes) { bool retry; do { retry = false; _firstRelId = NO_SUCH_RELATIONSHIP; // lock all the nodes involved by following the node id ordering CollectAndSortNodeIds(nodeId, transaction, nodes); LockAllNodes(_sortedNodeIds); // perform the action on each relationship, we will retry if the the relationship iterator contains // new relationships [email protected] read = transaction.DataRead(); read.SingleNode(nodeId, nodes); //if the node is not there, someone else probably deleted it, just ignore if (nodes.Next()) { using (RelationshipSelectionCursor rels = RelationshipSelections.allCursor(transaction.Cursors(), nodes, null)) { bool first = true; while (rels.Next() && !retry) { retry = PerformAction(rels.RelationshipReference(), first); first = false; } } } } while (retry); }
public override void Source(NodeCursor cursor) { Read.singleNode(SourceNodeReference(), cursor); }
public override void Target(NodeCursor cursor) { Read.singleNode(TargetNodeReference(), cursor); }
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)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void validateNodePropertyExistenceConstraint(org.neo4j.internal.kernel.api.NodeLabelIndexCursor allNodes, org.neo4j.internal.kernel.api.NodeCursor nodeCursor, org.neo4j.internal.kernel.api.PropertyCursor propertyCursor, org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException public override void ValidateNodePropertyExistenceConstraint(NodeLabelIndexCursor allNodes, NodeCursor nodeCursor, PropertyCursor propertyCursor, LabelSchemaDescriptor descriptor) { throw PropertyExistenceConstraintsNotAllowed(descriptor); }
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); } }
internal CursorPropertyAccessor(NodeCursor nodeCursor, PropertyCursor propertyCursor, Read read) { this._nodeCursor = nodeCursor; this._propertyCursor = propertyCursor; this._read = read; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void validateNodePropertyExistenceConstraint(org.neo4j.internal.kernel.api.NodeLabelIndexCursor allNodes, org.neo4j.internal.kernel.api.NodeCursor nodeCursor, org.neo4j.internal.kernel.api.PropertyCursor propertyCursor, org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor descriptor) throws org.neo4j.internal.kernel.api.exceptions.schema.CreateConstraintFailureException public override void ValidateNodePropertyExistenceConstraint(NodeLabelIndexCursor allNodes, NodeCursor nodeCursor, PropertyCursor propertyCursor, LabelSchemaDescriptor descriptor) { while (allNodes.Next()) { allNodes.Node(nodeCursor); while (nodeCursor.Next()) { foreach (int propertyKey in descriptor.PropertyIds) { nodeCursor.Properties(propertyCursor); if (!HasProperty(propertyCursor, propertyKey)) { throw CreateConstraintFailure(new NodePropertyExistenceException(descriptor, VERIFICATION, nodeCursor.NodeReference())); } } } } }