Search in sources :

Example 16 with RepositoryException

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

the class SesameYard method remove.

@Override
public void remove(String id) throws YardException, IllegalArgumentException {
    if (id == null) {
        throw new IllegalArgumentException("The parsed Representation id MUST NOT be NULL!");
    }
    RepositoryConnection con = null;
    try {
        con = repository.getConnection();
        con.begin();
        remove(con, sesameFactory.createURI(id));
        con.commit();
    } catch (RepositoryException e) {
        throw new YardException("Unable to remove for Representation " + id, e);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException ignore) {
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) RepositoryException(org.openrdf.repository.RepositoryException)

Example 17 with RepositoryException

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

the class SesameYard method removeAll.

@Override
public final void removeAll() throws YardException {
    RepositoryConnection con = null;
    try {
        con = repository.getConnection();
        con.begin();
        //removes everything
        con.clear(contexts);
        con.commit();
    } catch (RepositoryException e) {
        throw new YardException("Unable to remove parsed Representations", e);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException ignore) {
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) RepositoryException(org.openrdf.repository.RepositoryException)

Example 18 with RepositoryException

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

the class SesameYard method store.

/**
     * Generic store method used by store and update methods
     * @param representation the representation to store/update
     * @param allowCreate if new representation are allowed to be created
     * @param canNotCreateIsError if updates to existing one are allowed
     * @return the representation as added to the yard
     * @throws IllegalArgumentException
     * @throws YardException
     */
protected final Representation store(Representation representation, boolean allowCreate, boolean canNotCreateIsError) throws IllegalArgumentException, YardException {
    RepositoryConnection con = null;
    try {
        con = repository.getConnection();
        con.begin();
        Representation added = store(con, representation, allowCreate, canNotCreateIsError);
        con.commit();
        return added;
    } catch (RepositoryException e) {
        throw new YardException("Unable to remove parsed Representations", e);
    } catch (IllegalArgumentException e) {
        try {
            //to avoid Exception logs in case store(..) throws an Exception
            //in the case allowCreate and canNotCreateIsError do not allow
            //the store operation
            con.rollback();
        } catch (RepositoryException ignore) {
        }
        throw e;
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (RepositoryException ignore) {
            }
        }
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) RdfRepresentation(org.apache.stanbol.entityhub.model.sesame.RdfRepresentation) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) RepositoryException(org.openrdf.repository.RepositoryException)

Example 19 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, Resource tripleObject) {
    AbstractSesameResource sesameSubject = (AbstractSesameResource) tripleSubject;
    URI sesameNativePredicate = getSesameNativeProperty(triplePredicate);
    AbstractSesameResource sesameObject = (AbstractSesameResource) tripleObject;
    try {
        conn.remove(sesameSubject.getSesameNativeResource(), sesameNativePredicate, sesameObject.getSesameNativeResource(), 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 20 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, String tripleObject) {
    AbstractSesameResource sesameSubject = (AbstractSesameResource) tripleSubject;
    URI sesameNativePredicate = getSesameNativeProperty(triplePredicate);
    try {
        conn.remove(sesameSubject.getSesameNativeResource(), sesameNativePredicate, conn.getValueFactory().createLiteral(tripleObject, XMLSchema.STRING), 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)

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