You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Jeremy Carroll <je...@topquadrant.com> on 2012/08/16 07:40:08 UTC

MultiUnion multiGraphFind - closing iterators after exception

(From Jena 2.7.2)

I suggest replacing:

  /**
          Answer the concatenation of all the iterators from 
a-subGraph.find( t ).
     */
     private ExtendedIterator<Triple> multiGraphFind( final TripleMatch t )
         {
         Set<Triple> seen = CollectionFactory.createHashedSet();
         ExtendedIterator<Triple> result = NullIterator.instance();
         for (Iterator<Graph> graphs = m_subGraphs.iterator(); 
graphs.hasNext(); )
             {
             ExtendedIterator<Triple> newTriples = recording( rejecting( 
graphs.next().find( t ), seen ), seen );
             result = result.andThen( newTriples );
             }
         return result;
         }


With:

/**
          Answer the concatenation of all the iterators from 
a-subGraph.find( t ).
      */
     private ExtendedIterator<Triple> multiGraphFind( final TripleMatch t )
     {
         Set<Triple> seen = CollectionFactory.createHashedSet();
         ExtendedIterator<Triple> result = NullIterator.instance();
         boolean finished = false;
         try {
             for (Iterator<Graph> graphs = m_subGraphs.iterator(); 
graphs.hasNext(); )
             {
                 ExtendedIterator<Triple> newTriples = recording( 
rejecting( graphs.next().find( t ), seen ), seen );
                 result = result.andThen( newTriples );
             }
             finished = true;
             return result;
         }
         finally {
             if (!finished) {
                 result.close();
             }

         }
     }


I have had the case that an exception in the 2nd or 3rd 
graphs.next().find(t) then leaves 1st iterator open.

Jeremy

Re: MultiUnion multiGraphFind - closing iterators after exception

Posted by Andy Seaborne <an...@apache.org>.
Jeremy,

Could you put these (this and the ResourceImpl suggestion) on JIRA as 
patches?

	thanks,
	Andy

https://issues.apache.org/jira/browse/JENA

On 16/08/12 06:40, Jeremy Carroll wrote:
>
> (From Jena 2.7.2)
>
> I suggest replacing:
>
>   /**
>           Answer the concatenation of all the iterators from
> a-subGraph.find( t ).
>      */
>      private ExtendedIterator<Triple> multiGraphFind( final TripleMatch t )
>          {
>          Set<Triple> seen = CollectionFactory.createHashedSet();
>          ExtendedIterator<Triple> result = NullIterator.instance();
>          for (Iterator<Graph> graphs = m_subGraphs.iterator();
> graphs.hasNext(); )
>              {
>              ExtendedIterator<Triple> newTriples = recording( rejecting(
> graphs.next().find( t ), seen ), seen );
>              result = result.andThen( newTriples );
>              }
>          return result;
>          }
>
>
> With:
>
> /**
>           Answer the concatenation of all the iterators from
> a-subGraph.find( t ).
>       */
>      private ExtendedIterator<Triple> multiGraphFind( final TripleMatch t )
>      {
>          Set<Triple> seen = CollectionFactory.createHashedSet();
>          ExtendedIterator<Triple> result = NullIterator.instance();
>          boolean finished = false;
>          try {
>              for (Iterator<Graph> graphs = m_subGraphs.iterator();
> graphs.hasNext(); )
>              {
>                  ExtendedIterator<Triple> newTriples = recording(
> rejecting( graphs.next().find( t ), seen ), seen );
>                  result = result.andThen( newTriples );
>              }
>              finished = true;
>              return result;
>          }
>          finally {
>              if (!finished) {
>                  result.close();
>              }
>
>          }
>      }
>
>
> I have had the case that an exception in the 2nd or 3rd
> graphs.next().find(t) then leaves 1st iterator open.
>
> Jeremy