public boolean hasNext() { if (cancelled) { throw new QueryCancelledException(); } if (explicitlyClosed) { return false; } if (prefetchedRow == null) { ensureQueryExecuted(); tryFetchNextRow(); } return prefetchedRow != null; }
private void ensureQueryExecuted() { if (this.queryExecuted) { return; } this.queryExecuted = true; log.info(sql); try { Connection con = this.database.connection(); this.statement = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); if (database.fetchSize() != Database.NO_FETCH_SIZE) { try { this.statement.setFetchSize(database.fetchSize()); } catch (SQLException e) {} /* Some drivers don't support fetch sizes, e.g. JDBC-ODBC */ } database.vendor().beforeExecuteQuery(con); this.resultSet = this.statement.executeQuery(this.sql); database.vendor().afterExecuteQuery(con); log.debug("SQL result set created"); } catch (SQLException ex) { if (cancelled) { log.debug("SQL query execution cancelled", ex); throw new QueryCancelledException(); } throw new D2RQException(ex.getMessage() + ": " + this.sql); } }
private void ensureQueryExecuted() { if (this.queryExecuted) { return; } this.queryExecuted = true; log.info(sql); BeanCounter.totalNumberOfExecutedSQLQueries++; try { Connection con = this.database.connection(); this.statement = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); if (database.fetchSize() != Database.NO_FETCH_SIZE) { try { this.statement.setFetchSize(database.fetchSize()); } catch (SQLException e) {} /* Some drivers don't support fetch sizes, e.g. JDBC-ODBC */ } this.resultSet = this.statement.executeQuery(this.sql); log.debug("SQL result set created"); this.numCols = this.resultSet.getMetaData().getColumnCount(); } catch (SQLException ex) { if (cancelled) { log.debug("SQL query execution cancelled", ex); throw new QueryCancelledException(); } throw new D2RQException(ex.getMessage() + ": " + this.sql); } }
@Override public Mapping nextMapping() { try { if (abortIterator) { throw new QueryCancelledException(); } if (finished) { // If abortIterator set after finished. if (abortIterator) { throw new QueryCancelledException(); } throw new NoSuchElementException(Utils.className(this)); } if (!hasNextMapping()) { throw new NoSuchElementException(Utils.className(this)); } Mapping obj = moveToNextMapping(); if (obj == null) { throw new NoSuchElementException(Utils.className(this)); } if (requestingCancel && !finished) { // But .cancel sets both requestingCancel and abortIterator // This only happens with a continuing iterator. close(); } return obj; } catch (QueryFatalException ex) { Log.fatal(this, "QueryFatalException", ex); //abort ? throw ex; } }