public interface IDataCursor
This interface defines the methods you use to access, traverse, and manipulate the contents of an IData object. It is returned by an IData object's getIDataCursor method.
An IDataCursor is used to traverse the key/value pairs in an IData object. The cursor starts out in an unpositioned' state, meaning that it is not resting on an element of the IData object. The first command to a cursor determines its initial position. For example, if you use the next, first, or insertBefore method on an unpositioned cursor, the cursor is moved to the first element in the IData object. Conversely, if you use the previous, last, or insertAfter method on an unpositioned cursor, the cursor is moved to the last element in the IData object.
Be aware that a single instance of IData can be accessed concurrently from multiple different threads as long as the IData has a thread-safe implementation or the application protects itself against different threads modifying the IData at the same time. Each thread must have its own cursor. Not all IData implementations need to be thread-safe.
The IDataCursor methods do not throw exceptions when errors occur. Instead, errors accumulate in an error storage that you can examine after you call the method. Any IDataCursor method is capable of generating an error. A method does not generate more than one error during a given call.
Note: Be aware that not all types of cursors generate errors, so if you are using one that does not generate errors, it is not necessary to check for errors after each method call. The documentation for a cursor will indicate whether or not it generates errors.
When a method generates an error, the state of the underlying IData object and the cursor's position are unchanged. The IData object and the cursor are valid and usable after the error occurs.
IData
,
IDataFactory
Modifier and Type | Method and Description |
---|---|
boolean |
delete()
Removes the key/value pair at the cursor's current position and positions the cursor on the key/pair value that immediately follows the one you removed.
|
void |
destroy()
Discards this IData cursor.
|
boolean |
first()
Moves the cursor to the first key/value pair in the IData object.
|
boolean |
first(java.lang.String key)
Moves the cursor to the first key/value pair that has a specified key.
|
IDataCursor |
getCursorClone()
Returns a new cursor that is identical in state and type to the cursor on which you call this method.
|
java.lang.String |
getKey()
Returns a String object containing the key of the key/value pair at the cursor's current position.
|
DataException |
getLastError()
Returns the most recent cursor error.
|
java.lang.Object |
getValue()
Returns an Object containing the value of the key/value pair at the cursor's current position.
|
boolean |
hasMoreData()
Indicates whether the cursor is on the last element in the IData object (i.e., indicates whether next, if executed, would move the cursor successfully).
|
boolean |
hasMoreErrors()
Reports whether there are any errors in error storage.
|
void |
insertAfter(java.lang.String key,
java.lang.Object value)
Inserts a new key/value pair immediately after the cursor's current position.
|
void |
insertBefore(java.lang.String key,
java.lang.Object value)
Inserts a new key/value pair immediately before the cursor's current position and positions the cursor on the new pair.
|
IData |
insertDataAfter(java.lang.String key)
Inserts a new key/value pair immediately after the cursor's current position and positions the cursor on the new pair.
|
IData |
insertDataBefore(java.lang.String key)
Inserts a new key/value pair immediately before the cursor's current position.
|
boolean |
last()
Moves the cursor to the last key/value pair.
|
boolean |
last(java.lang.String key)
Moves the cursor to the last key/value pair that has a specified key.
|
boolean |
next()
Moves the cursor to the next key/value pair in the IData object (to the key/value pair that immediately follows the cursor's current position).
|
boolean |
next(java.lang.String key)
Moves the cursor to the next key/value pair that has a specified key.
|
boolean |
previous()
Moves the cursor to the previous key/value pair in the IData object (the pair that immediately precedes the cursor's current position).
|
boolean |
previous(java.lang.String key)
Moves the cursor to the previous key/value pair that has a specified key.
|
void |
setErrorMode(int mode)
Controls the behavior of error storage in cursors that are capable of generating errors.
|
void |
setKey(java.lang.String key)
Sets the key of the key/value pair at the cursor's current position to a specified String.
|
void |
setValue(java.lang.Object value)
Sets the value of the key/value pair at the cursor's current position.
|
void setErrorMode(int mode)
Controls the behavior of error storage in cursors that are capable of generating errors. Two modes are supported:
You may change the error mode at any point. When you change from LAST to STACK, if an error already exists in storage, that error becomes the oldest error in the stack. When you change from STACK to LAST, the current stack stays in memory until the next error occurs and the entire stack is replaced with the single error.
mode
- an int specifying the error mode. Must be ERROR_MODE_LAST or ERROR_MODE_STACK.DataException getLastError()
Returns the most recent cursor error.
If the cursor's error mode is LAST, error storage will be emptied by this call. If the error mode is STACK, this method returns the most recent error and leaves it and all previous errors in storage.
Once an error has been retrieved, it cannot be retrieved again.
boolean hasMoreErrors()
Reports whether there are any errors in error storage.
java.lang.String getKey()
Returns a String object containing the key of the key/value pair at the cursor's current position. If the cursor has not yet been positioned with one of the cursor's positioning methods (e.g., next, previous, first), getKey generates an error (in cursors that generate errors) and returns null.
Note: This method might also return null if the key at the cursor position is null.
getValue()
,
setKey(java.lang.String)
java.lang.Object getValue()
Returns an Object containing the value of the key/value pair at the cursor's current position. If the cursor has not yet been positioned with one of the cursor's positioning methods (e.g., next, previous, first), getValue generates an error (in cursors that generate errors) and returns null.
Note: This method might also return null if the value at the cursor position is null.
getKey()
,
setValue(java.lang.Object)
void setKey(java.lang.String key)
Sets the key of the key/value pair at the cursor's current position to a specified String. If the cursor has not yet been positioned with one of the cursor's positioning methods (e.g., next, previous, first), setKey generates an error (in cursors that generate errors) and does nothing.
setKey will also generate an error (in cursors that generate errors) if an IData implementation adheres to a particular schema and the action performed by setKey violates the schema.
Note: When setKey generates an error, it makes no changes to the IData object.
key
- a String that specifies the new key.setValue(java.lang.Object)
,
getKey()
void setValue(java.lang.Object value)
Sets the value of the key/value pair at the cursor's current position. If the cursor has not yet been positioned with one of the cursor's positioning methods (e.g., next, previous, first), setValue generates an error (in cursors that generate errors) and does nothing.
setValue will also generate an error (in cursors that generate errors) if an IData implementation adheres to a particular schema and the action performed by setValue violates the schema.
Note: When setValue generates an error, it makes no changes to the IData object.
value
- an Object that represents the value to be assigned at the current cursor position.setKey(java.lang.String)
,
getValue()
boolean delete()
Removes the key/value pair at the cursor's current position and positions the cursor on the key/pair value that immediately follows the one you removed.
insertBefore(java.lang.String, java.lang.Object)
,
insertAfter(java.lang.String, java.lang.Object)
void insertBefore(java.lang.String key, java.lang.Object value)
Inserts a new key/value pair immediately before the cursor's current position and positions the cursor on the new pair.
key
- a String that specifies the name of the key in the new key/value pair.value
- the Object that you want insertBefore to assign to the new key/value pair.insertDataBefore(java.lang.String)
,
insertAfter(java.lang.String, java.lang.Object)
,
delete()
void insertAfter(java.lang.String key, java.lang.Object value)
Inserts a new key/value pair immediately after the cursor's current position. After inserting the new key/value pair, insertAfter positions the cursor on the new pair.
key
- a String that specifies the name of the key for the new key/value pair.value
- the Object that you want insertAfter to assign to the new key/value pair.insertDataAfter(java.lang.String)
,
insertBefore(java.lang.String, java.lang.Object)
,
delete()
IData insertDataBefore(java.lang.String key)
Inserts a new key/value pair immediately before the cursor's current position. With this method, you specify only the key. The method provides the value, which is an object implementing the IData interface whose concrete class varies according to the concrete class of the IData object you are working with. This method supports the situation where the IData instance you are working with has to manage relationships among its constituent IData instances, and requires that a child IData instance be created in the context of a parent. It also supports the case where the IData instance can contain only IData instances of a particular concrete class, and the caller does not know or have access to the class.
After inserting the new key/value pair, insertDataBefore positions the cursor on the new pair.
key
- a String that specifies the name of the key for the new key/value pair.insertBefore(java.lang.String, java.lang.Object)
,
insertDataAfter(java.lang.String)
,
delete()
IData insertDataAfter(java.lang.String key)
Inserts a new key/value pair immediately after the cursor's current position and positions the cursor on the new pair.
With this method, you specify only the key. The method provides the value, which is an object implementing the IData interface whose concrete class varies according to the concrete class of the IData object you are working with. This method supports the situation where the IData instance you are working with has to manage relationships among its constituent IData instances, and requires that a child IData instance be created in the context of a parent. It also supports the case where an IData instance can contain only IData instances of a particular concrete class, and the caller does not know or have access to the class.
insertAfter(java.lang.String, java.lang.Object)
,
insertDataBefore(java.lang.String)
,
delete()
boolean next()
Moves the cursor to the next key/value pair in the IData object (to the key/value pair that immediately follows the cursor's current position).
next()
,
previous(String)
,
first(String)
,
last(String)
boolean next(java.lang.String key)
Moves the cursor to the next key/value pair that has a specified key.
Note: This method will not return the current key/value pair even if that pair has the proper key. It returns only a key/value pair that both follows the pair at the cursor's current position and has the key you specify.
key
- a String that specifies the name of the key to which you want the cursor moved. This parameter is case sensitive. The value you specify must match the key name exactly. A null parameter will match a key/value pair whose key is null.next()
,
previous(String)
,
first(String)
,
last(String)
boolean previous()
Moves the cursor to the previous key/value pair in the IData object (the pair that immediately precedes the cursor's current position).
previous(String)
,
next()
,
first()
,
last()
boolean previous(java.lang.String key)
Moves the cursor to the previous key/value pair that has a specified key.
Note: This method never returns the current key/value pair even if that pair has the specified key. It returns only a key/value pair that both follows the pair at the cursor's current position and has the key you specify.
key
- a String that specifies the name of the key to which you want the cursor moved. This parameter is case-sensitive. The value you specify must match the key name exactly. A null parameter will match a key/value pair whose key is null.previous()
,
next(String)
,
first(String)
,
last(String)
boolean first()
Moves the cursor to the first key/value pair in the IData object. If the object contains no key/value pairs, the cursor remains unpositioned and first returns false.
first(String)
,
last()
,
next()
,
previous()
boolean first(java.lang.String key)
Moves the cursor to the first key/value pair that has a specified key.
key
- a String that specifies the name of the key to which you want the cursor moved. This parameter is case sensitive. The value you specify must match the key name exactly. A null parameter will match a key/value pair whose key is null.first()
,
last(String)
,
next(String)
,
previous(String)
boolean last()
Moves the cursor to the last key/value pair. If there are no entries in the IData object, the cursor remains unpositioned and last returns false.
last(String)
,
first()
,
next()
,
previous()
boolean last(java.lang.String key)
Moves the cursor to the last key/value pair that has a specified key.
key
- a String that specifies the name of the key to which you want the cursor moved. This parameter is case sensitive. The value you specify must match the key name exactly. A null parameter will match a key/value pair whose key is null.last()
,
first(String)
,
next(String)
,
previous(String)
boolean hasMoreData()
Indicates whether the cursor is on the last element in the IData object (i.e., indicates whether next, if executed, would move the cursor successfully).
Note: This method basically returns the same value as next would if it were called and it did not generate an error.
Note: Although the status returned by hasMoreData indicates the status that next would return if it were executed, the presence or absence of an error after hasMoreData is not an indication of whether next will produce an error. You cannot use the error status from hasMoreData to predict whether or not next
next()
void destroy()
Discards this IData cursor. You should always explicitly discard (destroy) a cursor when you are finished using it, even though the Java garbage collector will do this if you neglect to do so. Explicitly destroying the cursor will provide more efficient performance.
Note: If you are using webMethods standard IData implementation, the cursor is returned to a cache when you destroy it, so the object does not need to be recreated the next time the getCursor method is called.
getCursorClone()
IDataCursor getCursorClone()
Returns a new cursor that is identical in state and type to the cursor on which you call this method. The new cursor operates on the same IData object. A copy of the current cursor is useful for saving the current cursor position (similar to "bookmarking" that position).
Note:The cursor position in a clone is completely independent from the cursor position in the cursor from which it was copied and form cursor clones that you create. When you change the position of the cursor in one clone, you do not affect the cursor positions in the others.