ResourceIterable (Neo4j Community 2.1.0-M01 API)
Date: 2014-02-20

org.neo4j.graphdb

## Interface ResourceIterable<T>

- Type Parameters:
    `T` - the type of values returned through the iterators
  All Superinterfaces:
    Iterable<T>
  All Known Subinterfaces:
    IndexHits<T>, Traverser
  All Known Implementing Classes:
    ExecutionResult

      public interface ResourceIterable<T>
      extends Iterable<T>

  `Iterable` whose `iterators` have associated resources that need to be released. `ResourceIterators` are always automatically released when their owning transaction is committed or rolled back. Inside a long running transaction, it is possible to release associated resources early. To do so you must ensure that all returned ResourceIterators are either fully exhausted, or explicitly closed.

  If you intend to exhaust the returned iterators, you can use conventional code as you would with a normal Iterable:

       ResourceIterable<Object> iterable;
       for ( Object item : iterable )
       {
           ...
       }

  However, if your code might not exhaust the iterator, (run until `Iterator.hasNext()` returns `false`), `ResourceIterator` provides you with a `ResourceIterator.close()` method that can be invoked to release its associated resources early, by using a `finally`-block, or try-with-resource.

       ResourceIterable<Object> iterable;
       ResourceIterator<Object> iterator = iterable.iterator();
       try
       {
           while ( iterator.hasNext() )
           {
               Object item = iterator.next();
               if ( ... )
               {
                   return item; // iterator may not be exhausted.
               }
           }
       }
       finally
       {
           iterator.close();
       }

  See Also:
    `ResourceIterator`, `Transaction`

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ResourceIterator<T>` | `iterator()` Returns an `iterator` with associated resources that may be managed.

- - ### Method Detail

    - #### iterator

          ResourceIterator<T> iterator()

      Returns an `iterator` with associated resources that may be managed.
      Specified by:
        `iterator` in interface `Iterable<T>`

Copyright © 2002–2014 The Neo4j Graph Database Project. All rights reserved.