/** * Creates new SELECT results metadata * * @param results * JDBC result set * @param rset * Underlying SPARQL results * @throws SQLException */ public SelectResultsMetadata(JenaResultSet results, ResultSet rset) throws SQLException { this(results, ResultSetFactory.makePeekable(rset)); }
/** * Creates new SELECT results metadata * * @param results * JDBC result set * @param rset * Underlying SPARQL results * @throws SQLException */ public SelectResultsMetadata(JenaResultSet results, ResultSet rset) throws SQLException { this(results, ResultSetFactory.makePeekable(rset)); }
/** * Creates new select results * * @param statement * Statement that created the result set * @param qe * Query Execution * @param results * SPARQL Results * @param commit * Whether a commit is necessary when the results are closed * @throws SQLException * Thrown if the arguments are invalid */ public SelectResults(JenaStatement statement, QueryExecution qe, org.apache.jena.query.ResultSet results, boolean commit) throws SQLException { this(statement, qe, ResultSetFactory.makePeekable(results), commit); }
/** * Creates new select results * * @param statement * Statement that created the result set * @param qe * Query Execution * @param results * SPARQL Results * @param commit * Whether a commit is necessary when the results are closed * @throws SQLException * Thrown if the arguments are invalid */ public SelectResults(JenaStatement statement, QueryExecution qe, org.apache.jena.query.ResultSet results, boolean commit) throws SQLException { this(statement, qe, ResultSetFactory.makePeekable(results), commit); }
private ResultSetPeekable make2Peekable(String var1, Node val1, String var2, Node val2) { ResultSet rs = make(var1, val1, var2, val2); ResultSetPeekable rsp = ResultSetFactory.makePeekable(rs); return rsp; } }
private ResultSetPeekable makePeekable(String var, Node val) { ResultSet rs = make(var, val); ResultSetPeekable rsp = ResultSetFactory.makePeekable(rs); return rsp; }
@Test public void test_RS_peeking_7() { // Peeking may fail if someone moves backwards in the result set // If we hadn't moved pass the first item this should be safe ResultSetRewindable inner = makeRewindable("x", NodeFactory.createURI("tag:local")); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Reset the inner result set independently inner.reset(); // Since we moved the underlying result set backwards but we hadn't gone anywhere // we should still be able to safely access the underlying results assertTrue(rs.hasNext()); }
@Test public void test_RS_peeking_5() { // Peeking should be able to cope with people moving on the underlying result set independently ResultSet inner = new ResultSetMem(make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local"))); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Move on the inner result set independently inner.next(); // Since we fiddled with the underlying result set there won't be further elements available anymore assertFalse(rs.hasNext()); }
@Test public void test_RS_peeking_6() { // Peeking should be able to cope with people moving on the underlying result set independently ResultSet inner = new ResultSetMem(make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local"))); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Move on the inner result set independently inner.next(); // Since we fiddled with the underlying result set we'll be out of sync // but there should still be further data available assertTrue(rs.hasNext()); }
@Test(expected=IllegalStateException.class) public void test_RS_peeking_8() { // Peeking may fail if someone moves backwards in the result set // If we had moved past the first item this should be an error ResultSetRewindable inner = new ResultSetMem(make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local"))); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); assertNotNull(rs.next()); // Reset the inner result set independently inner.reset(); // Since we moved the underlying result set backwards and had moved somewhere we // are now in an illegal state rs.hasNext(); }
@Test public void test_RS_peeking_9() { // Check that peeking causes the correct row to be returned when we actually access the rows Node first = NodeFactory.createURI("tag:first"); Node second = NodeFactory.createURI("tag:second"); Var x = Var.alloc("x"); ResultSet inner = new ResultSetMem(make("x", first), make("x", second)); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); // Peek and check row is as expected Binding peeked = rs.peekBinding(); assertNotNull(peeked); assertTrue(first.equals(peeked.get(x))); // Check first row is as expected Binding next = rs.nextBinding(); assertNotNull(next); assertTrue(first.equals(next.get(x))); // Repeat for second row peeked = rs.peekBinding(); assertNotNull(peeked); assertTrue(second.equals(peeked.get(x))); next = rs.nextBinding(); assertNotNull(next); assertTrue(second.equals(next.get(x))); }