001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.repository.manager;
007:
008: import java.io.File;
009:
010: import org.slf4j.Logger;
011: import org.slf4j.LoggerFactory;
012:
013: import org.openrdf.model.vocabulary.RDF;
014: import org.openrdf.repository.Repository;
015: import org.openrdf.repository.RepositoryConnection;
016: import org.openrdf.repository.RepositoryException;
017: import org.openrdf.repository.config.RepositoryConfig;
018: import org.openrdf.repository.config.RepositoryConfigException;
019: import org.openrdf.repository.config.RepositoryConfigSchema;
020: import org.openrdf.repository.config.RepositoryConfigUtil;
021: import org.openrdf.repository.event.base.NotifyingRepositoryWrapper;
022: import org.openrdf.repository.sail.SailRepository;
023: import org.openrdf.sail.memory.MemoryStore;
024:
025: /**
026: * FIXME: do not extend NotifyingRepositoryWrapper, because SystemRepository
027: * shouldn't expose RepositoryWrapper behaviour, just implement
028: * NotifyingRepository.
029: *
030: * @author Herko ter Horst
031: * @author Arjohn Kampman
032: */
033: public class SystemRepository extends NotifyingRepositoryWrapper {
034:
035: /*-----------*
036: * Constants *
037: *-----------*/
038:
039: private final Logger logger = LoggerFactory.getLogger(this
040: .getClass());
041:
042: /**
043: * The repository identifier for the system repository that contains the
044: * configuration data.
045: */
046: public static final String ID = "SYSTEM";
047:
048: public static final String TITLE = "System configuration repository";
049:
050: public static final String REPOSITORY_TYPE = "openrdf:SystemRepository";
051:
052: /*--------------*
053: * Constructors *
054: *--------------*/
055:
056: public SystemRepository(File systemDir) throws RepositoryException {
057: super ();
058: super
059: .setDelegate(new SailRepository(new MemoryStore(
060: systemDir)));
061: }
062:
063: /*---------*
064: * Methods *
065: *---------*/
066:
067: @Override
068: public void initialize() throws RepositoryException {
069: super .initialize();
070:
071: RepositoryConnection con = getConnection();
072: try {
073: if (con.isEmpty()) {
074: logger.info("Initializing empty {} repository", ID);
075:
076: con.setAutoCommit(false);
077: con.setNamespace("rdf", RDF.NAMESPACE);
078: con.setNamespace("sys",
079: RepositoryConfigSchema.NAMESPACE);
080:
081: RepositoryConfig repConfig = new RepositoryConfig(ID,
082: TITLE, new SystemRepositoryConfig());
083: RepositoryConfigUtil.updateRepositoryConfigs(con,
084: repConfig);
085:
086: con.commit();
087: }
088: } catch (RepositoryConfigException e) {
089: throw new RepositoryException(e.getMessage(), e);
090: } finally {
091: con.close();
092: }
093: }
094:
095: @Override
096: public void setDelegate(Repository delegate) {
097: throw new UnsupportedOperationException(
098: "Setting delegate on system repository not allowed");
099: }
100: }
|