@Override public void close() { sourceIterator.close(); } }
@Override public void close() { source.close(); } }
@Override public void close() { paths.close(); } }
private void closeRelationshipsIterator() { if ( this.nextRelationships != null ) { this.nextRelationships.close(); } }
@Override public void close() { try { inner.close(); } catch ( CypherException e ) { throw converted( e ); } }
@Override public void close() { if ( currentNestedIterator != null ) { currentNestedIterator.close(); } } }
private void closeIterator() { if ( iterator != null ) { iterator.close(); iterator = null; } }
@Override public void close() { ResourceIterator.this.close(); }
@Override public void close() { iterator.close(); }
private void resetRelationships() { if ( relationships != null ) { relationships.close(); } relationships = Iterators.emptyResourceIterator(); }
public static <T> boolean contains( Iterator<T> iterator, T item ) { try { for ( T element : loop( iterator ) ) { if ( item == null ? element == null : item.equals( element ) ) { return true; } } return false; } finally { if ( iterator instanceof ResourceIterator<?> ) { ((ResourceIterator<?>) iterator).close(); } } }
/** * Counts the number of filtered items in the {@code iterable} by looping through it. * * @param <T> the type of items in the iterator. * @param iterable the {@link Iterable} to count items in. * @param filter the filter to test items against * @return the number of found in {@code iterable}. */ public static <T> long count( Iterable<T> iterable, Predicate<T> filter ) { Iterator<T> iterator = iterable.iterator(); try { return Iterators.count( iterator, filter ); } finally { if ( iterator instanceof ResourceIterator ) { ((ResourceIterator<?>) iterator).close(); } } }
@Override public void close() { try { // inner iterator might be null if this result was consumed using visitor if ( innerIterator != null ) { innerIterator.close(); } // but we still need to close the underlying extended execution result inner.close(); } catch ( CypherException e ) { throw converted( e ); } }
@Test void shouldNotCloseDuringIteration() { // Given ResourceIterator<Long> it1 = spy( asResourceIterator( iterator( 1L, 2L, 3L ) ) ); ResourceIterator<Long> it2 = spy( asResourceIterator( iterator( 5L, 6L, 7L ) ) ); CombiningResourceIterator<Long> combingIterator = new CombiningResourceIterator<>( iterator(it1, it2) ); // When I iterate through it, things come back in the right order assertThat( Iterators.asList( combingIterator ), equalTo(asList( 1L, 2L, 3L, 5L, 6L, 7L )) ); // Then verify(it1, never()).close(); verify(it2, never()).close(); }
@Test public void shouldCloseIndexAndLabelScanSnapshots() throws Exception { // Given LabelScanStore labelScanStore = mock( LabelScanStore.class ); IndexingService indexingService = mock( IndexingService.class ); ExplicitIndexProvider explicitIndexes = mock( ExplicitIndexProvider.class ); when( explicitIndexes.allIndexProviders() ).thenReturn( Collections.emptyList() ); DatabaseLayout databaseLayout = mock( DatabaseLayout.class ); when( databaseLayout.metadataStore() ).thenReturn( mock( File.class ) ); LogFiles logFiles = mock( LogFiles.class ); filesInStoreDirAre( databaseLayout, STANDARD_STORE_DIR_FILES, STANDARD_STORE_DIR_DIRECTORIES ); StorageEngine storageEngine = mock( StorageEngine.class ); NeoStoreFileListing fileListing = new NeoStoreFileListing( databaseLayout, logFiles, labelScanStore, indexingService, explicitIndexes, storageEngine ); ResourceIterator<File> scanSnapshot = scanStoreFilesAre( labelScanStore, new String[]{"blah/scan.store", "scan.more"} ); ResourceIterator<File> indexSnapshot = indexFilesAre( indexingService, new String[]{"schema/index/my.index"} ); ResourceIterator<StoreFileMetadata> result = fileListing.builder().excludeLogFiles().build(); // When result.close(); // Then verify( scanSnapshot ).close(); verify( indexSnapshot ).close(); }
@Test void closesAllIteratorsOnShutdown() { // Given ResourceIterator<Long> it1 = spy( asResourceIterator( iterator( 1L, 2L, 3L ) ) ); ResourceIterator<Long> it2 = spy( asResourceIterator( iterator( 5L, 6L, 7L ) ) ); CombiningResourceIterator<Long> combingIterator = new CombiningResourceIterator<>( iterator(it1, it2) ); // Given I iterate through half of it int iterations = 4; while ( iterations-- > 0 ) { combingIterator.next(); } // When combingIterator.close(); // Then verify(it1).close(); verify(it2).close(); }
@Test public void shouldCloseTransactionsWhenIteratingOverSingleColumn() { // Given an execution result that has been started but not exhausted createNode(); createNode(); Result executionResult = db.execute( "CYPHER runtime=interpreted MATCH (n) RETURN n" ); ResourceIterator<Node> resultIterator = executionResult.columnAs( "n" ); resultIterator.next(); assertThat( activeTransaction(), is( notNullValue() ) ); // When resultIterator.close(); // Then assertThat( activeTransaction(), is( nullValue() ) ); }
@Test public void shouldNotTrimStringsByDefault() throws Exception { // GIVEN String name = " This is a line with leading and trailing whitespaces "; File data = data( ":ID,name", "1,\"" + name + "\""); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", data.getAbsolutePath() ); // THEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { ResourceIterator<Node> allNodes = db.getAllNodes().iterator(); Node node = Iterators.single( allNodes ); allNodes.close(); assertEquals( name, node.getProperty( "name" ) ); tx.success(); } }
@Test public void shouldAllowMultilineFieldsWhenEnabled() throws Exception { // GIVEN File data = data( ":ID,name", "1,\"This is a line with\nnewlines in\"" ); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--multiline-fields", "true" ); // THEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { ResourceIterator<Node> allNodes = db.getAllNodes().iterator(); Node node = Iterators.single( allNodes ); allNodes.close(); assertEquals( "This is a line with\nnewlines in", node.getProperty( "name" ) ); tx.success(); } }