private static void singleNode( Read read, NodeCursor nodeCursor, long node ) throws EntityNotFoundException { read.singleNode( node, nodeCursor ); if ( !nodeCursor.next() ) { throw new EntityNotFoundException( EntityType.NODE, node ); } }
static int nodeGetDegreeIfDense( Read read, long node, NodeCursor nodeCursor, CursorFactory cursors, Direction direction ) { read.singleNode( node, nodeCursor ); if ( !nodeCursor.next() ) { return 0; } if ( !nodeCursor.isDense() ) { return NOT_DENSE_DEGREE; } return nodeGetDegree( nodeCursor, cursors, direction ); }
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.isDense() ) { return NOT_DENSE_DEGREE; } return nodeGetDegree( nodeCursor, cursors, direction, type ); }
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.isDense() ) { return NOT_DENSE_DEGREE; } return calculateTotalDegree( nodeCursor, direction, relTypes, cursors ); }
public static RelationshipSelectionCursor nodeGetRelationships( Read read, CursorFactory cursors, NodeCursor node, long nodeId, Direction direction, int[] types ) { read.singleNode( nodeId, node ); if ( !node.next() ) { return RelationshipSelectionCursor.EMPTY; } switch ( direction ) { case OUTGOING: return RelationshipSelections.outgoingCursor( cursors, node, types ); case INCOMING: return RelationshipSelections.incomingCursor( cursors, node, types ); case BOTH: return RelationshipSelections.allCursor( cursors, node, types ); default: throw new IllegalStateException( "Unknown direction " + direction ); } }
private void singleNode( KernelTransaction transaction, NodeCursor nodes ) { transaction.dataRead().singleNode( nodeId, nodes ); if ( !nodes.next() ) { throw new NotFoundException( new EntityNotFoundException( EntityType.NODE, nodeId ) ); } }
private ResourceIterator<Relationship> getRelationshipSelectionIterator( KernelTransaction transaction, Direction direction, int[] typeIds ) { NodeCursor node = transaction.ambientNodeCursor(); transaction.dataRead().singleNode( getId(), node ); if ( !node.next() ) { throw new NotFoundException( format( "Node %d not found", nodeId ) ); } switch ( direction ) { case OUTGOING: return outgoingIterator( transaction.cursors(), node, typeIds, this ); case INCOMING: return incomingIterator( transaction.cursors(), node, typeIds, this ); case BOTH: return allIterator( transaction.cursors(), node, typeIds, this ); default: throw new IllegalStateException( "Unknown direction " + direction ); } }
@Test public void shouldNotAccessNegativeReferences() { // given try ( NodeCursor node = cursors.allocateNodeCursor() ) { // when read.singleNode( -2L, node ); // then assertFalse( "should not access negative reference node", node.next() ); } }
@Test public void shouldNotFindDeletedNode() { // given try ( NodeCursor nodes = cursors.allocateNodeCursor() ) { // when read.singleNode( gone, nodes ); // then assertFalse( "should not access deleted node", nodes.next() ); } }
@Override public boolean hasLabel( Label label ) { KernelTransaction transaction = safeAcquireTransaction(); NodeCursor nodes = transaction.ambientNodeCursor(); try ( Statement ignore = transaction.acquireStatement() ) { int labelId = transaction.tokenRead().nodeLabel( label.name() ); if ( labelId == NO_SUCH_LABEL ) { return false; } transaction.dataRead().singleNode( nodeId, nodes ); return nodes.next() && nodes.hasLabel( labelId ); } }
@Test public void shouldHaveBeenAbleToCreateDenseAndSparseNodes() { // given try ( NodeCursor node = cursors.allocateNodeCursor() ) { read.singleNode( dense.id, node ); assertTrue( "access dense node", node.next() ); assertTrue( "dense node", node.isDense() ); read.singleNode( sparse.id, node ); assertTrue( "access sparse node", node.next() ); assertFalse( "sparse node", node.isDense() && supportsSparseNodes() ); } }
private Value getPropertyValueFromStore( long nodeReference ) { try ( NodeCursor storeCursor = cursors.allocateNodeCursor(); PropertyCursor propertyCursor = cursors.allocatePropertyCursor() ) { read.singleNode( nodeReference, storeCursor ); storeCursor.next(); storeCursor.properties( propertyCursor ); propertyCursor.next(); return propertyCursor.propertyValue(); } }
private void assertNoNode( long nodeId ) throws TransactionFailureException { try ( Transaction tx = beginTransaction(); NodeCursor cursor = tx.cursors().allocateNodeCursor() ) { tx.dataRead().singleNode( nodeId, cursor ); assertFalse( cursor.next() ); } } }
@Test public void shouldNotAccessGroupsOfBareNode() { // given try ( NodeCursor node = cursors.allocateNodeCursor(); RelationshipGroupCursor group = cursors.allocateRelationshipGroupCursor() ) { // when read.singleNode( bare, node ); assertTrue( "access node", node.next() ); node.relationships( group ); // then assertFalse( "access group", group.next() ); } }
@Test public void shouldAccessNodesByReference() { // given try ( NodeCursor nodes = cursors.allocateNodeCursor() ) { for ( long id : NODE_IDS ) { // when read.singleNode( id, nodes ); // then assertTrue( "should access defined node", nodes.next() ); assertEquals( "should access the correct node", id, nodes.nodeReference() ); assertFalse( "should only access a single node", nodes.next() ); } } }
@Test public void shouldAccessNodesByReference() { // given try ( NodeCursor nodes = cursors.allocateNodeCursor() ) { for ( long id : NODE_IDS ) { // when read.singleNode( id, nodes ); // then assertTrue( "should access defined node", nodes.next() ); assertEquals( "should access the correct node", id, nodes.nodeReference() ); assertFalse( "should only access a single node", nodes.next() ); } } } }
@Test public void txReturnsCorrectIdWhenReadOnly() throws Exception { executeDummyTxs( db, 42 ); org.neo4j.internal.kernel.api.Transaction tx = newTransaction(); try ( NodeCursor node = tx.cursors().allocateNodeCursor() ) { tx.dataRead().singleNode( 1, node ); node.next(); } tx.success(); assertEquals( KernelTransaction.READ_ONLY, tx.closeTransaction() ); assertFalse( tx.isOpen() ); }
@Test public void shouldDiscoverDeletedNodeInTransaction() throws Exception { long nodeId; try ( Transaction tx = beginTransaction() ) { nodeId = tx.dataWrite().nodeCreate(); tx.success(); } try ( Transaction tx = beginTransaction() ) { assertTrue( tx.dataWrite().nodeDelete( nodeId ) ); try ( NodeCursor node = tx.cursors().allocateNodeCursor() ) { tx.dataRead().singleNode( nodeId, node ); assertFalse( node.next() ); } tx.success(); } }
@Test public void shouldNotAccessNonExistentProperties() { // given try ( NodeCursor node = cursors.allocateNodeCursor(); PropertyCursor props = cursors.allocatePropertyCursor() ) { // when read.singleNode( bare, node ); assertTrue( "node by reference", node.next() ); assertFalse( "no properties", hasProperties( node, props ) ); node.properties( props ); assertFalse( "no properties by direct method", props.next() ); read.nodeProperties( node.nodeReference(), node.propertiesReference(), props ); assertFalse( "no properties via property ref", props.next() ); assertFalse( "only one node", node.next() ); } }
@Test public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedNode() throws Exception { try ( Transaction tx = beginTransaction() ) { long node = tx.dataWrite().nodeCreate(); try ( NodeCursor cursor = tx.cursors().allocateNodeCursor(); PropertyCursor props = tx.cursors().allocatePropertyCursor() ) { tx.dataRead().singleNode( node, cursor ); assertTrue( cursor.next() ); assertFalse( hasProperties( cursor, props ) ); tx.dataWrite().nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ), stringValue( "foo" ) ); assertTrue( hasProperties( cursor, props ) ); } } }