Skip to content

Commit

Permalink
[ issue #40 ] Better state machine management on DeepPagingIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Gazzarini committed Mar 17, 2015
1 parent dc0284f commit 500ae52
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,8 @@ public boolean hasNext() {
}

@Override
public QuerySolution next() {
while (getRowNumber() < offset && resultSet.hasNext()) {
resultSet.nextBinding();
}

if (resultSet.getRowNumber() >= offset && getRowNumber() < (offset + size) && resultSet.hasNext()){
public QuerySolution next() {
if (resultSet.getRowNumber() >= offset && getRowNumber() < (offset + size)){
final QuerySolution solution = resultSet.nextSolution();
rows.add(solution);
return solution;
Expand Down Expand Up @@ -191,6 +187,18 @@ public int size() {
// This is because we need to trigger a request to Solr in order to collect DocSet (e.g. for faceting)
resultSet.next();
currentState = new CachedResultSet();
} else {
if (offset > 0) {
while (resultSet.hasNext() && resultSet.getRowNumber() < offset) {
resultSet.nextBinding();
}

// Sanity check: if offset is greater than the available
// rows then the resulting ResultSet must be empty
if (!resultSet.hasNext()) {
currentState = new CachedResultSet();
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import java.util.Arrays;
import java.util.List;

import org.apache.jena.riot.RDFLanguages;
import org.apache.jena.riot.resultset.ResultSetLang;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
Expand Down Expand Up @@ -75,12 +73,6 @@ public class LearningSparql_ITCase {
static SolrServer solr;
static final List<MisteryGuest> DATA = new ArrayList<MisteryGuest>();

public static void main(String[] args) {
ResultSetLang.init();
System.out.println(RDFLanguages.contentTypeToLang("application/sparql-results+json"));
System.out.println(RDFLanguages.contentTypeToLang("application/sparql-results+xml"));
}

/**
* Fills the data and queries map.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ public void sizeGreaterThanEffectiveSize() {
public void outOfAvailableRange() {
final ResultSetRewindable cut = new PagedResultSet(executeQuery(), 10, (int)(model.size() + 1));

try {
while (cut.hasNext()) {
cut.next();
}
fail();
} catch (IllegalStateException expected) {
// Nothing, this is the expected behaviour
}
while (cut.hasNext()) {
cut.next();
}

assertEquals(0, cut.size());

cut.reset();

assertEquals(0, cut.size());
}

/**
Expand Down

0 comments on commit 500ae52

Please sign in to comment.