Cursors can be retrieved from {@code PreparedQuery.asQueryResult*} functions.A typical use case would be:
The encoded cursor can then be passed safely in a get or post arg of a web request and on another request the next batch of results can be retrieved with:Cursor originalCursor = preparedQuery.asQueryResultList(withLimit(20)).getCursor(); String encodedCursor = original.toWebSafeString();
Cursor decodedCursor = Cursor.fromWebSafeString(encodedCursor); ListnextBatch = preparedQuery.asQueryResultList(withLimit(20).cursor(decoded));
Cursors may be used by multiple threads, but only serially. That is, the application must serialize access to the handle.
If the cursor is to be used to perform operations on behalf of a transaction, the cursor must be opened and closed within the context of that single transaction.
Once the cursor close method has been called, the handle may not be accessed again, regardless of the close method's success or failure.
To obtain a cursor with default attributes:
To customize the attributes of a cursor, use a CursorConfig object.Cursor cursor = myDatabase.openCursor(txn, null);
CursorConfig config = new CursorConfig(); config.setDirtyRead(true); Cursor cursor = myDatabase.openCursor(txn, config);
Modifications to the database during a sequential scan will be reflected in the scan; that is, records inserted behind a cursor will not be returned while records inserted in front of a cursor will be returned. In Queue and Recno databases, missing entries (that is, entries that were never explicitly created or that were created and then deleted) will be ignored during a sequential scan.
Cursors which are opened with a transaction instance are transactional cursors and may be used by multiple threads, but only serially. That is, the application must serialize access to the handle. Non-transactional cursors, opened with a null transaction instance, may not be used by multiple threads.
If the cursor is to be used to perform operations on behalf of a transaction, the cursor must be opened and closed within the context of that single transaction.
Once the cursor {@link #close} method has been called, the handle may notbe accessed again, regardless of the {@code close} method's success orfailure, with one exception: the {@code close} method itself may be calledany number of times to simplify error handling.
To obtain a cursor with default attributes:
Cursor cursor = myDatabase.openCursor(txn, null);
To customize the attributes of a cursor, use a CursorConfig object.
CursorConfig config = new CursorConfig(); config.setReadUncommitted(true); Cursor cursor = myDatabase.openCursor(txn, config);
Modifications to the database during a sequential scan will be reflected in the scan; that is, records inserted behind a cursor will not be returned while records inserted in front of a cursor will be returned.
The {@link DatabaseEntry#setPartial DatabaseEntry Partial} property canbe used to optimize in certain cases. This provides varying degrees of performance benefits that depend on the specific operation and use of {@code READ_UNCOMMITTED} isolation, as described below.
When retrieving a record with a {@link Database} or {@link Cursor}method, if only the key is needed by the application then the retrieval of the data item can be suppressed using the Partial property. If {@code setPartial(0, 0, true)} is called for the {@code DatabaseEntry} passed asthe data parameter, the data item will not be returned by the {@code Database} or {@code Cursor} method.
Suppressing the return of the data item potentially has a large performance benefit when the {@code READ_UNCOMMITTED} isolation mode isused. In this case, if the record data is not in the JE cache, it will not be read from disk. The performance benefit is potentially large because random access disk reads may be reduced. Examples are:
For other isolation modes ( {@code READ_COMMITTED}, {@code REPEATABLE_READ} and {@code SERIALIZABLE}), the performance benefit is not as significant. In this case, the data item must be read into the JE cache if it is not already present, in order to lock the record. The only performance benefit is that the data will not be copied from the JE cache to the application's entry parameter.
For information on specifying isolation modes, see {@link LockMode}, {@link CursorConfig} and {@link TransactionConfig}.
The Partial property may also be used to retrieve or update only a portion of a data item. This avoids copying the entire record between the JE cache and the application data parameter. However, this feature is not currently fully optimized, since the entire record is always read or written to the database, and the entire record is cached. A partial update may be performed only with {@link Cursor#putCurrent Cursor.putCurrent}.
In limited cases, the Partial property may also be used to retrieve a partial key item. For example, a {@code DatabaseEntry} with a Partialproperty may be passed to {@link #getNext getNext}. However, in practice this has limited value since the entire key is usually needed by the application, and the benefit of copying a portion of the key is generally very small. Partial key items may not be passed to methods that use the key as an input parameter, for example, {@link #getSearchKey getSearchKey}. In general, the usefulness of partial key items is very limited.
Purpose: Abstract class for CursoredStream and ScrolableCursor
Cursor
object is used to acquire bytes from a given source. This provides a cursor style reading of bytes from a stream in that it will allow the reader to move the cursor back if the amount of bytes read is too much. Allowing the cursor to move ensures that excess bytes back be placed back in the stream. This is used when parsing input from a stream as it ensures that on arrival at a terminal token any excess bytes can be placed back in to the stream. This allows data to be read efficiently in large chunks from blocking streams such as sockets. @author Niall Gallagher @see org.simpleframework.transport.TransportCursor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|