com.hp.hpl.mesa.rdf.jena.rdb
Class ModelRDB

java.lang.Object
  |
  +--com.hp.hpl.mesa.rdf.jena.common.ModelCom
        |
        +--com.hp.hpl.mesa.rdf.jena.rdb.ModelRDB
All Implemented Interfaces:
Model, ModelCon, ModelI, RDFReaderF, RDFWriterF

public class ModelRDB
extends ModelCom
implements Model, ModelI

This implementation of the Model interface uses a relational database to hold the model statements. This provides persistence, transactions and scaling at the expense of performance. It doesn't provide query support since the jena query interface is currently procedural rather than declarative.

Different SQL dialects and different table layout structures are supported by delegating all database access to a separate IRDBSpec implementation.

The constructor will open the default model on a jdbc url whereas a variety of static factory methods are available for creating and reopening database.

Version:
$Revision: 1.3 $ on $Date: 2001/12/06 11:55:09 $
Author:
Dave Reynolds

Constructor Summary
ModelRDB(IDBConnection dbcon)
          Return the default model from the specified database.
 
Method Summary
 Model abort()
          Abort the current transaction and abandon any changes in progress.
 Model begin()
          Begin a new transation.
 void close()
          Close the Model and free up resources held.
 Model commit()
          Commit the current transaction.
 Property convert(Property p)
          Convert a property to a database implementation
 RDFNode convert(RDFNode n)
          Convert a node (property, resource or literal) to a database implementation
 Resource convert(Resource r)
          Convert a resource to a database implementation
static ModelRDB create(IDBConnection dbcon, java.lang.String layoutType, java.lang.String databaseType)
          Create a new database suitable for storing RDF data.
 IConstraints createConstraints()
          Create a constraint object appropriate for this type of database layout
static ModelRDB createModel(IDBConnection dbcon, java.lang.String name)
          Create a new model on an existing, preformatted database.
 Model difference(Model model)
          Create a new model containing all the statements in this model which are not in another.
 IDBID getDBID()
          Return the database index id for this model.
 StoreRDB getStore()
          Return the store which underpins this model
 boolean independent()
          Determine whether this model is independent.
 Model intersection(Model model)
          Create a new model containing all the statements which are in both this model and another.
static java.util.Iterator listModels(IDBConnection dbcon)
          List the name of all models stored in the database
 StmtIterator listStatements(IConstraints constraints)
          List all the statements in the given moddel which make the given set of constraints (a constraint set can be obtained using createConstraints()).
static ModelRDB open(IDBConnection dbcon)
          Open an existing rdf database.
static ModelRDB open(IDBConnection dbcon, java.lang.String name)
          Open an existing rdf database.
 Model query(Selector selector)
          Create a new model containing the statements matching a query.
 boolean supportsSetOperations()
          Determine whether this model supports set operations.
 boolean supportsTransactions()
          Determine whether this model supports transactions.
 Model union(Model model)
          Create a new model containing all the statements in this model together with all of those in another given model.
 
Methods inherited from class com.hp.hpl.mesa.rdf.jena.common.ModelCom
add, add, add, add, add, add, add, add, add, add, add, add, add, add, containerContains, containerIndexOf, containerSize, contains, contains, contains, contains, contains, contains, contains, contains, contains, contains, contains, containsAll, containsAll, containsAny, containsAny, createAlt, createAlt, createBag, createBag, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createProperty, createProperty, createResource, createResource, createResource, createResource, createResource, createResource, createSeq, createSeq, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, equals, getAlt, getAlt, getBag, getBag, getProperty, getProperty, getProperty, getReader, getReader, getResource, getResource, getSeq, getSeq, getWriter, getWriter, isReified, listContainerMembers, listNameSpaces, listObjects, listObjectsOfProperty, listObjectsOfProperty, listReifiedStatements, listStatements, listStatements, listSubjects, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, read, read, read, read, remove, remove, remove, setReaderClassName, setWriterClassName, size, write, write, write
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.Model
add, add, add, contains, contains, contains, containsAll, containsAll, containsAny, containsAny, createLiteral, createLiteral, createProperty, createResource, createResource, createStatement, equals, getProperty, getProperty, getResource, isReified, listNameSpaces, listObjects, listObjectsOfProperty, listObjectsOfProperty, listReifiedStatements, listStatements, listStatements, listSubjects, listSubjectsWithProperty, listSubjectsWithProperty, read, read, read, read, remove, size, write, write, write
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.ModelCon
add, add, add, add, add, add, add, add, add, add, add, contains, contains, contains, contains, contains, contains, contains, contains, createAlt, createAlt, createBag, createBag, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createProperty, createResource, createResource, createResource, createResource, createSeq, createSeq, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, getAlt, getAlt, getBag, getBag, getProperty, getResource, getSeq, getSeq, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, remove, remove
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.RDFReaderF
getReader, getReader, setReaderClassName
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.RDFWriterF
getWriter, getWriter, setWriterClassName
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.common.ModelI
containerContains, containerIndexOf, containerSize, listContainerMembers
 

Constructor Detail

ModelRDB

public ModelRDB(IDBConnection dbcon)
         throws RDFRDBException
Return the default model from the specified database. If the database does not appear to be formated it formats it and creates an empty default model.
Parameters:
dbcon - a DBConnectionI specifying the database connection
Throws:
RDFRDBException - if the database cannot be opened
Method Detail

open

public static ModelRDB open(IDBConnection dbcon,
                            java.lang.String name)
                     throws RDFRDBException
Open an existing rdf database. The layout and datatype type information will be dynamically loaded from the database. Will throw an RDFRDBException if the database layout does not support multiple models or if the database does not seem to formated.
Parameters:
dbcon - a DBConnectionI specifying the database connection
name - the name of the RDF model to open, some database layouts support multiple models in a single database

open

public static ModelRDB open(IDBConnection dbcon)
                     throws RDFRDBException
Open an existing rdf database. The layout and datatype type information will be dynamically loaded from the database. If the database supports more than one model then the "default" model will be opended.
Parameters:
dbcon - a DBConnectionI specifying the database connection

createModel

public static ModelRDB createModel(IDBConnection dbcon,
                                   java.lang.String name)
                            throws RDFRDBException
Create a new model on an existing, preformatted database. Will throw an RDFRDBException if the database layout does not support multiple models or if the database does not seem to formated.
Parameters:
dbcon - a DBConnectionI specifying the database connection
name - the name to give the newly created model

listModels

public static java.util.Iterator listModels(IDBConnection dbcon)
                                     throws RDFRDBException
List the name of all models stored in the database

create

public static ModelRDB create(IDBConnection dbcon,
                              java.lang.String layoutType,
                              java.lang.String databaseType)
                       throws RDFRDBException
Create a new database suitable for storing RDF data. In fact the database has to exist since jdbc can't create an empty database from a vacuum but it can be empty and this call will format with appropriate tables and stored procedures.

The appropriate RDF-RDB driver to use is assumed to be the class Driver. If that can't be found it defaults to looking for a property file in /etc/Driver.config and using that to determine the driver class and parameters.

Parameters:
dbcon - a DBConnectionI specifying the database connection
layoutType - the name of the layout style to use. Currently one of: "Generic", "Hash", "MMGeneric", "MMHash", "Proc", "ThinProc" etc.
databaseType - the name of the database type. Currently one of: "Interbase" "Postgresql" etc. This may seem a little redundant given that the jdbc uri implicitly contains this information but there is no standard way of extracting this (esp. if the user connects via a bridge).

close

public void close()
Close the Model and free up resources held.

Not all implementations of Model require this method to be called. But some do, so in general its best to call it when done with the object, rather than leave it to the finalizer.

Specified by:
close in interface Model
Overrides:
close in class ModelCom

getStore

public StoreRDB getStore()
Return the store which underpins this model

getDBID

public IDBID getDBID()
Return the database index id for this model. This will be 0 unless the underlying database layout supports multiple models per database.

listStatements

public StmtIterator listStatements(IConstraints constraints)
                            throws RDFException
List all the statements in the given moddel which make the given set of constraints (a constraint set can be obtained using createConstraints()).

createConstraints

public IConstraints createConstraints()
Create a constraint object appropriate for this type of database layout

convert

public Resource convert(Resource r)
                 throws RDFException
Convert a resource to a database implementation
Specified by:
convert in interface ModelI
Overrides:
convert in class ModelCom
Following copied from interface: com.hp.hpl.mesa.rdf.jena.common.ModelI
Parameters:
r -  
Returns:
the converted resource
Throws:
RDFException -  

convert

public Property convert(Property p)
                 throws RDFException
Convert a property to a database implementation
Specified by:
convert in interface ModelI
Overrides:
convert in class ModelCom
Following copied from interface: com.hp.hpl.mesa.rdf.jena.common.ModelI
Parameters:
p -  
Returns:
the converted property
Throws:
RDFException -  

convert

public RDFNode convert(RDFNode n)
                throws RDFException
Convert a node (property, resource or literal) to a database implementation
Specified by:
convert in interface ModelI
Overrides:
convert in class ModelCom
Following copied from interface: com.hp.hpl.mesa.rdf.jena.common.ModelI
Parameters:
n -  
Returns:
the converted node
Throws:
RDFException -  

begin

public Model begin()
            throws RDFException
Begin a new transation.

All changes made to a model within a transaction, will either be made, or none of them will be made.

Specified by:
begin in interface Model
Overrides:
begin in class ModelCom
Returns:
this model to enable cascading.
Throws:
RDFException - Generic RDF Exception

abort

public Model abort()
            throws RDFException
Abort the current transaction and abandon any changes in progress.
Specified by:
abort in interface Model
Overrides:
abort in class ModelCom
Returns:
this model to enable cascading.
Throws:
RDFException - Generic RDF Exception

commit

public Model commit()
             throws RDFException
Commit the current transaction.
Specified by:
commit in interface Model
Overrides:
commit in class ModelCom
Returns:
this model to enable cascading.
Throws:
RDFException - Generic RDF Exception

independent

public boolean independent()
Determine whether this model is independent.

For efficiency reasons, some implementations may create models which which are dependent on others, i.e. a change in one model may cause a change in another. If this is the case this method will return false, otherwise it will return true.

Specified by:
independent in interface Model
Overrides:
independent in class ModelCom
Returns:
true if this model is indepdent of others

supportsTransactions

public boolean supportsTransactions()
Determine whether this model supports transactions.
Specified by:
supportsTransactions in interface Model
Returns:
true if this model supports transactions.

supportsSetOperations

public boolean supportsSetOperations()
Description copied from interface: Model
Determine whether this model supports set operations.
Specified by:
supportsSetOperations in interface Model
Following copied from interface: com.hp.hpl.mesa.rdf.jena.model.Model
Returns:
true if this model supports set operations.

query

public Model query(Selector selector)
            throws RDFException
Description copied from interface: Model
Create a new model containing the statements matching a query.

A statment is considered to match if the test method of s returns true when called on s.

Specified by:
query in interface Model
Following copied from interface: com.hp.hpl.mesa.rdf.jena.model.Model
Parameters:
s - A selector object.
Returns:
an iterator over the matching statements
Throws:
RDFException - Generic RDF exception.

union

public Model union(Model model)
            throws RDFException
Description copied from interface: Model
Create a new model containing all the statements in this model together with all of those in another given model.
Specified by:
union in interface Model
Following copied from interface: com.hp.hpl.mesa.rdf.jena.model.Model
Parameters:
model - The other model whose statements are to be included.
Returns:
A new model containing all the statements that are in either model
Throws:
RDFException - Generic RDF Exception

intersection

public Model intersection(Model model)
                   throws RDFException
Description copied from interface: Model
Create a new model containing all the statements which are in both this model and another. As models are sets of statements, a statement contained in both models will only appear once in the resulting model.
Specified by:
intersection in interface Model
Following copied from interface: com.hp.hpl.mesa.rdf.jena.model.Model
Parameters:
model - The other model.
Returns:
A new model containing all the statements that are in both models.
Throws:
RDFException - Generic RDF Exception

difference

public Model difference(Model model)
                 throws RDFException
Description copied from interface: Model
Create a new model containing all the statements in this model which are not in another.
Specified by:
difference in interface Model
Following copied from interface: com.hp.hpl.mesa.rdf.jena.model.Model
Parameters:
model - the other model whose statements are to be excluded.
Returns:
a new model containing all the statements in this model that are not in the given model.
Throws:
RDFException - Generic RDF Exception


Copyright 2001 Hewlett-Packard. All Rights Reserved.