mulgara - semantic store

skip navigation

SHOW SITE NAV
fixed
fluid
straight

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.

 

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.

Valid XHTML 1.0 TransitionalValid CSS 3.0!