Module org.tentackle.persistence
Package org.tentackle.persist
Class ResultSetCursor<T extends PersistentDomainObject<T>>
- java.lang.Object
-
- org.tentackle.persist.ResultSetCursor<T>
-
- Type Parameters:
T- the retrieved type
- All Implemented Interfaces:
AutoCloseable,org.tentackle.misc.ScrollableResource<T>
public class ResultSetCursor<T extends PersistentDomainObject<T>> extends Object implements org.tentackle.misc.ScrollableResource<T>
A cursor for aResultSetWrapper.- Author:
- harald
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResultSetCursor.FetchList<T>Adds a closed flag to saveObject a roundtrip in remote sessions.
-
Constructor Summary
Constructors Constructor Description ResultSetCursor(DomainContext context, RemoteResultSetCursor<T> remoteCursor)Creates a cursor for a remote session.
Constructor for pdo objects.ResultSetCursor(T pdo, ResultSetWrapper rs)Creates a cursor for a local session.ResultSetCursor(T pdo, ResultSetWrapper rs, JoinedSelect<T> js)Creates a cursor for a local session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterLast()Positions the cursor after the last row.
Works even for empty cursoresources.rs.protected voidassertNoJoins()Asserts that there are no joins in the query.protected voidassertSessionIsLocal()Asserts that session is local.protected voidassertSessionIsRemote()Asserts that session is remote.voidbeforeFirst()Positions the cursor before the first row.
Works even for empty cursoresources.rs.voidclose()Closes the cursor.
The cursor is opened in its constructor.protected voidconfigureRemoteObject(T pdo)Configures the remotely retrieved PDO.ResultSetCursor.FetchList<T>fetch()Fetches the next objects up to the fetchsize.
This method is provided to minimize the number of roundtrips especially for remote cursoresources.rs.booleanfirst()Rewinds the cursor to the first row.Tget()Gets the data object of the current row.DomainContextgetDomainContext()Gets the domain context.intgetFetchDirection()Gets the fetch direction.intgetFetchSize()Gets the fetchsize.JoinedSelect<T>getJoinedSelect()Gets the join configuration.RemoteResultSetCursor<T>getRemoteCursor()Gets the remote cursor.ResultSetWrappergetResultSet()Gets the result set.intgetRow()Gets the current row.
Row numbers start at 1.org.tentackle.session.SessiongetSession()Gets the session.booleanisAfterLast()Checks whether the cursor is after the last row.booleanisBeforeFirst()Checks whether the cursor is before the first row.booleanisClosed()Returns whether the cursor is closed.booleanlast()Positions the cursor on the last row.booleannext()Moves the cursor to the next row.
If there are no more rows the current row remains unchanged.booleanprevious()Moves the cursor to the previous row.
If we are already at the beginning, the cursor remains unchanged.booleanscroll(int rows)Moves the cursor a given number of rows.voidsetFetchDirection(int direction)Sets the fetch direction.voidsetFetchSize(int rows)Sets the fetchsize.
This is the number of rows the cursor will fetch from the server in one batch.booleansetRow(int row)Sets the cursor to a given row.
Row numbers start at 1.List<T>toList()Returns the objects of this cursor as a list.protected voidtoList(List<T> list)Adds the rest of the cursor to a list.List<T>toListAndClose()Returns the objects of this cursor as a list and closes this cursor.
-
-
-
Constructor Detail
-
ResultSetCursor
public ResultSetCursor(T pdo, ResultSetWrapper rs, JoinedSelect<T> js)
Creates a cursor for a local session.- Parameters:
pdo- the PDO proxyrs- the result setjs- the join configuration, null if no joins
-
ResultSetCursor
public ResultSetCursor(T pdo, ResultSetWrapper rs)
Creates a cursor for a local session.- Parameters:
pdo- the PDO proxyrs- the result set
-
ResultSetCursor
public ResultSetCursor(DomainContext context, RemoteResultSetCursor<T> remoteCursor)
Creates a cursor for a remote session.
Constructor for pdo objects.- Parameters:
context- the domain contextremoteCursor- the remote cursor
-
-
Method Detail
-
getResultSet
public ResultSetWrapper getResultSet()
Gets the result set.- Returns:
- the result set
-
getJoinedSelect
public JoinedSelect<T> getJoinedSelect()
Gets the join configuration.- Returns:
- the join configuration, null if no joins
- Throws:
org.tentackle.session.PersistenceException- if session is remote
-
getRemoteCursor
public RemoteResultSetCursor<T> getRemoteCursor()
Gets the remote cursor.- Returns:
- the remote cursor
- Throws:
org.tentackle.session.PersistenceException- if session is local
-
getSession
public org.tentackle.session.Session getSession()
Gets the session.- Returns:
- the session
-
getDomainContext
public DomainContext getDomainContext()
Gets the domain context.- Returns:
- the context
-
close
public void close()
Closes the cursor.
The cursor is opened in its constructor. Closing an already closed cursor is allowed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>
-
isClosed
public boolean isClosed()
Returns whether the cursor is closed.- Specified by:
isClosedin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- true if closed
-
getRow
public int getRow()
Gets the current row.
Row numbers start at 1.- Specified by:
getRowin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- the current row, 0 if before first row
-
setRow
public boolean setRow(int row)
Sets the cursor to a given row.
Row numbers start at 1.- Specified by:
setRowin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Parameters:
row- the row number (must be ≥ 0)- Returns:
- true if done, false if no such row and the cursor is now before the first row or after the last row
-
first
public boolean first()
Rewinds the cursor to the first row.- Specified by:
firstin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- true if rewound, false if cursor is empty
-
last
public boolean last()
Positions the cursor on the last row.- Specified by:
lastin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- true if positioned, false if cursor is empty
-
next
public boolean next()
Moves the cursor to the next row.
If there are no more rows the current row remains unchanged.- Specified by:
nextin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- true if moved, false if no more rows
-
previous
public boolean previous()
Moves the cursor to the previous row.
If we are already at the beginning, the cursor remains unchanged.- Specified by:
previousin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- true if advanced, false if already at the beginning
-
scroll
public boolean scroll(int rows)
Moves the cursor a given number of rows.- Specified by:
scrollin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Parameters:
rows- the number of rows to move, negative to move backwards- Returns:
- true if moved, false if no such row and the cursor is now positioned before the first row or after the last row
-
beforeFirst
public void beforeFirst()
Positions the cursor before the first row.
Works even for empty cursoresources.rs.- Specified by:
beforeFirstin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>
-
afterLast
public void afterLast()
Positions the cursor after the last row.
Works even for empty cursoresources.rs.- Specified by:
afterLastin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>
-
isBeforeFirst
public boolean isBeforeFirst()
Checks whether the cursor is before the first row.- Specified by:
isBeforeFirstin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- true if before first
-
isAfterLast
public boolean isAfterLast()
Checks whether the cursor is after the last row.- Specified by:
isAfterLastin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- true if after last
-
get
public T get()
Gets the data object of the current row.- Specified by:
getin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- the object, null if invalid row or no such object
-
toList
public List<T> toList()
Returns the objects of this cursor as a list.- Specified by:
toListin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- the list
-
toListAndClose
public List<T> toListAndClose()
Returns the objects of this cursor as a list and closes this cursor.- Specified by:
toListAndClosein interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- the list
-
setFetchSize
public void setFetchSize(int rows)
Sets the fetchsize.
This is the number of rows the cursor will fetch from the server in one batch. A fetchsize of 0 means server default.- Specified by:
setFetchSizein interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Parameters:
rows- the fetchsize
-
getFetchSize
public int getFetchSize()
Gets the fetchsize.- Specified by:
getFetchSizein interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- the fetchsize
-
setFetchDirection
public void setFetchDirection(int direction)
Sets the fetch direction.- Parameters:
direction- the direction, seeResultSet.setFetchDirection(int).
-
getFetchDirection
public int getFetchDirection()
Gets the fetch direction.- Returns:
- the direction
-
fetch
public ResultSetCursor.FetchList<T> fetch()
Fetches the next objects up to the fetchsize.
This method is provided to minimize the number of roundtrips especially for remote cursoresources.rs. The cursor is closed at the end of the cursor.- Specified by:
fetchin interfaceorg.tentackle.misc.ScrollableResource<T extends PersistentDomainObject<T>>- Returns:
- the list of objects, null if no more objects found
-
toList
protected void toList(List<T> list)
Adds the rest of the cursor to a list.- Parameters:
list- the list
-
configureRemoteObject
protected void configureRemoteObject(T pdo)
Configures the remotely retrieved PDO.- Parameters:
pdo- the PDO
-
assertSessionIsRemote
protected void assertSessionIsRemote()
Asserts that session is remote.
-
assertSessionIsLocal
protected void assertSessionIsLocal()
Asserts that session is local.
-
assertNoJoins
protected void assertNoJoins()
Asserts that there are no joins in the query.
-
-