001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.repository.sail;
007:
008: import java.io.File;
009:
010: import org.openrdf.model.ValueFactory;
011: import org.openrdf.repository.Repository;
012: import org.openrdf.repository.RepositoryException;
013: import org.openrdf.sail.Sail;
014: import org.openrdf.sail.SailException;
015:
016: /**
017: * An implementation of the {@link Repository} interface that operates on a
018: * (stack of) {@link Sail Sail} object(s). The behaviour of the repository is
019: * determined by the Sail stack that it operates on; for example, the repository
020: * will only support RDF Schema or OWL semantics if the Sail stack includes an
021: * inferencer for this.
022: * <p>
023: * Creating a repository object of this type is very easy. For example, the
024: * following code creates and initializes a main-memory store with RDF Schema
025: * semantics:
026: *
027: * <pre>
028: * Repository repository = new RepositoryImpl(new ForwardChainingRDFSInferencer(new MemoryStore()));
029: * repository.initialize();
030: * </pre>
031: *
032: * Or, alternatively:
033: *
034: * <pre>
035: * Sail sailStack = new MemoryStore();
036: * sailStack = new ForwardChainingRDFSInferencer(sailStack);
037: *
038: * Repository repository = new Repository(sailStack);
039: * repository.initialize();
040: * </pre>
041: *
042: * @author Arjohn Kampman
043: */
044: public class SailRepository implements Repository {
045:
046: /*-----------*
047: * Constants *
048: *-----------*/
049:
050: private final Sail sail;
051:
052: /*--------------*
053: * Constructors *
054: *--------------*/
055:
056: /**
057: * Creates a new repository object that operates on the supplied Sail.
058: *
059: * @param sail
060: * A Sail object.
061: */
062: public SailRepository(Sail sail) {
063: this .sail = sail;
064: }
065:
066: /*---------*
067: * Methods *
068: *---------*/
069:
070: public File getDataDir() {
071: return sail.getDataDir();
072: }
073:
074: public void setDataDir(File dataDir) {
075: sail.setDataDir(dataDir);
076: }
077:
078: public void initialize() throws RepositoryException {
079: try {
080: sail.initialize();
081: } catch (SailException e) {
082: throw new RepositoryException(e.getMessage(), e);
083: }
084: }
085:
086: public void shutDown() throws RepositoryException {
087: try {
088: sail.shutDown();
089: } catch (SailException e) {
090: throw new RepositoryException("Unable to shutdown Sail", e);
091: }
092: }
093:
094: /**
095: * Gets the Sail object that is on top of the Sail stack that this repository
096: * operates on.
097: *
098: * @return A Sail object.
099: */
100: public Sail getSail() {
101: return sail;
102: }
103:
104: public boolean isWritable() throws RepositoryException {
105: try {
106: return sail.isWritable();
107: } catch (SailException e) {
108: throw new RepositoryException(
109: "Unable to determine writable status of Sail", e);
110: }
111: }
112:
113: public ValueFactory getValueFactory() {
114: return sail.getValueFactory();
115: }
116:
117: public SailRepositoryConnection getConnection()
118: throws RepositoryException {
119: try {
120: return new SailRepositoryConnection(this , sail
121: .getConnection());
122: } catch (SailException e) {
123: throw new RepositoryException(e);
124: }
125: }
126: }
|