The C# Cursor Class

Cursor provides methods for iterating through list and index results for instances of a class.

For an overview see page C# Classes

Class Definition

    public enum Operation {
        LessThan, LessOrEquals, Equals, GreaterOrEquals, GreaterThan,
        Overlaps, Contains, ExactMatch, BestMatch, PrefixMatch,
        NextMatch, Neighbourhood, StrictEquals, IsPrefixOf, ContainsAll, ContainsAny
    }

    public interface ICursor : IEnumerable, IEnumerator {
        bool Checkpoint();
        void Update();
        void Remove();
        long GetAutoId();
    }

    public class Cursor<T> : ICursor, IEnumerable<T>, IEnumerator<T> where T : class
    {
        // --- Constructors ---
        public Cursor(Connection con, String indexName);
        public Cursor(Connection con);

        // --- Properties ---
        public T Current { get; }

        // --- Enumerator Methods ---
        public IEnumerator<T> GetEnumerator();

        // --- Search & Query Methods ---
        public bool Search(Operation op, params Object[] val);
        public T Find(params Object[] val);
        public bool QueryByExample(object from, object till);

        // --- Navigation Methods ---
        public bool MoveFirst();
        public bool MoveLast();
        public bool MoveNext();
        public bool MovePrev();
        public T Skip(int offset);

        // --- Data Modification Methods ---
        public void Update();
        public void Remove();
        public bool Checkpoint();

        // --- Utility Methods ---
        public long GetAutoId();
        public void Store();
        public void Close();
        public void Reset();
        public void Dispose();

        // --- Nested Public Enums ---
        public enum Position { Unknown, Empty, First, Curr, DeleteNext, DeletePrev }
        public enum Direction { Unknown, Forward, Backward }
    }

Method Descriptions

Operation enum
Defines search operations for index queries, including comparison, spatial, pattern-matching, and thick-array membership operations.
ICursor.Checkpoint()
Commits the current object by inserting indexes for the updated object previously returned by navigation methods. Returns false if an MVCC conflict occurs.
ICursor.Update()
Persists changes to the current object previously returned by MoveFirst(), MoveLast(), MoveNext(), MovePrev(), or Skip().
ICursor.Remove()
Deletes the current object from the database. The object must have been previously returned by a navigation method.
ICursor.GetAutoId()
Returns the AUTOID of the current object if one exists. The object must have been previously returned by a navigation method.
Cursor(Connection con, String indexName)
Initializes a cursor to iterate through instances of type T using the specified named index. Inheritance relationships are not considered.
Cursor(Connection con)
Initializes a cursor to iterate through instances of type T using the class's list or AUTOID index. The class must declare [Persistent(List=true)], [Persistent(AutoID=true)], or both.
Current
Gets the current element of type T at the cursor position. Returns null if no valid current object exists.
GetEnumerator()
Returns the cursor itself as an enumerator for iterating through cursor results. Note: all enumerators share the same underlying eXtremeDB cursor, so creating multiple enumerators for the same cursor is not recommended.
Search(Operation op, params Object[] val)
Executes a search operation and positions the cursor at the first matching element. Supported operations depend on index type: Hashtable (Equals, StrictEquals), BTree (comparison), RTree (spatial), Patricia (pattern), and Trigram (Contains). ContainsAll and ContainsAny apply to thick array indexes.
Find(params Object[] val)
Performs an exact-match lookup on a unique index. Equivalent to Search(Equals, value) followed by MoveNext(). Returns the matching object or default(T) if not found.
QueryByExample(object from, object till)
Executes a Query-By-Example search for KD-Tree indexes. Applicable only to classes generated by CILGenerator. Fields set in from define inclusive lower bounds; fields in till define inclusive upper bounds.
MoveFirst()
Positions the cursor at the first object in the result set. Returns true if the set is not empty.
MoveLast()
Positions the cursor at the last object in the result set. Returns true if the set is not empty.
MoveNext()
Advances the cursor to the next object in the result set. Returns true if successful, false if no more objects remain.
MovePrev()
Moves the cursor to the previous object in the result set. Returns true if successful, false if no more objects remain.
Skip(int offset)
Skips the specified number of results. Positive values move forward, negative values move backward. Returns the object at the target position or default(T) if unreachable.
Update()
Persists modifications to the current object in the database. The object must have been previously returned by a navigation method.
Remove()
Deletes the current object from the database. Requires a valid current object obtained via navigation methods.
Checkpoint()
Commits the current object and updates its indexes. Returns false if an MVCC conflict prevents the operation.
GetAutoId()
Retrieves the AUTOID of the current object. Throws an exception if the class lacks an AUTOID index or no current object exists.
Store()
Saves the cursor state for reuse in a subsequent transaction.
Close()
Closes the cursor. If the connection is still open, the underlying native cursor is closed as well.
Reset()
Resets the cursor to its initial state. After reset, navigation methods such as MoveNext(), MoveFirst(), or MoveLast() can position it again.
Dispose()
Resets the current cursor state. Use Close() when you need to close the underlying cursor handle.
Position enum
Internal state enum tracking cursor position: Unknown, Empty, First, Curr, DeleteNext, DeletePrev.
Direction enum
Internal enum indicating cursor traversal direction: Unknown, Forward, Backward.