Search in sources :

Example 36 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method getContextIDs.

public RepositoryResult<Resource> getContextIDs() throws RepositoryException {
    try {
        List<Resource> contextList = new ArrayList<Resource>();
        TupleQueryResult contextIDs = client.getContextIDs();
        try {
            while (contextIDs.hasNext()) {
                BindingSet bindingSet = contextIDs.next();
                Value context = bindingSet.getValue("contextID");
                if (context instanceof Resource) {
                    contextList.add((Resource) context);
                }
            }
        } finally {
            contextIDs.close();
        }
        return createRepositoryResult(contextList);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Resource(org.eclipse.rdf4j.model.Resource) ArrayList(java.util.ArrayList) Value(org.eclipse.rdf4j.model.Value) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Example 37 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method removeModel.

private void removeModel(Model m) throws RepositoryException {
    RDFFormat format = RDFFormat.BINARY;
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Rio.write(m, out, format);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        client.removeData(in, null, format);
    } catch (RDFHandlerException e) {
        throw new RepositoryException("error while writing statement", e);
    } catch (RDFParseException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 38 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class SystemRepository method initialize.

@Override
public void initialize() throws RepositoryException {
    super.initialize();
    RepositoryConnection con = getConnection();
    try {
        if (con.isEmpty()) {
            logger.debug("Initializing empty {} repository", ID);
            con.begin();
            con.setNamespace("rdf", RDF.NAMESPACE);
            con.setNamespace("sys", RepositoryConfigSchema.NAMESPACE);
            con.commit();
            RepositoryConfig repConfig = new RepositoryConfig(ID, TITLE, new SystemRepositoryConfig());
            RepositoryConfigUtil.updateRepositoryConfigs(con, repConfig);
        }
    } catch (RepositoryConfigException e) {
        throw new RepositoryException(e.getMessage(), e);
    } finally {
        con.close();
    }
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) RepositoryConfigException(org.eclipse.rdf4j.repository.config.RepositoryConfigException)

Example 39 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.

the class LocalRepositoryManager method getRepositoryInfo.

@Override
public RepositoryInfo getRepositoryInfo(String id) {
    RepositoryConfig config = getRepositoryConfig(id);
    if (config == null) {
        return null;
    }
    RepositoryInfo repInfo = new RepositoryInfo();
    repInfo.setId(config.getID());
    repInfo.setDescription(config.getTitle());
    try {
        repInfo.setLocation(getRepositoryDir(config.getID()).toURI().toURL());
    } catch (MalformedURLException mue) {
        throw new RepositoryException("Location of repository does not resolve to a valid URL", mue);
    }
    repInfo.setReadable(true);
    repInfo.setWritable(true);
    return repInfo;
}
Also used : RepositoryConfig(org.eclipse.rdf4j.repository.config.RepositoryConfig) MalformedURLException(java.net.MalformedURLException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 40 with RepositoryException

use of org.eclipse.rdf4j.repository.RepositoryException in project graal by graphik-team.

the class RDF4jStore method termsByPredicatePosition.

@Override
public CloseableIterator<Term> termsByPredicatePosition(Predicate p, int position) throws AtomSetException {
    TupleQuery query = null;
    TupleQueryResult results = null;
    try {
        if (position == 0) {
            query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?x <" + utils.createURI(p) + "> ?y }");
        } else if (position == 1) {
            query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?y <" + utils.createURI(p) + "> ?x }");
        } else {
            throw new WrongArityException("Position should be 0 for subject or 1 for object.");
        }
        results = query.evaluate();
    } catch (RepositoryException e) {
        throw new AtomSetException(e);
    } catch (MalformedQueryException e) {
        throw new AtomSetException(e);
    } catch (QueryEvaluationException e) {
        throw new AtomSetException(e);
    }
    return new TermsIterator(results, "x", this.utils);
}
Also used : QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) WrongArityException(fr.lirmm.graphik.graal.api.store.WrongArityException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Aggregations

RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)67 IOException (java.io.IOException)24 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)20 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)15 RDF4JException (org.eclipse.rdf4j.RDF4JException)13 HttpResponse (org.apache.http.HttpResponse)11 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)10 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)8 HttpGet (org.apache.http.client.methods.HttpGet)7 Resource (org.eclipse.rdf4j.model.Resource)7 Statement (org.eclipse.rdf4j.model.Statement)6 ArrayList (java.util.ArrayList)5 HttpPut (org.apache.http.client.methods.HttpPut)5 RDF4JProtocolSession (org.eclipse.rdf4j.http.client.RDF4JProtocolSession)5 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)5 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)5 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4