title: TupleQueryResult (result.hasNext()) decreasing performance
body: <p>I am using SPARQL queries to get RDF using java.</p>
  
  <p>My SPARQL query is running fine and I get the resultset and  when I started <code>while</code> loop, the <code>hasnext()</code> method decreasing the performance by taking too much time even for less records.</p>
  
  <p>I printed the logs and found <code>while (thisTermDataResult.hasNext()) {</code> is taking nearly 11000 ms which is not at all acceptable.</p>
  
  <p>SPARQL is also running fine. So what exactly doing <code>hasNext()</code> method from <code>TupleQueryResult</code> class. And do we have any alternative to iterate resultset of <code>TupleQueryResult</code></p>
  
  <p>I searched a lot on the internet for solution but no luck found.</p>
  
  <pre><code>thisTermDataTupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, thisTermDataQuery);
  thisTermDataResult = thisTermDataTupleQuery.evaluate();
  log.debug("#PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched at = "+ (System.currentTimeMillis() - initialTime));
  
  
  if (null != thisTermDataResult) {
      log.debug("#PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 1 = "+ (System.currentTimeMillis() - initialTime));
      while (thisTermDataResult.hasNext()) {
          log.debug("#PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 2 = "+ (System.currentTimeMillis() - initialTime));
          Map&lt;String, Object&gt; currentRecord = new LinkedHashMap&lt;String, Object&gt;();
          log.debug("#PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 3 = "+ (System.currentTimeMillis() - initialTime));
          BindingSet current = thisTermDataResult.next();
          log.debug("#PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 4 = "+ (System.currentTimeMillis() - initialTime));
          //logic
      }
  }
  </code></pre>
  
  <p><strong>Tha logs I have printed</strong></p>
  
  <pre><code>13:39:18.288 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# created a connection at = 1551
  13:39:18.297 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched at = 1560
  13:39:18.297 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 1 = 1560
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 2 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 3 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 4 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 5 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 6 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 7 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 8 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 9 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 10 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 11 = 11648
  13:39:28.385 DEBUG  c.l.u.p.plc.services.PLCServiceImpl - #PERF-getHouseAssessmentReview# thisTermDataTupleQuery# data fetched 12 = 11648
  </code></pre>