Package com.hp.hpl.jena.db

A general database backend for persistent storage of jena models.

See:
          Description

Interface Summary
IDBConnection Encapsulate the specification of a jdbc connection, mostly used to simplify the calling pattern for ModelRDB factory methods.
 

Class Summary
DBConnection Encapsulate the specification of a jdbc connection.
GraphRDB GraphRDB implementation This graph stores data persistently in a relational database.
ModelRDB A persistent relational database implemention of the RDF API.
 

Exception Summary
RDFRDBException Used to signal most errors with RDB access.
 

Package com.hp.hpl.jena.db Description

A general database backend for persistent storage of jena models. This is a preliminary Jena2 release that only supports one implementation, the relational model using MySQL. It is largely backwards-compatible with Jena1 but does not support the various Jena1 layouts. Also missing is support for reification and datatypes for literals. A future release will support these feature and enable additional database types and layouts.

Overview

The jena/db module provides an implementation of the jena model interface which stores the RDF statement information in a relational database.

Creating and accessing database instances

Database-backed RDF models are instances of the class jena.db.ModelRDB. As well as implementing the full jena.model.Model interface the static methods on ModelRDB provide means to create, extend and reopen database instances. For backwards-compatibility, Jena2 supports Jena1 methods for creating and opening databases (see release notes for details on changes).

In Jena2, the database type is specified as part of the database connection. Configuration information (model and database properties) are specified as statements in an RDF model. The following examples show how this is done.

Default models

First consider the situation where we have an available database but as yet it has no RDF models stored in it and we want to format it for holding RDF statements. To construct a default model use:

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    DBConnection dbcon = new DBConnection("jdbc:mysql://localhost/test", myusername, mypassword, "MySQL");
    ModelRDB model = ModelRDB.createModel(dbcon);

To later reopen that default model, use:

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    DBConnection dbcon = new DBConnection("jdbc:mysql://localhost/test", myusername, mypassword, "MySQL");
    ModelRDB model = ModelRDB.open(dbcon);

Multiple models per database

To place more than one model within a single database you'll need to give each one a name (so they may be distinguished later). Here is an example which checks to see if a specific named model exists and then creates or reopens it as necessary:

    String myModelName = "myModelName";
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    DBConnection dbcon = new DBConnection("jdbc:mysql://localhost/test", myusername, mypassword, "MySQL");
    ModelRDB model;
    if( !dbcon.containsModel( myModelName ) )
        model = ModelRDB.createModel(dbcon, myModelName);
    else
        model = ModelRDB.open(dbcon, myModelName);

Customizing the layout/optimization parameters

Database and model configuration parameters are declared as statements in an RDF model. Currently, properties may be retrieved but not specified. A future release will enable applications to set configuration parameters. The names of the configuration properties are specified in com.hp.hpl.jena.vocabulary.DB

To retrieve a Model containing the Database properties use:

    Model dbProperties = dbcon.getDatabaseProperties();

To retrieve a Model containing the properties of a model within the databae use:

    Model modelProperties = model.getModelProperties();

To access any particular property, use the standard jena Model interface (for example: listStatments).



Copyright © 2001-2003 Hewlett-Packard. All Rights Reserved.