/** * Gets whether there are further rows in the underlying SELECT results */ @Override protected boolean hasNext() throws SQLException { // No null check here because superclass will not call us after we are // closed and set to null try { return this.innerResults.hasNext(); } catch (QueryCancelledException e) { throw new SQLException("Query was cancelled, it is likely that your query exceeded the specified execution timeout", e); } catch (Throwable e) { // Wrap as SQL exception throw new SQLException("Unexpected error while moving through results", e); } }
/** * Gets the next row from the underlying SELECT results */ @Override protected Binding moveNext() throws SQLException { // No null check here because superclass will not call us after we are // closed and set to null try { return this.innerResults.nextBinding(); } catch (QueryCancelledException e) { throw new SQLException("Query was cancelled, it is likely that your query exceeded the specified execution timeout", e); } catch (Throwable e) { // Wrap as SQL exception throw new SQLException("Unexpected error while moving through results", e); } } }
@Test(expected=NoSuchElementException.class) public void test_RS_peeking_4() { // Expect that a rewindable result set will be peekable ResultSetPeekable rs = (ResultSetPeekable) makeRewindable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); // Peeking beyond end of results throws an error rs.peek(); }
@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))); }
List<String> vars = rset.getResultVars(); ColumnInfo[] columns = new ColumnInfo[vars.size()]; if (rset.hasNext()) { b = rset.peekBinding(); } else {
@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()); }
/** * 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, ResultSetPeekable results, boolean commit) throws SQLException { super(statement, qe, commit); if (results == null) throw new SQLException("SPARQL Results cannot be null"); this.innerResults = results; this.columns = new ArrayList<String>(this.innerResults.getResultVars()); this.metadata = statement.getJenaConnection().applyPostProcessors(new SelectResultsMetadata(this, this.innerResults)); }
@Test(expected=NoSuchElementException.class) public void test_RS_peeking_2() { ResultSetPeekable rs = makePeekable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); // Peeking beyond end of results throws an error rs.peek(); }
List<String> vars = rset.getResultVars(); ColumnInfo[] columns = new ColumnInfo[vars.size()]; if (rset.hasNext()) { b = rset.peekBinding(); } else {
@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()); }
/** * 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, ResultSetPeekable results, boolean commit) throws SQLException { super(statement, qe, commit); if (results == null) throw new SQLException("SPARQL Results cannot be null"); this.innerResults = results; this.columns = new ArrayList<String>(this.innerResults.getResultVars()); this.metadata = statement.getJenaConnection().applyPostProcessors(new SelectResultsMetadata(this, this.innerResults)); }
@Test public void test_RS_peeking_1() { ResultSetPeekable rs = makePeekable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); 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()); }
/** * Gets whether there are further rows in the underlying SELECT results */ @Override protected boolean hasNext() throws SQLException { // No null check here because superclass will not call us after we are // closed and set to null try { return this.innerResults.hasNext(); } catch (QueryCancelledException e) { throw new SQLException("Query was cancelled, it is likely that your query exceeded the specified execution timeout", e); } catch (Throwable e) { // Wrap as SQL exception throw new SQLException("Unexpected error while moving through results", e); } }
/** * Gets the next row from the underlying SELECT results */ @Override protected Binding moveNext() throws SQLException { // No null check here because superclass will not call us after we are // closed and set to null try { return this.innerResults.nextBinding(); } catch (QueryCancelledException e) { throw new SQLException("Query was cancelled, it is likely that your query exceeded the specified execution timeout", e); } catch (Throwable e) { // Wrap as SQL exception throw new SQLException("Unexpected error while moving through results", e); } } }
@Test public void test_RS_peeking_3() { // Expect that a rewindable result set will be peekable ResultSetPeekable rs = (ResultSetPeekable)makeRewindable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(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(); }