fter downloading
Sesame 3.0-alpha1, the first thing you might notice is that
Sesame 3.0 is packaged slightly differently than in 2.x. The awkwardly named
sesame-onejar.jar was replaced by sesame-client.jar and
sesame-runtime.jar, the openrdf-workbench.war file is gone, and there is a
new server script.The sesame-client.jar contains the RDF parsers and writers distributed with Sesame along with the repository API, HTTP client, and manager. This is the only jar you need for most RDF programs that don't embed an RDF store. If your application embeds its own RDF store, you can use the sesame-runtime.jar instead. This jar contains the familiar MemoryStore, NativeStore, RdbmsStore, and more. As with 2.x, Sesame Server and Console are not present in either of these jars, but you can find them in the lib directory of the SKD, along with scripts to run them.
By simply including the sesame-client.jar, all RDF parsers, writers, and basic model types such as URI, Literal, Statement, and Model are available. To demonstrate working with RDF files, the code in Listing 1 shows how to read in an RDF file, validate it, and then write it back out in an organized format.
// Sesame 2.x Repository API
RepositoryResult<Statement> result = con.getStatements(subj, pred, null, true);
try {
if (result.hasNext())
return result.next().getObject().stringValue();
return null;
} finally {
result.close();
}
// Sesame 3.0 Repository API
return con.match(subj, pred, null, true).asModel().objectString();
Every repository now includes RepositoryMetaData to allow an application to inquire about the features and behavior of the underlying RDF store. This provides the supported formats, query languages, functions, inferencing rules, and version used by the (possibly remote) repository.
The new 3.0 Repository API is not backwards compatible with the 2.x API. While many 2.x methods still exist (getStatements are deprecated in 3.0), some incompatibilities require client-side changes. The most prominent change in the Repository API is the Result types of both the RepositoryConnection and Query. Instead of the generic Result type of 2.x, 3.0 uses specific ContextResult and ModelResult. The TupleQuery now returns TupleResult from evaluate() and the GraphQuery now returns GraphResult. These are the most significant API changes in 3.0.
Blank nodes (Bnodes) are no longer globally referencable (as they were in Sesame 2.x); you can now only reference them within the same connection. Applications that used a BNode as a global reference must change to use a URI instead, as Sesame RDF stores might use different BNode IDs in different connections to reference the same internal resource. However, BNodes created outside of the connection automatically maps to a new BNode within that connection.
| Author's Note: A BNode Java object is only valid within the connection it was created or received from. |
This works similar to how RDF files are added to the RDF store: external BNodes are mapped to internal BNodes, within a particular scope. The following code demonstrates how you can use BNodes with Sesame 3.0.
BNode node = conA.getValueFactory().createBNode();
conA.add(node, RDF.TYPE, RDF.LIST);
conA.hasMatch(node, RDF.TYPE, RDF.LIST);
// [] no results because node was not created with conB
conB.hasMatch(node, RDF.TYPE, RDF.LIST); // maybe false
// contains the new statement, but with a different nodeID
conB.size(null, RDF.TYPE, RDF.LIST) >= 1;
Unlike the ANSI SQL isolation levels, Sesame distinguishes between snapshot and serializable isolation levels. Furthermore, Sesame's definition of snapshot isolation allows independent RDF stores to use eventual consistency to manage the changes to the store. This makes clusters of RDF stores easier to implement for connections that allow eventual consistency, but still require a consistent non-changing view of the store. Some of Sesame's lower levels of isolation explicitly permit the use of HTTP caching (with some restrictions). This allows connections that only need weak consistency to operate at a significantly enhanced speed, by not having to check for new modifications every time.
Most of the RDF stores are not yet optimized for each of the isolation levels. By adding them to the API now, system architects and developers can start planning if and how they will implement caching, validation, federation, and distribution of RDF stores. For more details on the exact isolation levels supported, see the JavaDoc that is provided with the release.
The following code represents an in-memory RDF store configuration (or template):
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rep: <http://www.openrdf.org/config/repository#>.
@prefix sr: <http://www.openrdf.org/config/repository/sail#>.
@prefix sail: <http://www.openrdf.org/config/sail#>.
@prefix ms: <http://www.openrdf.org/config/sail/memory#>.
[] a rep:Repository ;
rep:repositoryTitle "Memory store" ;
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository" ;
sr:sailImpl [
sail:sailType "openrdf:MemoryStore" ;
ms:persist true ;
ms:syncDelay 0
]
].
The following code is a memory RDF store wrapped in a RDFS inferencer and a dataset sail that auto-loads any query-referenced datasets (memory-rdfs-dataset.ttl):
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rep: <http://www.openrdf.org/config/repository#>.
@prefix sr: <http://www.openrdf.org/config/repository/sail#>.
@prefix sail: <http://www.openrdf.org/config/sail#>.
@prefix ms: <http://www.openrdf.org/config/sail/memory#>.
[] a rep:Repository ;
rep:repositoryTitle "Memory Dataset store" ;
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository" ;
sr:sailImpl [
sail:sailType "openrdf:DatasetSail" ;
sail:delegate [
sail:sailType "openrdf:ForwardChainingRDFSInferencer" ;
sail:delegate [
sail:sailType "openrdf:MemoryStore" ;
ms:persist true ;
ms:syncDelay 0
]
]
]
].
The Sesame Server and protocol was revamped to support transactions; now, a remote repository behaves the same as a local repository. This allows applications to develop using an embedded RDF store and later move to a remote RDF store, while keeping the same behavior. The protocol was also extended to support server-side prepared queries. Large queries that are executed multiple times within a connection can be stored on the server and parsed only once reducing evaluation overhead.
The Sesame Server was extended to support weak consistency when the -c option (number of seconds clients can use their cache before validating) is given a value greater then zero. This allows clients to store results from the server for a period of time before validating the value on the server, and is appropriate when speed is more important than seeing the effects of all write operations. This enables RDF stores to scale much higher by enabling intermediate proxies to cache the results. The Sesame HTTP repository uses weak consistency (if enabled) when running in auto-commit mode for sizeMatch and hasMatch results. By using an intermediate proxy between the client and server, you can cache other results such as match and query evaluation.
The Federation SAIL uses the new sizeMatch method of the RepositoryConnection for query optimizations. This causes noticeable delays when evaluating queries over large repositories. Changing the members to use weak consistency can help, but does not effect the time it takes to optimize new queries with new basic graph patterns. However, the Federation does have a few configuration options that can improve the query performance. The most significant is to ensure the members use the openrdf:SailRepository. This allows the Federation to transfer portions of the query to the members and significantly reduces bandwidth and evaluation latency. Setting the distinct configuration option to true allows you to stream results from the members without further processing; thus reducing memory and CPU usage in the Federation. The localPropertySpace configuration option reduces the cross-member joins done during query evaluation for members partitioned by statement subject. This combined with the openrdf:SailRepository drastically reduces the query processing overhead of multiple members. You can only use this option with predicates that are used with subjects that are co-located in the same member.
The HTTPRepository was overhauled to enable effective use within a Federation. It has two new configuration options that are specifically related to the Federation. These are the readOnly option and the subjectSpace option. The readOnly option prevents clients from writing to the remote store and informs the Federation which member should receive new statements. The subjectSpace option is an optimization that reduces redundant bandwidth by informing the Federation where a statement is located based on its subject.
| DevX is a division of Jupitermedia Corporation © Copyright 2007 Jupitermedia Corporation. All Rights Reserved. Legal Notices |