rdf4j logo Eclipse rdf4j: documentation

Home

The SAIL API

The RDF4J SAIL (Storage And Inference Layer) API is a collection of interfaces designed for low-level transactional access to RDF data. It functions as a decoupling point between specific database implementations and the functional modules (parsers, query engines, end-user API access, etc) of the RDF4J framework.

Here, we document the design of the API and explain the roles and rationale behind the various interfaces. We also explain how various abstract base classes provided as part of the API can be reused by third-party implementors, in order to make implementing a SAIL-compatible database easier.

this document is currently in draft, and incomplete. Feedback and suggestions for change are welcome, either on our GitHub repo, or on the RDF4J Users Group.

1. Overview

SAIL Main interfaces
Figure 1. SAIL Main interfaces

In diagram SAIL Main interfaces we see an overview of the two main interfaces: Sail, and SailConnection. The Sail interface is the main access point for RDF storage. Roughly speaking, this is "the database". Each Sail object is composed of zero or more SailConnection objects. This is where all the actual database access functionality is concentrated. SailConnection provides methods to execute queries, retrieve and modify triples, and manage transactions.

1.1. AbstractSail and AbstractSailConnection

RDF4J provides default (abstract) implementations for most of the SAIL functionality, which can be reused (and of course overridden) by any concrete implementation.

Abstract base implementations
Figure 2. Abstract base implementations

The AbstractSail class (see diagram Abstract base implementations) provides base implementations of all methods of the Sail interface. It provides the following benefits to concrete Sail implementations:

  1. implementations of all required basic getter/setter methods

  2. store shutdown management, including grace periods for active connections and eventual forced closure of active connections on store shutdown.

  3. thread-safety: take care of basic concurrency issues around opening multiple connections.

  4. ongoing compatibility: future RDF4J releases that introduce new functionality in Sail provide default implementations in AbstractSail.

Similarly, the AbstractSailConnection provides base implementations of all methods of the SailConnection interface. It provides the following benefits to concrete SailConnection implementations:

  1. handles all basic concurrency issues around starting / executing transactions

  2. (configurable) buffering of active changes in any transaction

  3. ongoing compatibility: future RDF4J releases that introduce new functionality in SailConnection provide default implementations in AbstractSailConnection.

The abstract base classes use the naming convention methodnameInternal to indicate the methods that concrete subclasses should concentrate on implementing. The rationale is that the public method implementations in the abstract class implement basic concurrency handling and other book-keeping, and their corresponding (protected) …​Internal methods can be implemented by the concrete subclass to provide the actual business logic of the method.

For example, the query method AbstractSailConnection.getStatements() provides a lot of book keeping: it ensures pending updates are flushed, acquires a read lock on the connection, verifies the connection is still open, and takes care of internally registering the resulting Iteration from the query for resource management and concurrency purposes. In between all of this, it calls getStatementsInternal. The only job of this method is to answer the query by retrieving the relevant data from the data source.

1.2. NotifyingSail and AbstractNotifyingSail

The NotifyingSail and NotifyingSailConnection interfaces provide basic event handling for SAIL implementations. The main goal of these interfaces is to provide a messaging mechanism for closely-linked SAIL implementations (for example, a "Sail stack" where a reasoner is to be kept informed of changes to the underlying database).

NotifyingSail interfaces
Figure 3. NotifyingSail interfaces

As can be seen in diagram NotifyingSail interfaces, the NotifyingSail interface provides the option of registering one or more SailChangedListener implementations. When registered, the listener will be messaged via the sailChanged method. The contents of the message is a SailChangedEvent that provides basic info on what has been changed.

More fine-grained event data is available at the Connection level. The NotifyingSailConnection allows registering a SailConnectionListener, which receives a message for each individual statement added or removed on the connection.

RDF4J also provides base implementation classes for these two interfaces. As can be seen in diagram NotifyingSail interfaces, these classes - AbstractNotifyingSail and AbstractNotifyingSailConnection - are extensions of the AbstractSail(Connection) classes that add default implementations of the methods defined in the NotifyingSail(Connection) interfaces.

1.3. Stacking SAILs

Stackable SAIL interface
Figure 4. Stackable SAIL interface

The SAIL API provides the StackableSail interface to allow SAIL implementations to "stack" on top of each other, providing a chain of responsility: each SAIL implementation in the stack implements a specific feature (reasoning, access control, data filtering, query expansion, etc. etc.). The last SAIL implementation in the stack is expected to not implement StackableSail, and this Sail is responsible for the actual persistence of the data. RDF4J’s NativeStore and MemoryStore are implementations of such a persistence SAIL, while the ForwardChainingRDFSInferencer (responsible for RDFS inferencing) and LuceneSail (responsible for full-text indexing) are examples of StackableSail implementations.

2. Querying

The SAIL API has no knowledge of SPARQL queries. Instead, it operates on a query algebra, that is, an object representation of a (SPARQL) query as provided by the SPARQL query parser.

SailConnection has a single evaluate() method, which accepts a org.eclipse.rdf4j.queryalgebra.model.TupleExpr object. This is the object representation of the query as produced by the query parser.

3. Transactions

TODO