how to check if a graph exists or not in marklogic database?

99 views Asked by At

I am using java-api of Marklogic database, As per my requirement I delete the triple graph each time I receive request and then create a new one with triples. For now I have wrapped the code in try-catch block to catch exception and proceed.

try {
    GraphManager graphManager = client.newGraphManager();
    graphManager.setDefaultMimetype(RDFMimeTypes.NTRIPLES);
    graphManager.delete(graphUri)
}
catch (Exception ex) {
    // do nothing for this
}

Is there any better way to check for the existing graph of triples with graph manager, I have seen graph manager class, but I didn't find any way to check availability of graph.

2

There are 2 answers

2
Dave Cassel On

With GraphManager, call listGraphUris. That will give you an Iterator<String>. Loop through that to check whether the URI of the graph you're interested in is present.

3
David Ennis  -CleverLlamas.com On

Please see this endpoint:

https://docs.marklogic.com/REST/HEAD/v1/graphs

I prefer to use: https://docs.marklogic.com/REST/GET/v1/graphs With the named graph and category set to 'metadata.