[MarkLogic Dev General] question about transactions

Geert Josten Geert.Josten at marklogic.com
Wed Jan 24 21:49:35 PST 2018


The outer query runs in query mode, so runs against the timestamp of initial invocation, causing it to never see the result of sem:rdf-insert. You’d have to put the sem:sparql in an xdmp:eval with different-transaction as well.

I also wonder though: what are you trying to do, why trying to squeeze insert and read in one request?

Cheers,
Geert

From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of David Ennis <David.Ennis at marklogic.com<mailto:David.Ennis at marklogic.com>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Wednesday, January 24, 2018 at 7:34 PM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] question about transactions

Please look up the options for xdmp:eval and note the following options explained there:
- transaction-mode
- isolation

Then change your eval to have the following options:
- transaction-mode=update-auto-commit
- isolation = different transaction

Then move the sem:sparql statement below the eval in your main code.

What are you doing here?

You are telling the insert to run as a separate transaction and auto-commit. This makes the triples available immediately after the eval is done. Therefore, you should run the select in the main code and not the isolated transaction.

Careful with the use of different transactions via eval and invoke. The wrong combination can get you into a deadlock.

Regards,
David Ennis

--


From: <general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com>> on behalf of Erik Zander <Erik.Zander at studentlitteratur.se<mailto:Erik.Zander at studentlitteratur.se>>
Reply-To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Date: Wednesday, January 24, 2018 at 5:35 PM
To: MarkLogic Developer Discussion <general at developer.marklogic.com<mailto:general at developer.marklogic.com>>
Subject: [MarkLogic Dev General] question about transactions

Hi All,

I have a question about I think transactions.

I want to insert some rdf and then query the database, and I want to do this in a function so I can call the function and depending on if I have the data in Marklogic or not get the data as rdf and insert it.

But my problem is that the following code only returns result second time I call it.
I’m thankful for pointers here
Regards
Erik
Code below
==============================================

xquery version "1.0-ml"encoding "utf-8";


import module namespace sem="http://marklogic.com/semantics"
      at"/MarkLogic/semantics.xqy";
declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";

let $wDataRdf:=
<rdf:RDF
                      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                      xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"

                      xmlns:wikibase="http://wikiba.se/ontology#"
                      xmlns:wd="http://www.wikidata.org/entity/"
                      >
    <rdf:Descriptionrdf:about="http://www.wikidata.org/entity/Q925hhq">
        <rdfs:labelxml:lang="sv">mup</rdfs:label>
    </rdf:Description>

</rdf:RDF>
let$insert:=  xdmp:eval(
            '
            import module namespace sem = "http://marklogic.com/semantics"
      at "/MarkLogic/semantics.xqy";
            declare variable $wDataRdf as node() external;
            sem:rdf-insert(sem:rdf-parse($wDataRdf,("rdfxml", "graph=http://www.wikidata.org")))'
            ,(xs:QName("wDataRdf"),$wDataRdf)
            )
return sem:sparql('
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label WHERE {
   wd:Q925hhq  rdfs:label ?label
   FILTER (langMatches( lang(?label), "SV" ) )
}'
)




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20180125/28af054d/attachment-0001.html 


More information about the General mailing list