Cursor provides methods for iterating through instances of a class.
public class Cursor<T> implements Iterable<T>, Iterator<T>, java.io.Closeable
{
public enum Operation
{
LessThan,
LessOrEquals,
Equals,
GreaterOrEquals,
GreaterThan,
Overlaps,
Contains,
ExactMatch,
BestMatch,
PrefixMatch,
NextMatch,
Neighbourhood,
StrictEquals,
IsPrefixOf,
ContainsAll,
ContainsAny
};
public Cursor(Connection con, Class cls, String indexName)
{
...
}
public Cursor(Connection con, Class cls)
{
...
}
public boolean search(Operation op, Object... value)
{
...
}
public boolean search(Operation op, long value)
{
...
}
public boolean search(Operation op, double value)
{
...
}
public boolean search(Operation op, String value)
{
...
}
public T find(Object... value)
{
...
}
public T find(long value)
{
...
}
public T find(String value)
{
...
}
public boolean hasPrev()
{
...
}
public boolean hasNext()
{
...
}
public boolean moveNext()
{
...
}
public boolean movePrev()
{
...
}
public T skip(int offset)
{
...
}
public T getCurrent()
{
...
}
public T next()
{
...
}
public T prev()
{
...
}
public T first()
{
...
}
public T last()
{
...
}
public void remove()
{
...
}
public void update()
{
...
}
public void checkpoint()
{
...
}
public long getAutoId()
{
...
}
public void close()
{
...
}
public Iterator<T> iterator()
{
...
}
};
Construct a cursor to iterate through instances of the specified class (inheritance is not considered).
Parameters:
con — A database connection.cls — The iterated class.indexName — The name of the index used for iteration and searching.Construct a cursor for a class having a list or AUTOID index
(list() or autoid() attributes of the Persistent
annotation).
Parameters:
con — A database connection.cls — The iterated class.public boolean search(Operation op, Object... value)
public boolean search(Operation op, long value)
public boolean search(Operation op, double value)
public boolean search(Operation op, String value)
Perform the specified search operation op.
Parameters:
op — The operation to be performed from enum Operation.value — The Object, long, double or
String key value to search.This method can be used for any type of index; the supported search operations depend on the index type:
Hashtable — Equals.BTree — LessThan, LessOrEquals, Equals, GreaterThan, GreaterOrEquals.RTree — Equals, Overlaps, Contains, Neighbourhood.Patricia — Equals, ExactMatch, BestMatch, PrefixMatch, NextMatch.Trigram — Contains.This method positions the cursor at the first element matching the specified search condition. Move forward or backward to locate all other elements for which this condition is true.
For example, in a LessThan search move backward and in a GreaterOrEquals
search move forward.
public T find(Object... value)
public T find(long value)
public T find(String value)
Perform an exact match search on a unique index. Return an object with the specified key or
null if no object with this key value is found.
Parameters:
value — The Object, long or String key value
to search.This method is equivalent to:
cursor.search(Cursor.Operation.Equals, value);
T result = cursor.next();
public boolean hasPrev()
public boolean hasNext()
public boolean moveNext()
Move the cursor position forward without fetching the current object. This method allows traversal of
the cursor without fetching objects. A desired object can be explicitly fetched using the
getCurrent() method. Return true if the current element is not the last
one, false otherwise.
public boolean movePrev()
Move the cursor position backward without fetching the current object. This method allows traversal
of the cursor without fetching objects. A desired object can be explicitly fetched using the
getCurrent() method. Return true if the current element is not the first
one, false otherwise.
public T skip(int offset)
Skip the specified number of results. Return the object at the specified position in the cursor or
null if this position cannot be reached.
Parameters:
offset — If positive, move forward; if negative, move backward (zero value is not
accepted).public T getCurrent()
Get the current object. This method should be used only with methods moveNext() or
movePrev() as an alternative to next() or prev().
public T next()
Move forward. Return the next object in the result set or null if there are no more
objects.
public T prev()
Move backward. Return the previous object in the result set or null if there are no more
objects.
public T first()
Get the first object in the result set. Return the first object in the result set or
null if the result set is empty.
public T last()
Get the last object in the result set. Return the last object in the result set or null
if the result set is empty.
public void remove()
Remove the current object, i.e. the object previously returned by methods first(),
last(), next(), prev() or skip().
public void update()
Update the current object, i.e. the object previously returned by methods first(),
last(), next(), prev() or skip().
public boolean checkpoint()
Checkpoint the current object, i.e. insert indexes for the updated object previously returned by
methods first(), last(), next(), prev() or
skip().
Return false if there is an MVCC conflict.
public long getAutoId()
Get the AUTOID of the current object (if it has one). Return the AUTOID of
the object previously returned by methods first(), last(),
next(), prev() or skip().
public void close()
public Iterator<T> iterator()