Top Description Fields Constructors Methods
org.eclipse.persistence.queries

public Class CursoredStream

extends Cursor
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.internal.sessions.remote.RemoteCursoredStream
Imports
java.util.*, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.expressions.*, org.eclipse.persistence.internal.queries.*, org.eclipse.persistence.internal.sessions.AbstractRecord, org.eclipse.persistence.internal.expressions.*, org.eclipse.persistence.internal.databaseaccess.*, org.eclipse.persistence.internal.helper.*

Purpose: Stream class which is used to deal with large collections returned from TOPLink queries more efficiently.

Responsibilities: Wraps a database result set cursor to provide a stream on the resulting selected objects.

Author
Yvon Lavoie
Since
TOPLink/Java 1.0

Field Summary

Modifier and TypeField and Description
protected int
marker

Marker for backing up.

Inherited from org.eclipse.persistence.queries.Cursor:
executionSessionfieldsinitiallyConformingIndexnextRowobjectCollectionpolicypositionqueryresultSetselectionCriteriaClonesessionsizestatementtranslationRow

Constructor Summary

AccessConstructor and Description
public
CursoredStream()

INTERNAL: Initialize the state of the stream

public
CursoredStream(DatabaseCall call, CursoredStreamPolicy policy)

INTERNAL: Initialize the state of the stream

Method Summary

Modifier and TypeMethod and Description
public boolean
atEnd()

PUBLIC: Return whether the cursored stream is at its end.

public int
available()

PUBLIC: Returns the number of objects that can be read from this input without blocking.

public Expression
buildCountDistinctExpression(List<E> includeFields, ExpressionBuilder builder)

INTERNAL: Must build the count on the primary key fields, not * as * is not allowed if there was a distinct.

public void
clear()

Overrides org.eclipse.persistence.queries.Cursor.clear.

PUBLIC: Release all objects read in so far.
protected List<Object>
copy(int startIndex, int endIndex)

INTERNAL: Answer a list of the elements of the receiver's collection from startIndex to endIndex.

protected int
getCursorSize()

Implements abstract org.eclipse.persistence.queries.Cursor.getCursorSize.

INTERNAL: Retrieve the size of the open cursor by executing a count on the same query as the cursor.
protected int
getInitialReadSize()

INTERNAL: Return the threshold for the stream.

protected int
getMarker()

INTERNAL: Return the marker used for mark() & reset() operations.

public int
getPageSize()

Overrides org.eclipse.persistence.queries.Cursor.getPageSize.

INTERNAL: Return the page size for the stream.
public int
getPosition()

Implements abstract org.eclipse.persistence.queries.Cursor.getPosition.

INTERNAL: Return the position of the stream inside the object collection
public boolean
hasMoreElements()

Implements java.util.Enumeration.hasMoreElements.

PUBLIC: Return whether the cursored stream has any more elements.
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

PUBLIC: Return whether the cursored stream has any more elements.
public void
mark(int
Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from the database, there is no actual limit, so this argument is ignored.
readAheadLimit
)

PUBLIC: Mark the present position in the stream.

public boolean
markSupported()

PUBLIC: Tests if this input stream supports the mark and reset methods.

public Object

Returns:

the next object in stream
next
()

Implements java.util.Iterator.next.

PUBLIC: Return the next object from the collection, if beyond the read limit read from the cursor.
public List<Object>

Returns:

the next objects in stream
next
(int numberOfElements)

PUBLIC: Return a Vector of at most numberOfElements of the next objects from the collection.

public Object

Returns:

the next object in stream
nextElement
()

Implements java.util.Enumeration.nextElement.

PUBLIC: Return the next object from the collection, if beyond the read limit read from the cursor.
public Vector<E>

Returns:

the next objects in stream
nextElements
(int numberOfElements)

PUBLIC: Return a Vector of at most numberOfElements of the next objects from the collection.

public Object
peek()

PUBLIC: Return the next object in the stream, without incrementing the stream's position.

public Object

Returns:

- next object in stream
read
()

PUBLIC: This method differs slightly from conventional read() operation on a Java stream.

public List<Object>

Returns:

- vector containing next number of objects
read
(int
- number of objects to be returned
number
)

PUBLIC: This method differs slightly from conventional read() operation on a Java stream.

public void
releasePrevious()

PUBLIC: Release all objects read in so far.

public void
reset()

PUBLIC: Repositions this stream to the position at the time the mark method was last called on this stream.

protected Object
retrieveNextObject()

Implements abstract org.eclipse.persistence.queries.Cursor.retrieveNextObject.

INTERNAL: Read the next row from the result set.
protected Object
retrieveNextPage()

INTERNAL: Retrieve and add the next page size of rows to the vector.

protected void
setLimits()

INTERNAL: Initialize the stream size and position

protected void
setMarker(int value)

INTERNAL: Set the marker used for mark() & reset() operations

Inherited from org.eclipse.persistence.queries.Cursor:
buildAndRegisterObjectclosefinalizegetAccessorgetExecutionSessiongetFieldsgetInitiallyConformingIndexgetObjectCollectiongetPolicygetQuerygetResultSetgetSelectionCriteriaClonegetSessiongetStatementgetTranslationRowisClosedremovesetExecutionSessionsetFieldssetInitiallyConformingIndexsetObjectCollectionsetPolicysetPositionsetResultSetsetSelectionCriteriaClonesetSessionsetSizesetTranslationRowsize

Field Detail

markerback to summary
protected int marker

Marker for backing up.

Constructor Detail

CursoredStreamback to summary
public CursoredStream()

INTERNAL: Initialize the state of the stream

CursoredStreamback to summary
public CursoredStream(DatabaseCall call, CursoredStreamPolicy policy)

INTERNAL: Initialize the state of the stream

Method Detail

atEndback to summary
public boolean atEnd() throws DatabaseException

PUBLIC: Return whether the cursored stream is at its end.

availableback to summary
public int available() throws DatabaseException

PUBLIC: Returns the number of objects that can be read from this input without blocking.

buildCountDistinctExpressionback to summary
public Expression buildCountDistinctExpression(List<E> includeFields, ExpressionBuilder builder)

INTERNAL: Must build the count on the primary key fields, not * as * is not allowed if there was a distinct. This require a manually defined operator. added for CR 2900

clearback to summary
public void clear()

Overrides org.eclipse.persistence.queries.Cursor.clear.

PUBLIC: Release all objects read in so far. This should be performed when reading in a large collection of objects in order to preserve memory.

Annotations
@Override
copyback to summary
protected List<Object> copy(int startIndex, int endIndex) throws QueryException

INTERNAL: Answer a list of the elements of the receiver's collection from startIndex to endIndex.

getCursorSizeback to summary
protected int getCursorSize() throws DatabaseException, QueryException

Implements abstract org.eclipse.persistence.queries.Cursor.getCursorSize.

INTERNAL: Retrieve the size of the open cursor by executing a count on the same query as the cursor.

Annotations
@Override
getInitialReadSizeback to summary
protected int getInitialReadSize()

INTERNAL: Return the threshold for the stream.

getMarkerback to summary
protected int getMarker()

INTERNAL: Return the marker used for mark() & reset() operations.

getPageSizeback to summary
public int getPageSize()

Overrides org.eclipse.persistence.queries.Cursor.getPageSize.

INTERNAL: Return the page size for the stream.

Annotations
@Override
getPositionback to summary
public int getPosition()

Implements abstract org.eclipse.persistence.queries.Cursor.getPosition.

INTERNAL: Return the position of the stream inside the object collection

Annotations
@Override
hasMoreElementsback to summary
public boolean hasMoreElements()

Implements java.util.Enumeration.hasMoreElements.

PUBLIC: Return whether the cursored stream has any more elements.

Returns:boolean

Doc from java.util.Enumeration.hasMoreElements.

true if and only if this enumeration object contains at least one more element to provide; false otherwise.

Annotations
@Override
hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

PUBLIC: Return whether the cursored stream has any more elements.

Returns:boolean

Doc from java.util.Iterator.hasNext.

true if the iteration has more elements

Annotations
@Override
markback to summary
public void mark(int readAheadLimit)

PUBLIC: Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.

Parameters
readAheadLimit:int

Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from the database, there is no actual limit, so this argument is ignored.

markSupportedback to summary
public boolean markSupported()

PUBLIC: Tests if this input stream supports the mark and reset methods. The markSupported method of InputStream returns false.

nextback to summary
public Object next()

Implements java.util.Iterator.next.

PUBLIC: Return the next object from the collection, if beyond the read limit read from the cursor.

Returns:Object

the next object in stream

Annotations
@Override
nextback to summary
public List<Object> next(int numberOfElements)

PUBLIC: Return a Vector of at most numberOfElements of the next objects from the collection. If there aren't that many objects left to read, just return what is available.

Returns:List<Object>

the next objects in stream

nextElementback to summary
public Object nextElement()

Implements java.util.Enumeration.nextElement.

PUBLIC: Return the next object from the collection, if beyond the read limit read from the cursor.

Returns:Object

the next object in stream

Annotations
@Override
nextElementsback to summary
public Vector<E> nextElements(int numberOfElements)

PUBLIC: Return a Vector of at most numberOfElements of the next objects from the collection. If there aren't that many objects left to read, just return what is available.

Returns:Vector<E>

the next objects in stream

peekback to summary
public Object peek() throws DatabaseException

PUBLIC: Return the next object in the stream, without incrementing the stream's position.

readback to summary
public Object read() throws DatabaseException, QueryException

PUBLIC: This method differs slightly from conventional 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

Returns:Object

- next object in stream

Exceptions
DatabaseException:
if read pass end of stream
readback to summary
public List<Object> read(int number) throws DatabaseException

PUBLIC: This method differs slightly from conventional read() operation on a Java stream. This method returns the next number of objects in the collection in a vector. Return the next object from the collection, if beyond the read limit read from the cursor

Parameters
number:int

- number of objects to be returned

Returns:List<Object>

- vector containing next number of objects

Exceptions
DatabaseException:
if read pass end of stream
releasePreviousback to summary
public void releasePrevious()

PUBLIC: Release all objects read in so far. This should be performed when reading in a large collection of objects in order to preserve memory.

resetback to summary
public void reset()

PUBLIC: Repositions this stream to the position at the time the mark method was last called on this stream.

retrieveNextObjectback to summary
protected Object retrieveNextObject() throws DatabaseException

Implements abstract org.eclipse.persistence.queries.Cursor.retrieveNextObject.

Doc from org.eclipse.persistence.queries.Cursor.retrieveNextObject.

INTERNAL: Read the next row from the result set.

Annotations
@Override
retrieveNextPageback to summary
protected Object retrieveNextPage() throws DatabaseException

INTERNAL: Retrieve and add the next page size of rows to the vector. Return the last object, or null if at end.

setLimitsback to summary
protected void setLimits()

INTERNAL: Initialize the stream size and position

setMarkerback to summary
protected void setMarker(int value)

INTERNAL: Set the marker used for mark() & reset() operations