@Override public void close() { if (scrollableCursor != null) { scrollableCursor.close(); } } }
@Override public boolean hasNext() { return scrollableCursor != null && scrollableCursor.hasNext(); }
@Override public T next() { if (scrollableCursor == null) { throw new NoSuchElementException("No ScrollableCursor"); } return (T) scrollableCursor.next(); }
/** * PUBLIC: * Moves the cursor to the end of the result set, just after the last row. */ public void afterLast() throws DatabaseException { clearNextAndPrevious(); try { this.resultSet.afterLast(); setPosition(size() + 1); } catch (SQLException exception) { DatabaseException commException = getAccessor().processExceptionForCommError(this.session, exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, getAccessor(), this.session, false); } }
/** * INTERNAL: * Read the next row from the result set. */ protected Object retrieveNextObject() throws DatabaseException { while (true) { if (getPosition() < getObjectCollection().size()) { setPosition(getPosition() + 1); return getObjectCollection().elementAt(getPosition() - 1); } if (isClosed()) { return null; } AbstractRecord row = getAccessor().cursorRetrieveNextRow(getFields(), getResultSet(), getExecutionSession()); if (row == null) { // If already afterLast do not increment position again. setPosition(size() + 1); return null; } setPosition(getPosition() + 1); Object object = buildAndRegisterObject(row); if (object == InvalidObject.instance) { continue; } return object; } }
/** * PUBLIC: * Moves the cursor to the front of the result set, just before the first row */ public void beforeFirst() throws DatabaseException { clearNextAndPrevious(); try { getResultSet().beforeFirst(); setPosition(0); } catch (SQLException exception) { DatabaseException commException = getAccessor().processExceptionForCommError(getSession(), exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, getAccessor(), getSession(), false); } }
clearNextAndPrevious(); try { boolean suceeded = false; int initiallyConforming = getObjectCollection().size(); if ((rows >= 0) && (rows <= initiallyConforming)) { getResultSet().beforeFirst(); setPosition(rows); return true; } else if (rows > initiallyConforming) { suceeded = getResultSet().absolute(rows - initiallyConforming); if (suceeded) { setPosition(initiallyConforming + rows); } else { setPosition(size() + 1); return absolute(size() + rows); DatabaseException commException = getAccessor().processExceptionForCommError(getSession(), exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, getAccessor(), getSession(), false);
int currentPosition = getPosition(); if (currentPosition <= (this.objectCollection.size() + 1)) { if ((currentPosition == (this.objectCollection.size() + 1)) && (!isClosed())) { getAccessor().cursorRetrievePreviousRow(this.fields, this.resultSet, this.executionSession); if (isClosed()) { return null; row = getAccessor().cursorRetrievePreviousRow(this.fields, this.resultSet, this.executionSession); } else { row = this.previousRow; Object object = buildAndRegisterObject(row);
clearNextAndPrevious(); try { boolean suceeded = false; int oldPosition = getPosition(); int newPosition = getPosition() + rows; int initiallyConforming = getObjectCollection().size(); if (newPosition <= initiallyConforming) { setPosition(newPosition); if (oldPosition > initiallyConforming) { getResultSet().beforeFirst(); setPosition(0); suceeded = getResultSet().relative(rows); if (!suceeded) { setPosition(size() + 1); } else { setPosition(newPosition); DatabaseException commException = getAccessor().processExceptionForCommError(getSession(), exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, getAccessor(), getSession(), false);
/** * Retrieve next object from the scrollable cursor */ public Transporter scrollableCursorNextObject(Transporter remoteScrollableCursorOid) { Transporter transporter = new Transporter(); try { ScrollableCursor stream = (ScrollableCursor)getRemoteCursors().get(remoteScrollableCursorOid.getObject()); if (stream != null) { Object objectNext = null; // For bug 2797683 read beyond end of stream exception should not be thrown here: called first by RemoteScrollableCursor.hasNext(). if (stream.hasNext()) { objectNext = stream.next(); } if (objectNext == null) { // 2612538 - the default size of Map (32) is appropriate transporter.setObjectDescriptors(new IdentityHashMap()); } else { if (stream.getQuery().isReadAllQuery() && (!stream.getQuery().isReportQuery())) { transporter.setObjectDescriptors(replaceValueHoldersIn(objectNext)); } } transporter.setObject(objectNext); } } catch (RuntimeException exception) { transporter.setException(exception); } return transporter; }
ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Employee.class); query.setSelectionCriteria(new ExpressionBuilder.get("id").greaterThan(100)); // Set the JDBC fetch size query.setFetchSize(50); // Configure the query to return results as a ScrollableCursor query.useScrollableCursor(); // Execute the query ScrollableCursor cursor = (ScrollableCursor) session.executeQuery(query); // Iterate over the results while (cursor.hasNext()) { System.out.println(cursor.next().toString()); } cursor.close();
/** * PUBLIC: * Moves the cursor to the front of the result set, just before the first row */ public void beforeFirst() throws DatabaseException { clearNextAndPrevious(); try { this.resultSet.beforeFirst(); setPosition(0); } catch (SQLException exception) { DatabaseException commException = getAccessor().processExceptionForCommError(this.session, exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, getAccessor(), this.session, false); } }
/** * PUBLIC: * Moves the cursor to the last row in the result set */ public boolean last() throws DatabaseException { clearNextAndPrevious(); try { boolean isLast = this.resultSet.last(); if (!isLast) { // cursor must be empty. if (this.objectCollection.size() > 0) { setPosition(this.objectCollection.size()); isLast = true; } } else { setSize(this.objectCollection.size() + this.resultSet.getRow()); setPosition(size); } return isLast; } catch (SQLException exception) { DatabaseException commException = getAccessor().processExceptionForCommError(this.session, exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, getAccessor(), this.session, false); } }
/** * PUBLIC: * Return the previous object from the collection. * * @return - previous object in stream * @exception - throws exception if read pass first of stream */ public Object previous() throws DatabaseException, QueryException { // CR#4139 loadPrevious(); if (getPreviousObject() == null) { throw QueryException.readBeyondStream(getQuery()); } Object previous = getPreviousObject(); clearNextAndPrevious(); return previous; }
/** * PUBLIC: * This method differs slightly from conventinal read() operation on a Java stream. This * method return the next object in the collection rather than specifying the number of * bytes to be read in. * * Return the next object from the collection, if beyond the read limit read from the cursor * @return - next object in stream * @exception - throws exception if read pass end of stream */ public Object next() throws DatabaseException, QueryException { loadNext(); if (getNextObject() == null) { throw QueryException.readBeyondStream(getQuery()); } Object next = getNextObject(); clearNextAndPrevious(); return next; }
/** * PUBLIC: * Retrieves the previous row index (against the current row) */ public int previousIndex() throws DatabaseException { return currentIndex() - 1; }
/** * INTERNAL: * Execute the cursored select and build the stream. */ public Object execute() { DatabaseCall call = getQuery().getQueryMechanism().cursorSelectAllRows(); // Create cursored stream ScrollableCursor cursor = new ScrollableCursor(call, this); return cursor; }
/** * Moves the cursor to the front of the result set, just before the first row */ public Transporter scrollableCursorBeforeFirst(Transporter remoteScrollableCursorOid) { Transporter transporter = new Transporter(); try { ScrollableCursor stream = (ScrollableCursor)getRemoteCursors().get(remoteScrollableCursorOid.getObject()); if (stream != null) { stream.beforeFirst(); } } catch (RuntimeException exception) { transporter.setException(exception); } return transporter; }
/** * Moves the cursor to the end of the result set, just after the last row. */ public Transporter scrollableCursorAfterLast(Transporter remoteScrollableCursorOid) { Transporter transporter = new Transporter(); try { ScrollableCursor stream = (ScrollableCursor)getRemoteCursors().get(remoteScrollableCursorOid.getObject()); if (stream != null) { stream.afterLast(); } } catch (RuntimeException exception) { transporter.setException(exception); } return transporter; }
/** * Moves the cursor to the given row number in the result set */ public Transporter scrollableCursorAbsolute(Transporter remoteScrollableCursorOid, int rows) { Transporter transporter = new Transporter(); try { ScrollableCursor stream = (ScrollableCursor)getRemoteCursors().get(remoteScrollableCursorOid.getObject()); if (stream != null) { transporter.setObject(new Boolean(stream.absolute(rows))); } else { transporter.setObject(new Boolean(false)); } } catch (RuntimeException exception) { transporter.setException(exception); } return transporter; }