Zipunrar
Zipunrar

Reputation: 203

MarkLogic Java Client API - Patching Metadata and Document Content

I have a question related to the NoSQL-Database MarkLogic 8 and the Java Client API 3.0.5:

Patching a XML-document content and the metadata (properties, collections) is possible via the XMLDocumentManager and a DocumentPatchHandle.

# First Approach (Content & Metadata Patch at once)

XMLDocumentManager mgr = client.newXMLDocumentManager();
DocumentPatchBuilder builder = mgr.newPatchBuilder();

builder.insert(...);
builder.replacePropertyValue(...);

mgr.patch("test.xml", builder.build());

My question is (not answered in the documentation): Is such a update done in a transaction automatically?

I ask this because I can do a content patch and a metadata update separately. If I want to do it that way, I need to ask the server to generate a new Transaction instance which I have to commit or rollback.

# Second Approach (separate Content & Metadata Patch)

XMLDocumentManager mgr = client.newXMLDocumentManager();
DocumentPatchBuilder builder = mgr.newPatchBuilder();

builder.insert(...);

DocumentMetadataPatchBuilder mbuilder = mgr.newPatchBuilder();

mbuilder.replacePropertyValue(...);

Transaction tx = client.newTransaction();

mgr.patch("test.xml", builder.build());

mgr.patch("test.xml", mbuilder.build());

tx.commit();

I think doing it like this in the second snippet would result in two DocumentPatchHandle instances and 4 request (transaction, patch, patch, commit). The first seems to need only one request.

In other words: Is either the first or the second approach better/faster/elegant?

Upvotes: 4

Views: 178

Answers (1)

grtjn
grtjn

Reputation: 20414

All updates in MarkLogic execute in a transactional way. So, the first approach is equally safe in that regard. And yes, I think the first approach does do the same with just one call to the back-end instead of four. So, I'd personally say the first is more elegant, particularly since you are really just updating one document in the database.

HTH!

Upvotes: 2

Related Questions