Jem, why not extend the REST API to implement that as a single request? That 
should give you the benefits of using the REST API, without requiring multiple 
requests.

http://docs.marklogic.com/guide/rest-dev/extensions discusses this feature and 
has an example that you could modify to suit your application.

BTW in your sample code below I would probably use fn:exists() rather than 
xdmp:exists(). You are using that boolean to decide whether or not to update 
the database. Therefore you probably want ACID consistency guarantees, which 
xdmp:exists explicitly avoids in its subexpression because it always runs 
timestamped. Replacing it with fn:exists(doc($documentUri)) will read-lock any 
document at $documentUri, which guarantees consistency and avoids a potential 
race condition.

-- Mike

On 19 Nov 2012, at 07:59 , Jem Rayfield <[email protected]> wrote:

> Hi,
> 
> Would I be correct that the following type of XQuery should be translated to 
> a sequence of REST calls using a tx-id.
> So, a single simple XQuery update such as:
> 
> if (xdmp:exists(doc($documentUri)))
> then (
>  if ($timeCode < xs:dateTime(doc($documentUri)/document/header/timeStamp) )
>  then ()
>  else (
>   xdmp:document-insert($documentUri, xdmp:unquote($xml), 
> xdmp:default-permissions(), local:getCollections())
>  )
> )else (
>  xdmp:document-insert($documentUri, xdmp:unquote($xml), 
> xdmp:default-permissions(), local:getCollections())
> )
> 
> Would be translated to a number of REST calls:
> 
> Get a transaction; /transactions
> Invoke XQuery to get time stamp using the tx id; /query
> Update Document using the tx id; /documents
> 
> Or is there a better way of doing this using the current REST API spec?
> There could be a lot of I/O etc for something quite simple.
> 
> I may have missed something here so please do point me in the right direction.
> 
> Cheers
> Jem
> 
>  
> 
> http://www.bbc.co.uk
> This e-mail (and any attachments) is confidential and may contain personal 
> views which are not the views of the BBC unless specifically stated.
> If you have received it in error, please delete it from your system.
> Do not use, copy or disclose the information in any way nor act in reliance 
> on it and notify the sender immediately.
> Please note that the BBC monitors e-mails sent or received.
> Further communication will signify your consent to this.
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to