1
  1. In Java API, No Exception is thrown, albeit erroneous transaction:
try {
…………………………………
  logger.info("Delete Document " + uri);
    docMgr.delete("rocky-mountains");
    System.out.println("Deleted");
} catch (Exception e) {
    logger.error("Exception : " + e.toString() );
  }

Document rocky-mountains doesn’t exist, however, the API happily declares Deleted:

Jul 05, 2020 9:35:04 PM com.fc.allegro.DeleteDocument deleteDocument
INFO: Delete Document rocky-mountains
Jul 05, 2020 9:35:04 PM com.marklogic.client.impl.DocumentManagerImpl delete
INFO: Deleting rocky-mountains
Deleted

In Query Console, eval detects and throws error:

[1.0-ml] XDMP-DOCNOTFOUND: xdmp:document-delete("rocky-mountains") -- Document not found
  1. As the lesser of two evils, DMSDK implies no document deleted but still doesn’t throw exception:
  QueryBatcher batcher = dmManager.newQueryBatcher(new StructuredQueryBuilder().document("rocky-mountains"));
        batcher.onUrisReady(new DeleteListener())
               .onQueryFailure( exception -> exception.printStackTrace() );

Result:

Jul 05, 2020 9:52:07 PM com.marklogic.client.datamovement.impl.QueryBatcherImpl withForestConfig
INFO: (withForestConfig) Using forests on [localhost] hosts for "allegro"
Batch Deleted
INFO: Job complete, jobBatchNumber=1, jobResultsSoFar=0

I tried checked and unchecked exceptions, but to no avail.

Which MarkLogic Class and Method does enforce throwing exceptions and mitigate risk?

  1. A query transaction via Java API:

enter image description here

Failure: enter image description here

Success: enter image description here

Fiona Chen
  • 1,358
  • 5
  • 16

1 Answers1

1

There is an important difference between running xdmp:document-delete and using Java API to delete a document. The Java API is a wrapper for the MarkLogic REST-API, which follows the rules for a RESTful API. One important rule of a RESTful API is that calls are expected to be idempotent. In short that means that you should be able to run the call twice and get same reply both times. That is why calls to insert, update, and delete don't throw errors if the document does or does not exist.

See also for instance: https://restfulapi.net/http-methods/#delete

I'd recommend using Data Services, or custom REST extensions if you want your app to be more strict.

HTH!

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
grtjn
  • 20,254
  • 1
  • 24
  • 35
  • Very good, Geert…I have the greatest difficulty convincing myself that I was not merely seeing the mirage. Please see above query transaction through Java: `exception` was caught by `Servlet`…To say the least, it tells me to FixIt-Or-Repair-Daily.
    ***Robust*** is more of the word than `strict`. And strictly speaking, end user shouldn’t use qconsole, REST API or ask DBA to execute txn. When one executes a txn through Angular UI engine, the consumer has no inkling of behind-the-scenes.
    – Fiona Chen Jul 07 '20 at 00:00
  • It strikes me that the ensuing idempotence is an assertion needs to be challenged. Surely, you suggest the update transaction exception can’t survive any Java exception handling? Below `**SQLException**` does exist and, arguably, is the comparable I am looking for: --- `Description`: https://docs.oracle.com/javase/tutorial/jdbc/basics/sqlexception.html --- `Class`: https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/SQLException.html --- `Method`: https://docs.oracle.com/en/java/javase/11/docs/api/java.sql/java/sql/SQLException.html#method.summary – Fiona Chen Jul 07 '20 at 00:02
  • They could have made different decisions, but this was the choice they made, to stick close to the principles of RESTful APIs, which causes the Java and Node Client libraries to work in the way they work. (shrug) – grtjn Jul 07 '20 at 06:05