org.cruxframework.crux.core.client.db
Interface Cursor<K,V>

Type Parameters:
K - The type of the key used to identify objects into the cursor.
V - The type of the objects referenced by this cursor
All Known Subinterfaces:
FileCursor
All Known Implementing Classes:
IDXCursor, IDXFileCursor, WSQLCursor

public interface Cursor<K,V>

Represents a Cursor into Crux Database. Cursors can be used to iterate over the result of a database query.

To open a cursor, you must ask to an ObjectStore or an Index object. Both classes define an openCursor method.

See the following example:

 Transaction transaction = database.getTransaction(new String[]{"MyObjectStore"}, Mode.readOnly);
 ObjectStore store = transaction.getObjectStore("MyObjectStore");
 store.openCursor(new DatabaseCursorCallback<Integer, MyObject>(){
    public void onSuccess( result) {
      if (result != null && result.getValue() != null) {
         Window.alert("Object found. ID ["+result.getKey()+"]");
         continueCusror();
      }
    }
 });
 

Author:
Thiago da Rosa de Bustamante

Nested Class Summary
static class Cursor.CursorDirection
          Direction for the cursor.
 
Method Summary
 void advance(int count)
          Advance the cursor current position by a number of positions.
 void continueCursor()
          Make cursor to go to the next element.
 void continueCursor(K key)
          Make cursor to go to the element referenced by the given key.
 void delete()
          Delete the current value, pointed by the cursor, from the database.
 Cursor.CursorDirection getDirection()
          Direction of iteration used by this cursor.
 K getKey()
          Return the key of record pointed by the cursor.
 com.google.gwt.core.client.JsArrayMixed getNativeArrayKey()
          Return the cursor key, as a native javascript object.
 V getValue()
          Return the value of record pointed by the cursor.
 boolean hasValue()
          Return true if cursor points to a valid value.
 void update(V value)
          Update current record pointed by the cursor with the given value.
 

Method Detail

advance

void advance(int count)
Advance the cursor current position by a number of positions. Cursor callback onSuccess method will be called again, receiving the new value where cursor points after the advance.

Parameters:
count - number of items to advance

continueCursor

void continueCursor()
Make cursor to go to the next element. Cursor callback onSuccess method will be called again, receiving the new value where cursor points after the advance.


continueCursor

void continueCursor(K key)
Make cursor to go to the element referenced by the given key. Cursor callback onSuccess method will be called again, receiving the new value where cursor points after the advance.

Parameters:
key - key of the element to be pointed by the cursor.

delete

void delete()
Delete the current value, pointed by the cursor, from the database.


hasValue

boolean hasValue()
Return true if cursor points to a valid value.

Returns:
true if cursor points to a valid value

getDirection

Cursor.CursorDirection getDirection()
Direction of iteration used by this cursor.

Returns:
cursor direction

getNativeArrayKey

com.google.gwt.core.client.JsArrayMixed getNativeArrayKey()
Return the cursor key, as a native javascript object.

Returns:
cursor key.

update

void update(V value)
Update current record pointed by the cursor with the given value.

Parameters:
value - new value to update

getKey

K getKey()
Return the key of record pointed by the cursor.

Returns:
key of the element pointed by the cursor

getValue

V getValue()
Return the value of record pointed by the cursor.

Returns:
value of the element pointed by the cursor


Copyright © 2014. All rights reserved.