Project

General

Profile

Actions

UserAPI » History » Revision 1

Revision 1/9 | Next »
Paula Gearon, 05/15/2008 08:24 PM


= Connections =
Mulgara now supports a new interface called a `Connection`. This will be replacing the current `ItqlInterpreterBean` interface as the full suite of utilities becomes available.

The existing `ItqlInterpreterBean` interface provides a completely automated connection mechanism, based on the URLs of graphs referenced in TQL queries. While convenient, this has several undesirable effects:
  • All queries issued to this interface must contain at least one URL for a graph on the server that will handle the query.
  • Arbitrary graph names are not permitted. Graph names must follow a particular format, and will include the hostname of the server containing the graph.
  • Queries against graphs must be changed when the server hosting the graph changes.
  • Connections to a server cannot be cached.
  • Distributed queries (queries where the requested data comes from more than one server) are sent to an arbitrary server and not necessarily the most desirable one.
  • Query languages which use a default graph name (like [http://www.w3.org/TR/rdf-sparql-query/ SPARQL]) cannot identify a server if no graph names are given.

The `Connection` interface avoids these issues by establishing a link to a specified server. This link can be to a server running in the current process, over inter-process-communication (IPC) to a server running on the same machine, or across a network. Queries and commands can be sent along this link, and all operations will be performed by the server that has been connected to.

The `Connection` interface and its supporting classes are found in the `org.mulgara.connection` package.

Connection Factory
While Connections can be created directly, the `ConnectionFactory` class attempts to manage connections to ensure that the correct type is created, and reduce network overhead. The connections returned by a `ConnectionFactory` are only managed by that factory, and will not interfere with connections from a separate factory instance.

`Connection`s can be established based on the URL of a database (in the form ''protocol''://''host''/''service'') or by wrapping a `Session` instance. The `Session` interface has existed in Mulgara for some time, and it may be more appropriate for existing code to use its internal `Session` instances to create new `Connection`s.

For the moment, the only supported protocol is ''rmi''. Other protocols, including ''http'' are expected shortly.

Using a Connection
Once a `Connection` has been created, commands can be sent on it using the `execute` method. Alternatively, commands also have their own `execute` method that can be applied to a connection, with the same effect.

The following is an example of using a Connection to create a graph, and load a file into that graph: {{{
#!java
// define the server we want to connect to
URI serverURI = new URI;
// define the file we want to load
URI dataFile = new File("data.rdf").toURI();
// define the name of the graph to load the data into
URI myData = new URI;

// Create a factory, and connect to the server
ConnectionFactory factory = new ConnectionFactory();
Connection connection = factory.newConnection(serverUri);
// execute a CREATE command
connection.execute(new CreateGraph(myData));
// execute a LOAD command
connection.execute(new Load(dataFile, myData, true));
// cleaning up the connection allows the network resources to be re-used
connection.close();
}}}

Updated by Paula Gearon almost 16 years ago · 1 revisions