Coordinates threads to export all of the rows
from a view in batches.
To construct a RowBatcher, use the DataMovementManager.newRowBatcher() factory
method. You pass a sample handle (that is, an adapter for the Java
class that stores a batch of retrieved rows). The sample handle
must implement both the ContentHandle
and StructuredReadHandle
interfaces. Because RowBatcher can retrieve rows in multiple
formats, you must specify the format or mime type on the sample
handle if the handle can be used for multiple row formats. The
RowBatcher takes a generic type for the Java class adapted by the
sample handle.
The following example constructs a RowBatcher for retrieving the
rows in CSV format as a Java String. The factory call passes a
StringHandle configured with the appropriate format and mime
type:
RowBatcher<String> rowBatcher = dataMovementMgr.newRowBatcher(
new StringHandle().withFormat(Format.TEXT).withMimetype("text/csv")
);
After constructing the RowBatcher, use the getRowManager() method to get
the RowManager for the rows. You can use the RowManager's setDatatypeStyle() method to emit data types in
the header and setRowStructureStyle() method to emit rows as
objects or arrays. The RowManager's newPlanBuilder()
method provides a factory for constructing a PlanBuilder.
Use the RowManager's PlanBuilder
to build a plan for retrieving the rows from a view. The plan must
have the following characteristics:
Must start with a fromView() operation that specifies the view with
the rows to be exported.
May filter the exported rows with a where() operation prior to any joins.
May project columns from the exported rows with a select() operation prior to any joins.
Must not limit, group, or sort over the exported view (either
before or after any joins).
May join other views with the exported view, applying any
operation to a joined view prior to the join.
May join documents or uris with the exported view.
Must not specify parameter placeholders.
Pass the built plan to the withBatchView() method to initialize the
RowBatcher with the plan.
Specify the number of threads for retrieving rows with the
withThreadCount()
method and the number of rows in a batch with the withBatchSize() method.
Specify a success listener for processing each batch of rows
retrieved from the server. The RowBatcher passes a response event
to the success listener. The success listener calls the
RowBatchResponseEvent.getRowsDoc() method to to get the
rows in the batch. The rows are returned as an instance of the Java
class adapted by the sample handle passed to the factory that
constructs the RowBatcher (that is, the generic type of the
RowBatcher).
RowBatcher<String> rowBatcher = ...construct the row batcher...;
rowBatcher.onSuccess(event -> {
String rowBatch = event.getRowsDoc();
...process the batch of rows...
});
Specify a failure listener to handle any errors during
retrieval.
Supplies a callback function (typically, a
lambda) for processing the batch of rows. The callback receives a
RowBatchResponseEvent
parameter and can call the event's
getRowsDoc() method to get the rows as an instance of
the Java class adapted by the sample handle used to construct the
RowBatcher.
Parameters:
listener - The callback function that receives the
rows
Supplies a callback function (typically, a
lambda) for logging and specifying the disposition of errors. The
callback receives a RowBatchFailureEvent
parameter for inspecting the number of retries of the error and
overall failures and for setting the disposition of the
error.
Parameters:
listener - The callback function that receives any
errors
Suspends execution of the current thread until
either all rows have been retrieved from the view, the job is
stopped, or a timeout expires.
Parameters:
timeout - the amount for the timeout
unit - the unit of measure for the amount
Returns:
true if all batches were processed
Throws:
InterruptedException - on interruption
before the job finishes or timeout expires
getRowEstimate
longgetRowEstimate()
After the job is started, provides an estimate
of the total number of rows to be exported from the view. To
estimate progress, the row estimate can be compared to the rows
retrieved so far, which can be estimated with getBatchCount() * getBatchSize()
.
Returns:
the estimate of the view rows
getBatchCount
longgetBatchCount()
The total number of batches of rows retrieved
from the view.
Returns:
the number of row batches
getFailedBatches
longgetFailedBatches()
The number of batches that the RowBatcher failed
to retrieve from the view.
If withConsistentSnapshot was used
before starting the job, will return the MarkLogic server timestamp
associated with the snapshot. Returns null otherwise.
Returns:
the timestamp or null
Copyright (c) 2010-2025 Progress
Software Corporation and/or its subsidiaries or affiliates. All
Rights Reserved.