java-client-api
java-client-api copied to clipboard
Delete temporal documents via DMSDK
Creating this feature request in GitHub for visibility for a customer that has a need for bulk delete of temporal documents via DMSDK. The customer is going to create their own TemporalDeleteListener
that is specific to their needs in the meantime.
It looks like the basic pattern for deleting a temporal document is this:
TemporalDocumentManager<?, ?> docMgr = batch.getClient().newXMLDocumentManager();
// Protecting is only required if there's not already a protection on the document
javax.xml.datatype.Duration xmlDuration = DatatypeFactory.newInstance().newDuration("PT0M");
docMgr.protect(uris[i], temporalCollection, TemporalDocumentManager.ProtectionLevel.NOUPDATE, xmlDuration);
docMgr.wipe(uris[i], temporalCollection);
We'll need to provide configurability over the above code - e.g. since protect/wipe only exist on the concrete JSON/XML document managers, a user would need to configure the listener to specify whether JSON or XML documents are being deleted (this seems unfortunate, ideally the generic DocumentManager
interface would have these protect/wipe methods).
For implementation - it seems that the easiest path would be to modify the existing DeleteListener
and extract the batch.getClient().newDocumentManager().delete( batch.getItems() );
line into a new protected method. TemporalDeleteListener
can then override that method to provide its own delete functionality while inheriting the rest of the useful functionality in DeleteListener
.
Since docMgr.wipe() is only one per URI, may be another feature is to have bulk delete capability on wipe ?
Both the protect
and wipe
calls can only accept one URI based on how the REST API works - https://docs.marklogic.com/REST/POST/v1/documents/protection . So until the server is altered, it's not possible to do this efficiently as it would require 2 calls per URI.
I think the better approach is to make use of temporal.collectionSetOptions
to apply the update-admin-override
option. That allows for a regular delete to work, and N URIs can be sent in a single delete call.