Search in sources :

Example 6 with Repository

use of org.openrdf.repository.Repository in project stanbol by apache.

the class SesameYardComponent method addingService.

@Override
public Object addingService(ServiceReference serviceReference) {
    Repository repo = (Repository) bundleContext.getService(serviceReference);
    if (repo == null) {
        log.error("could not retrieve Sesame Repository for ServiceRefernece {} " + "(repository name: {})", serviceReference, repoId);
    } else {
        if (repoServiceReference != null) {
            //check if the added service reference has a higher ranking
            if (serviceReference.compareTo(repoServiceReference) > 0) {
                log.info("re-regsiter SesameYard because ServiceReference {} " + "has a higher ranking as the currently used one {}!", serviceReference, repoServiceReference);
                unregisterSesameYard();
                registerSesameYard(serviceReference, repo);
            }
        //else the added reference has a lower ranking ... nothing todo
        } else {
            //first service is registered
            registerSesameYard(serviceReference, repo);
        }
    }
    return repo;
}
Also used : Repository(org.openrdf.repository.Repository)

Example 7 with Repository

use of org.openrdf.repository.Repository in project backstage by zepheira.

the class DataLoadingUtilities method loadDataFromStream.

public static void loadDataFromStream(InputStream stream, String sourceURL, String lang, Sail sail) throws Exception {
    RepoSailTuple rs = createMemoryRepository(null);
    Repository r = rs.repository;
    lang = lang.toLowerCase();
    if ("exhibit/json".equals(lang)) {
        Properties properties = new Properties();
        BabelReader reader = new ExhibitJsonReader();
        try {
            if (reader.takesReader()) {
                InputStreamReader isr = new InputStreamReader(stream);
                reader.read(isr, sail, properties, Locale.getDefault());
            } else {
                reader.read(stream, sail, properties, Locale.getDefault());
            }
        } finally {
            stream.close();
        }
    } else {
        RDFParser parser = null;
        if ("rdfxml".equals(lang)) {
            parser = new RDFXMLParser(r.getValueFactory());
        } else if ("n3".equals(lang) || "turtle".equals(lang)) {
            parser = new TurtleParser(r.getValueFactory());
        } else if ("ntriples".equals(lang)) {
            parser = new NTriplesParser(r.getValueFactory());
        }
        try {
            SailConnection c = null;
            try {
                c = sail.getConnection();
                BNodeConverterStatementHandler handler = new BNodeConverterStatementHandler(c);
                parser.setRDFHandler(handler);
                parser.setParseErrorListener(new LoggingParseErrorListener(sourceURL));
                parser.setVerifyData(false);
                parser.setStopAtFirstError(false);
                parser.parse(stream, sourceURL);
                c.commit();
                _logger.info("Read " + handler.m_count + " statements from '" + sourceURL + "'");
            } catch (RepositoryException e) {
                if (c != null)
                    c.rollback();
            } finally {
                if (c != null)
                    c.close();
            }
        } catch (Exception e) {
            throw new ModelReadFromFileException("Failed to read data from '" + sourceURL + "'", e);
        } finally {
            stream.close();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) RDFXMLParser(org.openrdf.rio.rdfxml.RDFXMLParser) NTriplesParser(org.openrdf.rio.ntriples.NTriplesParser) RepositoryException(org.openrdf.repository.RepositoryException) Properties(java.util.Properties) RDFParser(org.openrdf.rio.RDFParser) SailException(org.openrdf.sail.SailException) RepositoryException(org.openrdf.repository.RepositoryException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TurtleParser(org.openrdf.rio.turtle.TurtleParser) SailRepository(org.openrdf.repository.sail.SailRepository) Repository(org.openrdf.repository.Repository) BabelReader(edu.mit.simile.babel.BabelReader) SailConnection(org.openrdf.sail.SailConnection) ExhibitJsonReader(edu.mit.simile.babel.exhibit.ExhibitJsonReader)

Example 8 with Repository

use of org.openrdf.repository.Repository in project stanbol by apache.

the class SesameYardComponent method removedService.

@Override
@SuppressWarnings("unchecked")
public void removedService(ServiceReference serviceReference, Object o) {
    if (serviceReference.equals(repoServiceReference)) {
        log.info(" - currently used Repository was removed (ref: {})", serviceReference);
        unregisterSesameYard();
    }
    ServiceReference[] serviceRefs = repositoryTracker.getServiceReferences();
    List<ServiceReference> others = serviceRefs == null ? Collections.<ServiceReference>emptyList() : Arrays.asList(serviceRefs);
    if (others.size() > 1) {
        //sort by priority
        Collections.sort(others);
    }
    boolean registered = false;
    for (Iterator<ServiceReference> refs = others.iterator(); !registered && refs.hasNext(); ) {
        ServiceReference ref = refs.next();
        Repository repo = (Repository) repositoryTracker.getService(ref);
        if (repo != null) {
            log.info(" - re-register Yard with other available repository {}", ref);
            registerSesameYard(ref, repo);
            registered = true;
        }
    }
    bundleContext.ungetService(serviceReference);
}
Also used : Repository(org.openrdf.repository.Repository) ServiceReference(org.osgi.framework.ServiceReference)

Example 9 with Repository

use of org.openrdf.repository.Repository in project gocd by gocd.

the class InMemoryRepositoryFactory method emptyRepository.

public static Repository emptyRepository() {
    try {
        Repository repo = new SailRepository(new MemoryStore());
        repo.initialize();
        return repo;
    } catch (RepositoryException ex) {
        throw new ShineRuntimeException(ex);
    }
}
Also used : MemoryStore(org.openrdf.sail.memory.MemoryStore) Repository(org.openrdf.repository.Repository) SailRepository(org.openrdf.repository.sail.SailRepository) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) SailRepository(org.openrdf.repository.sail.SailRepository) RepositoryException(org.openrdf.repository.RepositoryException)

Example 10 with Repository

use of org.openrdf.repository.Repository in project gocd by gocd.

the class SesameGraph method createTempGraph.

public Graph createTempGraph() {
    try {
        if (!conn.isOpen()) {
            throw new IllegalStateException("Cannot create a temp graph on a closed graph!");
        }
        Repository inMemRepos = InMemoryRepositoryFactory.emptyRepository();
        String contextURI = null;
        if (contextResource.length > 0) {
            contextURI = contextResource[0].stringValue();
        }
        Graph tempGraph = new SesameGraph(inMemRepos.getConnection(), contextURI);
        tempGraphs.add(tempGraph);
        return tempGraph;
    } catch (RepositoryException ex) {
        throw new ShineRuntimeException("Unable to create temp graph!", ex);
    }
}
Also used : Repository(org.openrdf.repository.Repository) Graph(com.thoughtworks.studios.shine.semweb.Graph) ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException)

Aggregations

Repository (org.openrdf.repository.Repository)10 RepositoryException (org.openrdf.repository.RepositoryException)6 SailRepository (org.openrdf.repository.sail.SailRepository)6 IOException (java.io.IOException)4 FileNotFoundException (java.io.FileNotFoundException)3 RDFHandlerException (org.openrdf.rio.RDFHandlerException)3 SailException (org.openrdf.sail.SailException)3 MemoryStore (org.openrdf.sail.memory.MemoryStore)3 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)2 InputStreamReader (java.io.InputStreamReader)2 RepositoryConnection (org.openrdf.repository.RepositoryConnection)2 Sail (org.openrdf.sail.Sail)2 Graph (com.thoughtworks.studios.shine.semweb.Graph)1 BabelReader (edu.mit.simile.babel.BabelReader)1 ExhibitJsonReader (edu.mit.simile.babel.exhibit.ExhibitJsonReader)1 FileInputStream (java.io.FileInputStream)1 Properties (java.util.Properties)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.Test)1 URI (org.openrdf.model.URI)1