Modifies documents in-place in the database by applying a
com.marklogic.client.document.ServerTransform.
If the transform modifies documents to no longer match the query,
ApplyTransformListener should only be used when:
- merge timestamp
is enabled and
QueryBatcher#withConsistentSnapshot is called, or
-
DataMovementManager#newQueryBatcher(Iterator) is used to traverse a static data set
For example, given the REST transform myTransform.sjs:
function transform_function(context, params, content) ;
exports.transform = transform_function;
}
installed in the server like so (using the MarkLogic Java Client API):
restAdminClient.newServerConfigManager().newTransformExtensionsManager().writeJavascriptTransform(
you can run the transform on documents matching a query like so:
ServerTransform transform = new ServerTransform(transformName2)
As with all the provided listeners, this listener will not meet the needs
of all applications but the
source code
for it should serve as helpful sample code so you can write your own custom
listeners.
In this listener, we initialize only the HostAvailabilityListener's
RetryListener and not NoResponseListener's RetryListener because if we get
empty responses when we try to apply a transform to the batch of URIs
retrieved from the server, we are not sure what happened in the server - if
the transform has been applied or it has not been applied. Retrying in those
scenarios would apply the transform twice if the transform has been already
applied and this is not desirable.
In order to handle such scenarios where we get an empty response, it is
recommended to add a BatchFailureListener which would take care of apply
transform failures and retry only for those URIs for which the apply
transform has failed. If the transform is idempotent, we can just initialize
the RetryListener of the NoResponseListener by calling
NoResponseListener.initializeRetryListener(this) and add it to the
BatchFailureListeners similar to what we have in the other listeners.