private boolean nodeExists( long nodeId ) { try ( StorageNodeCursor node = allocateNodeCursor( nodeId ) ) { return node.next(); } }
@Override public void visitDeletedNode( long id ) { counts.incrementNodeCount( ANY_LABEL, -1 ); nodeCursor.single( id ); if ( nodeCursor.next() ) { decrementCountForLabelsAndRelationships( nodeCursor ); } super.visitDeletedNode( id ); }
private boolean nodeExists( long id ) { try ( StorageNodeCursor node = storageReader.allocateNodeCursor() ) { node.single( id ); return node.next(); } }
private Value committedValue( NodeState nodeState, int property, StorageNodeCursor node, StoragePropertyCursor properties ) { if ( state.nodeIsAddedInThisTx( nodeState.getId() ) ) { return Values.NO_VALUE; } node.single( nodeState.getId() ); if ( !node.next() ) { return Values.NO_VALUE; } return committedValue( properties, node.propertiesReference(), property ); }
@SuppressWarnings( "unchecked" ) private StorageNodeCursor newCursor( long nodeId ) { StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(); nodeCursor.single( nodeId ); assertTrue( nodeCursor.next() ); return nodeCursor; }
@Override public boolean next() { // Check tx state boolean hasChanges = hasChanges(); if ( hasChanges && addedNodes.hasNext() ) { storeCursor.setCurrent( addedNodes.next() ); return true; } while ( storeCursor.next() ) { if ( !hasChanges || !read.txState().nodeIsDeletedInThisTx( storeCursor.entityReference() ) ) { return true; } } return false; }
private void assertHasRelationships( long node ) { try ( KernelStatement statement = (KernelStatement) tx.acquireStatement(); StorageNodeCursor nodeCursor = allocateNodeCursor( node ) ) { assertTrue( nodeCursor.next() ); try ( StorageRelationshipTraversalCursor relationships = allocateRelationshipTraversalCursor( nodeCursor ) ) { assertTrue( relationships.next() ); } } }
if ( node.next() )
private void deleteRelationships( long nodeId ) { try ( KernelStatement statement = (KernelStatement) tx.acquireStatement(); StorageNodeCursor nodeCursor = allocateNodeCursor( nodeId ) ) { assertTrue( nodeCursor.next() ); try ( StorageRelationshipTraversalCursor relationships = allocateRelationshipTraversalCursor( nodeCursor ) ) { while ( relationships.next() ) { relDelete( relationships.entityReference() ); } } } }
@Override public void visitNodeLabelChanges( long id, final LongSet added, final LongSet removed ) throws ConstraintValidationException { // update counts if ( !(added.isEmpty() && removed.isEmpty()) ) { added.each( label -> counts.incrementNodeCount( label, 1 ) ); removed.each( label -> counts.incrementNodeCount( label, -1 ) ); // get the relationship counts from *before* this transaction, // the relationship changes will compensate for what happens during the transaction nodeCursor.single( id ); if ( nodeCursor.next() ) { visitDegrees( nodeCursor, ( type, out, in ) -> { added.forEach( label -> updateRelationshipsCountsFromDegrees( type, label, out, in ) ); removed.forEach( label -> updateRelationshipsCountsFromDegrees( type, label, -out, -in ) ); } ); } } super.visitNodeLabelChanges( id, added, removed ); }
if ( nodeCursor.next() )
@Test public void processAllNodeProperties() throws Exception { CopyUpdateVisitor propertyUpdateVisitor = new CopyUpdateVisitor(); StoreViewNodeStoreScan storeViewNodeStoreScan = new StoreViewNodeStoreScan( new RecordStorageReader( neoStores ), locks, null, propertyUpdateVisitor, new int[]{labelId}, id -> true ); try ( StorageNodeCursor nodeCursor = reader.allocateNodeCursor() ) { nodeCursor.single( 1 ); nodeCursor.next(); storeViewNodeStoreScan.process( nodeCursor ); } EntityUpdates propertyUpdates = propertyUpdateVisitor.getPropertyUpdates(); assertNotNull( "Visitor should contain container with updates.", propertyUpdates ); LabelSchemaDescriptor index1 = SchemaDescriptorFactory.forLabel( 0, 0 ); LabelSchemaDescriptor index2 = SchemaDescriptorFactory.forLabel( 0, 1 ); LabelSchemaDescriptor index3 = SchemaDescriptorFactory.forLabel( 0, 0, 1 ); LabelSchemaDescriptor index4 = SchemaDescriptorFactory.forLabel( 1, 1 ); List<LabelSchemaDescriptor> indexes = Arrays.asList( index1, index2, index3, index4 ); assertThat( Iterables.map( IndexEntryUpdate::indexKey, propertyUpdates.forIndexKeys( indexes ) ), containsInAnyOrder( index1, index2, index3 ) ); }
private StorageProperty nodeAddProperty( long nodeId, int key, Object value ) { StorageProperty property = new PropertyKeyValue( key, Values.of( value ) ); StorageProperty oldProperty = null; try ( StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor() ) { nodeCursor.single( nodeId ); if ( nodeCursor.next() ) { StorageProperty fetched = getProperty( key, nodeCursor.propertiesReference() ); if ( fetched != null ) { oldProperty = fetched; } } } if ( oldProperty == null ) { transaction.nodeDoAddProperty( nodeId, key, property.value() ); } else { transaction.nodeDoChangeProperty( nodeId, key, property.value() ); } return property; }
StorageNodeCursor nodeCursor = allocateNodeCursor( node ) ) assertTrue( nodeCursor.next() ); try ( StorageRelationshipTraversalCursor relationships = allocateRelationshipTraversalCursor( nodeCursor ) )
@Test public void shouldBeAbleToListLabelsForNode() throws Exception { // GIVEN long nodeId; int labelId1; int labelId2; try ( Transaction tx = db.beginTx() ) { nodeId = db.createNode( label1, label2 ).getId(); String labelName1 = label1.name(); String labelName2 = label2.name(); labelId1 = labelId( Label.label( labelName1 ) ); labelId2 = labelId( Label.label( labelName2 ) ); tx.success(); } // THEN StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(); nodeCursor.single( nodeId ); assertTrue( nodeCursor.next() ); assertEquals( newSetWith( labelId1, labelId2 ), newSetWith( nodeCursor.labels() ) ); }
StorageNodeCursor nodeCursor = allocateNodeCursor( node ) ) assertTrue( nodeCursor.next() ); try ( StorageRelationshipTraversalCursor relationships = allocateRelationshipTraversalCursor( nodeCursor ) )
assertTrue( node.next() );
@Override public void visitDeletedNode( long id ) { counts.incrementNodeCount( ANY_LABEL, -1 ); nodeCursor.single( id ); if ( nodeCursor.next() ) { decrementCountForLabelsAndRelationships( nodeCursor ); } super.visitDeletedNode( id ); }
private Value committedValue( NodeState nodeState, int property, StorageNodeCursor node, StoragePropertyCursor properties ) { if ( state.nodeIsAddedInThisTx( nodeState.getId() ) ) { return Values.NO_VALUE; } node.single( nodeState.getId() ); if ( !node.next() ) { return Values.NO_VALUE; } return committedValue( properties, node.propertiesReference(), property ); }
@Override public boolean next() { // Check tx state boolean hasChanges = hasChanges(); if ( hasChanges && addedNodes.hasNext() ) { storeCursor.setCurrent( addedNodes.next() ); return true; } while ( storeCursor.next() ) { if ( !hasChanges || !read.txState().nodeIsDeletedInThisTx( storeCursor.entityReference() ) ) { return true; } } return false; }