A manager for CRUD operations on semantic graphs which reside in MarkLogic Server.
For example:
If you have a file called "example.nt" containing one triple in turtle mimetype:
<http://example.org/subject1> <http://example.org/predicate1> <http://example.org/object1> .
You could write it to the database in a graph called "myExample/graphUri" like so:
GraphManager graphMgr = databaseClient.newGraphManager();
FileHandle fileHandle = new FileHandle(new File("example.nt")).withMimetype(RDFMimeTypes.NTRIPLES);
graphMgr.write("myExample/graphUri", fileHandle);
Then you could add another triple to the graph like so:
StringHandle stringHandle = new StringHandle()
.with("<http://example.org/subject2> <http://example.org/predicate2> <http://example.org/object2> .")
.withMimetype(RDFMimeTypes.NTRIPLES);
graphMgr.merge("myExample/graphUri", stringHandle);
Then you read the graph from the database into turtle syntax into a variable "triples" like so:
String triples = graphMgr.read("myExample/graphUri",
new StringHandle().withMimetype(RDFMimeTypes.NTRIPLES)).get();
You could simplify these examples if you first set the default mimetype so you don't have to call setMimetype on each handle. That also enables you to use the *As convenience methods:
graphMgr.setDefaultMimetype(RDFMimeTypes.NTRIPLES);
String triples = graphMgr.readAs("myExample/graphUri", String.class);
If you need to limit access to a graph you can set the permissions:
graphMgr.writePermissions("myExample/graphUri",
graphMgr.permission("example_manager", Capability.READ)
.permission("example_manager", Capability.UPDATE));
Permissions can also be added with
mergePermissions, deleted with deletePermissions,
or set with calls to
write or
merge to a graph by providing the permissions
argument.
Each new instance of GraphManager is created by DatabaseClient.newGraphManager().
While these examples use FileHandle and StringHandle, any
TriplesWriteHandle may be used, including custom handles. While
JSONWriteHandles
will need to use RDFMimeTypes.RDFJSON
mimetype, and XMLWriteHandles
will need to use RDFMimeTypes.RDFXML
mimetype, most TriplesWriteHandles
can write any text mimteypt and can therefore write triples using
any of the RDFMimeTypes.
GraphManager is thread-safe other than setDefaultMimetype.
In other words the only state maintained by an instance is the
default mimetype. Common usage is to call setDefaultMimetype only
once then use the instance across many threads. If you intend to
call setDefaultMimetype from multiple threads, create a new
GraphManager for each thread.
For details about RDF, SPARQL, and semantics in MarkLogic see Semantics Developer's Guide
static final Stringvoidvoiddelete (String uri, Transaction transaction)voidvoiddeleteGraphs (Transaction transaction)voiddeletePermissions (String uri)voiddeletePermissions (String uri, Transaction transaction)getPermissions (String uri)getPermissions (String uri, Transaction transaction)voidmerge (String uri, TriplesWriteHandle handle)voidmerge (String uri, TriplesWriteHandle handle,
GraphPermissions permissions)voidmerge (String uri, TriplesWriteHandle handle,
GraphPermissions permissions,
Transaction transaction)voidmerge (String uri, TriplesWriteHandle handle,
Transaction transaction)voidvoidmergeAs (String uri, Object graphData, GraphPermissions permissions)voidmergeAs (String uri, Object graphData, GraphPermissions permissions,
Transaction transaction)voidmergeAs (String uri, Object graphData, Transaction transaction)voidmergeGraphs (QuadsWriteHandle handle)voidmergeGraphs (QuadsWriteHandle handle,
Transaction transaction)voidmergeGraphsAs (Object quadsData)voidmergeGraphsAs (Object quadsData, Transaction transaction)voidmergePermissions (String uri, GraphPermissions permissions)voidmergePermissions (String uri, GraphPermissions permissions,
Transaction transaction)permission (String role, Capability... capabilities)<T extends TriplesReadHandle>
T<T extends TriplesReadHandle>
Tread (String uri, T handle, Transaction transaction)<T> T<T> TreadAs (String uri, Class<T> as, Transaction transaction)voidreplaceGraphs (QuadsWriteHandle handle)voidreplaceGraphs (QuadsWriteHandle handle,
Transaction transaction)voidreplaceGraphsAs (Object quadsData)voidreplaceGraphsAs (Object quadsData, Transaction transaction)voidsetDefaultMimetype (String mimetype)<T extends TriplesReadHandle>
T<T> Tvoidwrite (String uri, TriplesWriteHandle handle)voidwrite (String uri, TriplesWriteHandle handle,
GraphPermissions permissions)voidwrite (String uri, TriplesWriteHandle handle,
GraphPermissions permissions,
Transaction transaction)voidwrite (String uri, TriplesWriteHandle handle,
Transaction transaction)voidvoidwriteAs (String uri, Object graphData, GraphPermissions permissions)voidwriteAs (String uri, Object graphData, GraphPermissions permissions,
Transaction transaction)voidwriteAs (String uri, Object graphData, Transaction transaction)voidwritePermissions (String uri, GraphPermissions permissions)voidwritePermissions (String uri, GraphPermissions permissions,
Transaction transaction)Use with any GraphManager method in place of the uri to work against the default graph. The string value is not important and for java-client internal use only--it is never sent to the database.
Example:
StringHandle stringHandle = new StringHandle()
.with("<http://example.org/subject2> <http://example.org/predicate2> <http://example.org/object2> .")
.withMimetype(RDFMimeTypes.NTRIPLES);
graphMgr.merge(DEFAULT_GRAPH, stringHandle);
Get the uri for available graphs.
Example:
Iterator<String> iter = graphMgr.listGraphUris();
while ( iter.hasNext() ) {
String uri = iter.next();
...
}
Read triples from the server. The server can serialize the
triples using any RDFMimeTypes except TRIG. Specify the desired
serialization mimetype by calling setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
T - the type of TriplesReadHandle to returnuri - the graph uri or DEFAULT_GRAPH constanthandle - the handle to populate and return, set
with the desired mimetype from RDFMimeTypesResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRead triples from the server. The server can serialize the
triples using any RDFMimeTypes except TRIG. Specify the desired
serialization mimetype by calling setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
T - the type of TriplesReadHandle to returnuri - the graph uri or DEFAULT_GRAPH constanthandle - the handle to populate and return with
the desired mimetype from RDFMimeTypes mimetype from
RDFMimeTypestransaction - the open transaction to read
fromResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRead triples from the server as the specified type. The server
can serialize the triples using any RDFMimeTypes except TRIG.
Specify the desired serialization using setDefaultMimetype.
T - the type of object that will be returned by
the handle registered for ituri - the graph uri or DEFAULT_GRAPH constantas - the type to populate and return. This type
must be registered by an io handle.ResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRead triples from the server as the specified type. The server
can serialize the triples using any RDFMimeTypes except TRIG.
Specify the desired serialization using setDefaultMimetype.
T - the type of object that will be returned by
the handle registered for ituri - the graph uri or DEFAULT_GRAPH constantas - the type to populate and return. This type
must be registered by an io handle.transaction - the open transaction to read
fromResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRetrieve permissions for a graph.
uri - the graph uri or DEFAULT_GRAPH constantResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRetrieve permissions for a graph.
uri - the graph uri or DEFAULT_GRAPH constanttransaction - the open transaction to read
fromResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionDelete all permissions for the graph.
uri - the graph uri or DEFAULT_GRAPH constantResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionDelete all permissions for the graph.
uri - the graph uri or DEFAULT_GRAPH constanttransaction - the open transaction to delete
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite all permissions for the graph.
uri - the graph uri or DEFAULT_GRAPH constantpermissions - the permissions to set for this
graphResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite all permissions for the graph.
uri - the graph uri or DEFAULT_GRAPH constantpermissions - the permissions to set for this
graphtransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd to permissions on the graph.
uri - the graph uri or DEFAULT_GRAPH constantpermissions - the permissions to add to this
graphResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd to permissions on the graph.
uri - the graph uri or DEFAULT_GRAPH constantpermissions - the permissions to add to this
graphtransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionrole - the name of the role receiving these
capabilitiescapabilities - the capabilities (READ, UPDATE, or
EXECUTE) granted to this roleAdd triples from the handle to the specified graph. The server
can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypesResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd triples from the handle to the specified graph. The server
can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypestransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd triples from the handle and add specified permissions to the
specified graph. The server can receive the triples as any of the
RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypespermissions - the permissions to add to this
graphResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd triples from the handle and add specified permissions to the
specified graph. The server can receive the triples as any of the
RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypespermissions - the permissions to add to this
graphtransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd triples from the graphData object to the specified graph.
The server can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
appropriate RDFMimeTypesMimetype}ResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd triples from the graphData object to the specified graph.
The server can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
RDFMimeTypes specified by setDefaultMimetypetransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd triples from the graphData object and add specified
permissions to the specified graph. The server can receive the
triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
RDFMimeTypes specified by setDefaultMimetypepermissions - the permissions to add to this
graphResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd triples from the graphData object and add specified
permissions to the specified graph. The server can receive the
triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
RDFMimeTypes specified by setDefaultMimetypepermissions - the permissions to add to this
graphtransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the handle as the specified graph. The
server can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypesResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the handle as the specified graph. The
server can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypestransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the handle and specified permissions as
the specified graph. The server can receive the triples as any of
the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypespermissions - the permissions to ovewrite for this
graphResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the handle and specified permissions as
the specified graph. The server can receive the triples as any of
the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
uri - the graph uri or DEFAULT_GRAPH constanthandle - the handle containing triples of
appropriate RDFMimeTypespermissions - the permissions to ovewrite for this
graphtransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the graphData object as the specified
graph. The server can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
RDFMimeTypes specified by setDefaultMimetypeResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the graphData object as the specified
graph. The server can receive the triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
RDFMimeTypes specified by setDefaultMimetypetransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the graphData object and specified
permissions as the specified graph. The server can receive the
triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
RDFMimeTypes specified by setDefaultMimetypepermissions - the permissions to ovewrite for this
graphResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionOverwrite triples from the graphData object and specified
permissions as the specified graph. The server can receive the
triples as any of the RDFMimeTypes.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
uri - the graph uri or DEFAULT_GRAPH constantgraphData - the object containing triples of
RDFMimeTypes specified by setDefaultMimetypepermissions - the permissions to ovewrite for this
graphtransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionPermanently delete the specified graph from the server.
uri - the graph uri or DEFAULT_GRAPH constantResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionPermanently delete the specified graph from the server.
uri - the graph uri or DEFAULT_GRAPH constanttransaction - the open transaction to delete
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRetrieves all triples related to specified subject or object
iris. The server can serialize the triples using any RDFMimeTypes
except TRIG. Specify the desired serialization mimetype by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
T - the type of TriplesReadHandle to returnhandle - the handle to populate and return with
the desired mimetype from RDFMimeTypesiris - the subject or object iris to retrieveResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRetrieves all triples related to specified subject or object
iris. The server can serialize the triples using any RDFMimeTypes
except TRIG. Specify the desired serialization using setDefaultMimetype.
T - the type of object that will be returned by
the handle registered for itas - the type to populate and return. This type
must be registered by an io handle.iris - the subject or object iris to retrieveResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd quads from the handle to the graphs specified in the quads
data. The server can receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
handle - the handle containing quads of
appropriate RDFMimeTypesResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd quads from the handle to the graphs specified in the quads
data. The server can receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
handle - the handle containing quads of
appropriate RDFMimeTypestransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd quads from the object to the graphs specified in the quads
data. The server can receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
quadsData - the object containing quads of
RDFMimeTypes specified by setDefaultMimetypeResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionAdd quads from the object to the graphs specified in the quads
data. The server can receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
quadsData - the object containing quads of
RDFMimeTypes specified by setDefaultMimetypetransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRemove all quads from all graphs then insert quads from the
handle to the graphs specified in the quads data. The server can
receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
handle - the handle containing quads of
appropriate RDFMimeTypesResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRemove all quads from all graphs then insert quads from the
handle to the graphs specified in the quads data. The server can
receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype
or handle.setMimetype
or withMimetype (if available) on your handle.
handle - the handle containing quads of
appropriate RDFMimeTypestransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRemove all quads from all graphs then insert quads from the
quadsData to the graphs specified in the quads data. The server can
receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
quadsData - the object containing quads of
RDFMimeTypes specified by setDefaultMimetypeResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionRemove all quads from all graphs then insert quads from the
quadsData to the graphs specified in the quads data. The server can
receive the quads as RDFMimeTypes.NQUADS or
RDFMimeTypes.TRIG.
Specify the mimetype appropriate for your content by calling
setDefaultMimetype.
quadsData - the object containing quads of
RDFMimeTypes specified by setDefaultMimetypetransaction - the open transaction to write
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionPermanently delete all quads from all graphs.
Permanently delete all quads from all graphs.
transaction - the open transaction to delete
inResourceNotFoundExceptionForbiddenUserExceptionFailedRequestExceptionmimetype - the new default mimetypeCopyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.