/** * @return {@link LabelScanReader} capable of finding node ids with given label ids. * Readers will immediately see updates made by {@link LabelScanWriter}, although {@link LabelScanWriter} * may internally batch updates so functionality isn't reliable. The only given is that readers will * see at least updates from closed {@link LabelScanWriter writers}. */ @Override public LabelScanReader newReader() { return new NativeLabelScanReader( index ); }
/** * Closes all currently open {@link RawCursor cursors} from last query method call. */ @Override public void close() { try { ensureOpenCursorsClosed(); } catch ( IOException e ) { throw new UncheckedIOException( e ); } }
@Override public PrimitiveLongResourceIterator nodesWithAnyOfLabels( long fromId, int... labelIds ) { List<PrimitiveLongResourceIterator> iterators = iteratorsForLabels( fromId, labelIds ); return new CompositeLabelScanValueIterator( iterators, false ); }
@Test public void shouldCloseUnexhaustedCursorsOnReaderClose() throws Exception { // GIVEN GBPTree<LabelScanKey,LabelScanValue> index = mock( GBPTree.class ); RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor1 = mock( RawCursor.class ); when( cursor1.next() ).thenReturn( false ); RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor2 = mock( RawCursor.class ); when( cursor2.next() ).thenReturn( false ); when( index.seek( any( LabelScanKey.class ), any( LabelScanKey.class ) ) ).thenReturn( cursor1, cursor2 ); // WHEN try ( NativeLabelScanReader reader = new NativeLabelScanReader( index ) ) { // first check test invariants reader.nodesWithLabel( LABEL_ID ); reader.nodesWithLabel( LABEL_ID ); verify( cursor1, never() ).close(); verify( cursor2, never() ).close(); } // THEN verify( cursor1, times( 1 ) ).close(); verify( cursor2, times( 1 ) ).close(); }
@Override public PrimitiveLongResourceIterator nodesWithLabel( int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } return new LabelScanValueIterator( cursor, openCursors, NO_ID ); }
try ( NativeLabelScanReader reader = new NativeLabelScanReader( index ) ) LongIterator first = reader.nodesWithLabel( LABEL_ID ); LongIterator second = reader.nodesWithLabel( LABEL_ID );
private List<PrimitiveLongResourceIterator> iteratorsForLabels( long fromId, int[] labelIds ) { List<PrimitiveLongResourceIterator> iterators = new ArrayList<>(); try { for ( int labelId : labelIds ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor = seekerForLabel( fromId, labelId ); openCursors.add( cursor ); iterators.add( new LabelScanValueIterator( cursor, openCursors, fromId ) ); } } catch ( IOException e ) { throw new UncheckedIOException( e ); } return iterators; }
/** * @return {@link LabelScanReader} capable of finding node ids with given label ids. * Readers will immediately see updates made by {@link LabelScanWriter}, although {@link LabelScanWriter} * may internally batch updates so functionality isn't reliable. The only given is that readers will * see at least updates from closed {@link LabelScanWriter writers}. */ @Override public LabelScanReader newReader() { return new NativeLabelScanReader( index ); }
@Override public void nodesWithLabel( IndexProgressor.NodeLabelClient client, int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } client.scan( new LabelScanValueIndexProgressor( cursor, openCursors, client ), false, labelId ); }
@Override public PrimitiveLongResourceIterator nodesWithAllLabels( int... labelIds ) { List<PrimitiveLongResourceIterator> iterators = iteratorsForLabels( NO_ID, labelIds ); return new CompositeLabelScanValueIterator( iterators, true ); }
/** * Closes all currently open {@link RawCursor cursors} from last query method call. */ @Override public void close() { try { ensureOpenCursorsClosed(); } catch ( IOException e ) { throw new UncheckedIOException( e ); } }
@Override public PrimitiveLongResourceIterator nodesWithLabel( int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } return new LabelScanValueIterator( cursor, openCursors, NO_ID ); }
@Override public PrimitiveLongResourceIterator nodesWithAnyOfLabels( long fromId, int... labelIds ) { List<PrimitiveLongResourceIterator> iterators = iteratorsForLabels( fromId, labelIds ); return new CompositeLabelScanValueIterator( iterators, false ); }
private List<PrimitiveLongResourceIterator> iteratorsForLabels( long fromId, int[] labelIds ) { List<PrimitiveLongResourceIterator> iterators = new ArrayList<>(); try { for ( int labelId : labelIds ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor = seekerForLabel( fromId, labelId ); openCursors.add( cursor ); iterators.add( new LabelScanValueIterator( cursor, openCursors, fromId ) ); } } catch ( IOException e ) { throw new UncheckedIOException( e ); } return iterators; }
@Override public PrimitiveLongResourceIterator nodesWithAllLabels( int... labelIds ) { List<PrimitiveLongResourceIterator> iterators = iteratorsForLabels( NO_ID, labelIds ); return new CompositeLabelScanValueIterator( iterators, true ); }
@Override public void nodesWithLabel( IndexProgressor.NodeLabelClient client, int labelId ) { RawCursor<Hit<LabelScanKey,LabelScanValue>,IOException> cursor; try { cursor = seekerForLabel( 0, labelId ); openCursors.add( cursor ); } catch ( IOException e ) { throw new UncheckedIOException( e ); } client.scan( new LabelScanValueIndexProgressor( cursor, openCursors, client ), false, labelId ); }