Previous Topic

Next Topic

Creating the Graph

The Comparison of JRDF Graph Implementations section outlines the advantages and disadvantages of the different implementation options. Choose the one that is most suitable for your requirements.

You can create more than one graph and use them together. For example, you might use an iTQL graph to retrieve results from a query, load the contents into a memory graph for efficient presentation and editing, and then persist the edited statements using a client graph.

In This Section

JRDF Graph (Memory Graph)

Server-side JRDF Graph (Server Graph)

Server Backed JRDF Graph (Client Graph)

Read Only iTQL Result JRDF Graph (iTQL Graph)

See Also

JRDF Tutorial

Prerequisites

Obtaining a Session from a Mulgara Server

Comparison of JRDF Graph Implementations

Creating Nodes and Triples

Adding Triples to the Graph

Searching the Graph

Reify Triples

Removing Triples from the Graph

JRDF Graph (Memory Graph)

The following code creates a memory graph:

Graph graph = new GraphImpl();

Server-side JRDF Graph (Server Graph)

You need to obtain a session for your Mulgara server before you can create a server graph. When obtaining the session, use SessionFactoryFinder.newSessionFactory(serverURI, false) to indicate that the server is running in the same JVM (that is, it is running locally).

The server graph is created using a LocalJRDFSession. See the Obtaining a Session from the TKS Server section for more information on how to obtain a LocalJRDFSession.

After obtaining a local session, the following code creates a server graph:

//create a new Model
URI modelURI = new URI("rmi://mysite.com/server1#exampleGraph");
URI modelType = new URI("http://mulgara.org/mulgara#Model");
session.createModel(modelURI, modelType);

//create a JRDF Graph for the model
Graph graph = new JRDFGraph(session, modelURI);

Server Backed JRDF Graph (Client Graph)

You need to obtain a session for your Mulgara server before you can create a client graph. When obtaining the session, use SessionFactoryFinder.newSessionFactory(serverURI, true) to indicate that the server is running remotely.

The Client Graph is created using a JRDFSession. See the Obtaining a Session from the Mulgara Server section for more information on how to obtain a JRDFSession.

After obtaining a session, the following code creates a client graph:

//create a new Model
URI modelURI = new URI("rmi://mysite.com/server1#exampleGraph");
URI modelType = new URI("http://mulgara.org/mulgara#Model");
session.createModel(modelURI, modelType);

//create a JRDF Graph for the model
Graph graph = AbstractGraphFactory.createGraph(modelURI, session);

The code session.createModel(modelURI, modelType); creates a new model if the model does not exist. If the model already exists, this line is not required.

Read Only iTQL Result JRDF Graph (iTQL Graph)

You need to obtain a session for your Mulgara server before you can create an iTQL graph. After obtaining a session, the following code creates an iTQL graph.

//create the query
String queryText = "select $s $p $o from <rmi://mysite.com/server1#testModel> where $s $p $o ; ";
ItqlInterpreter interpreter = new ItqlInterpreter(new HashMap());
Query query = interpreter.parse(queryText);

//execute the query
Answer queryResult = session.query(query);

//create a JRDF Graph
Graph graph = AbstractGraphFactory.createGraph(queryResult);

The iTQL query select $s $p $o from <rmi://mysite.com/server1#testModel> where $s $p $o; returns all statements from the model.

Open Source logo

© 2001-2004 Tucana Technologies, Inc. Some rights reserved.

© 2006 The Mulgara Project. Some rights reserved.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".