Search in sources :

Example 31 with RepositoryException

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

the class SesameGraph method remove.

public void remove(Resource tripleSubject, RDFProperty triplePredicate, Integer integer) {
    AbstractSesameResource sesameSubject = (AbstractSesameResource) tripleSubject;
    URI sesameNativePredicate = getSesameNativeProperty(triplePredicate);
    try {
        conn.remove(sesameSubject.getSesameNativeResource(), sesameNativePredicate, conn.getValueFactory().createLiteral(String.valueOf(integer), XMLSchema.INTEGER), contextResource);
    } catch (RepositoryException e) {
        throw new ShineRuntimeException(e);
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) URI(org.openrdf.model.URI)

Example 32 with RepositoryException

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

the class SesameGraph method addStatement.

public void addStatement(Resource subject, RDFProperty predicate, String object) {
    AbstractSesameResource sesameSubject = (AbstractSesameResource) subject;
    URI sesameNativePredicate = getSesameNativeProperty(predicate);
    try {
        conn.add(sesameSubject.getSesameNativeResource(), sesameNativePredicate, conn.getValueFactory().createLiteral(String.valueOf(object), XMLSchema.STRING), contextResource);
    } catch (RepositoryException e) {
        throw new ShineRuntimeException("Could not add statement << [" + subject + "] [" + predicate + "] [" + object + "] >>", e);
    }
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) URI(org.openrdf.model.URI)

Example 33 with RepositoryException

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

the class SesameGraphTest method checkWhenAddStatementWithResourceObjectExplodesItThrowsAShineRuntimeException.

@Test(expected = ShineRuntimeException.class)
public void checkWhenAddStatementWithResourceObjectExplodesItThrowsAShineRuntimeException() throws RepositoryException {
    RDFProperty property = new RDFProperty("http://www.example.com/ontology#foo");
    RepositoryConnection badConnection = mock(RepositoryConnection.class);
    doThrow(new RepositoryException("")).when(badConnection).add((org.openrdf.model.Resource) any(), (org.openrdf.model.URI) any(), (org.openrdf.model.Value) any());
    org.openrdf.model.ValueFactory stubValueFactory = mock(org.openrdf.model.ValueFactory.class);
    when(badConnection.getValueFactory()).thenReturn(stubValueFactory);
    SesameURIReference stubSubject = mock(SesameURIReference.class);
    when(stubSubject.getSesameNativeResource()).thenReturn(null);
    URIReference stubPredicate = mock(URIReference.class);
    when(stubPredicate.getURIText()).thenReturn("");
    SesameGraph badGraph = new SesameGraph(badConnection, null);
    badGraph.addStatement(stubSubject, property, (Integer) null);
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RepositoryException(org.openrdf.repository.RepositoryException) Test(org.junit.Test)

Example 34 with RepositoryException

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

the class SesameGraphTest method checkWhenAddNamespaceExplodesItThrowsAShineRuntimeException.

@Test(expected = ShineRuntimeException.class)
public void checkWhenAddNamespaceExplodesItThrowsAShineRuntimeException() throws Exception {
    RepositoryConnection badConnection = mock(RepositoryConnection.class);
    doThrow(new RepositoryException("")).when(badConnection).setNamespace("foo", "http://example.org/");
    SesameGraph badGraph = new SesameGraph(badConnection, null);
    badGraph.addNamespace(new Namespace("foo", "http://example.org/"));
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RepositoryException(org.openrdf.repository.RepositoryException) Test(org.junit.Test)

Example 35 with RepositoryException

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

the class SesameGraphTest method checkGetNamespaceByPrefixExplodesItThrowsAShineRuntimeException.

@Test(expected = ShineRuntimeException.class)
public void checkGetNamespaceByPrefixExplodesItThrowsAShineRuntimeException() throws RepositoryException {
    RepositoryConnection badConnection = mock(RepositoryConnection.class);
    when(badConnection.getNamespace("ex")).thenThrow(new RepositoryException(""));
    SesameGraph badGraph = new SesameGraph(badConnection, null);
    badGraph.getNamespaceByPrefix("ex");
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RepositoryException(org.openrdf.repository.RepositoryException) Test(org.junit.Test)

Aggregations

RepositoryException (org.openrdf.repository.RepositoryException)36 RepositoryConnection (org.openrdf.repository.RepositoryConnection)20 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)12 URI (org.openrdf.model.URI)12 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)10 Test (org.junit.Test)7 RdfRepresentation (org.apache.stanbol.entityhub.model.sesame.RdfRepresentation)5 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)5 IOException (java.io.IOException)4 Value (org.openrdf.model.Value)4 Repository (org.openrdf.repository.Repository)4 InputStreamReader (java.io.InputStreamReader)3 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)3 BindingSet (org.openrdf.query.BindingSet)3 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)3 TupleQueryResult (org.openrdf.query.TupleQueryResult)3 SailRepository (org.openrdf.repository.sail.SailRepository)3 Graph (com.thoughtworks.studios.shine.semweb.Graph)2 RdfValueFactory (org.apache.stanbol.entityhub.model.sesame.RdfValueFactory)2 Model (org.openrdf.model.Model)2