1

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.

Harshit Saklecha
  • 100
  • 1
  • 10

2 Answers2

2

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.

  • Hey i am using graph manager of java-api for triples, is there any way to check if graph exists or not through GraphManager, i have updated the question again. – Harshit Saklecha Jan 04 '17 at 15:03
  • The closest is what Dave Cassel suggests - but in my case, with temporal data, listing existing graphs would, I believe, result in millions of responses. Using GraphManager, other than iterating over the list of available graphs, the only other option is to try to do an action on a graph and catch the ResourceNotFoundException failure(like getPermissions). But this is the approach you are already using already, I believe. – David Ennis -CleverLlamas.com Jan 04 '17 at 17:37
  • yes, catching the exception is what i am doing already, i thought there might be something to check if it exists, like rest head call you suggested, thanks for the response. – Harshit Saklecha Jan 05 '17 at 07:41
2

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.

Dave Cassel
  • 8,352
  • 20
  • 38