Search in sources :

Example 1 with Update

use of org.eclipse.rdf4j.query.Update in project rdf4j by eclipse.

the class InterceptorTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final Update updateStub = new UpdateStub() {

        public void execute() throws UpdateExecutionException {
            fail();
        }
    };
    final RepositoryConnection stub = new RepositoryConnectionStub() {

        public Update prepareUpdate(QueryLanguage ql, String query, String baseURI) throws MalformedQueryException, RepositoryException {
            return updateStub;
        }
    };
    Repository repo = stub.getRepository();
    InterceptingRepositoryConnection con = new InterceptingRepositoryConnectionWrapper(repo, stub);
    con.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() {

        public boolean execute(RepositoryConnection conn, QueryLanguage ql, String update, String baseURI, Update operation) {
            assertEquals(stub, conn);
            assertEquals(SPARQL, ql);
            assertEquals("DELETE DATA { <> <> <> }", update);
            assertEquals("http://example.com/", baseURI);
            assertEquals(updateStub, operation);
            return true;
        }
    });
    Update update = con.prepareUpdate(SPARQL, "DELETE DATA { <> <> <> }", "http://example.com/");
    update.execute();
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) QueryLanguage(org.eclipse.rdf4j.query.QueryLanguage) RepositoryConnectionInterceptorAdapter(org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter) AbstractUpdate(org.eclipse.rdf4j.query.impl.AbstractUpdate) Update(org.eclipse.rdf4j.query.Update) InterceptingRepositoryConnectionWrapper(org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper) Test(org.junit.Test)

Example 2 with Update

use of org.eclipse.rdf4j.query.Update in project rdf4j by eclipse.

the class SPARQLUpdateOperation method execute.

public void execute(RepositoryConnection con) throws RepositoryException {
    try {
        Update preparedUpdate = con.prepareUpdate(QueryLanguage.SPARQL, getUpdateString(), getBaseURI());
        preparedUpdate.setIncludeInferred(isIncludeInferred());
        preparedUpdate.setDataset(getDataset());
        if (getBindings() != null) {
            for (Binding binding : getBindings()) {
                preparedUpdate.setBinding(binding.getName(), binding.getValue());
            }
        }
        preparedUpdate.execute();
    } catch (MalformedQueryException e) {
        throw new RepositoryException(e);
    } catch (UpdateExecutionException e) {
        throw new RepositoryException(e);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) UpdateExecutionException(org.eclipse.rdf4j.query.UpdateExecutionException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) Update(org.eclipse.rdf4j.query.Update)

Example 3 with Update

use of org.eclipse.rdf4j.query.Update in project rdf4j by eclipse.

the class NotifyingTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final Update updateStub = new UpdateStub();
    final RepositoryConnection stub = new RepositoryConnectionStub() {

        public Update prepareUpdate(QueryLanguage ql, String query, String baseURI) throws MalformedQueryException, RepositoryException {
            return updateStub;
        }
    };
    Repository repo = stub.getRepository();
    NotifyingRepositoryConnection con = new NotifyingRepositoryConnectionWrapper(repo, stub);
    con.addRepositoryConnectionListener(new RepositoryConnectionListenerAdapter() {

        public void execute(RepositoryConnection conn, QueryLanguage ql, String update, String baseURI, Update operation) {
            assertEquals(stub, conn);
            assertEquals(SPARQL, ql);
            assertEquals("DELETE DATA { <> <> <> }", update);
            assertEquals("http://example.com/", baseURI);
            assertEquals(updateStub, operation);
        }
    });
    Update update = con.prepareUpdate(SPARQL, "DELETE DATA { <> <> <> }", "http://example.com/");
    update.execute();
}
Also used : RepositoryConnection(org.eclipse.rdf4j.repository.RepositoryConnection) Repository(org.eclipse.rdf4j.repository.Repository) NotifyingRepositoryConnectionWrapper(org.eclipse.rdf4j.repository.event.base.NotifyingRepositoryConnectionWrapper) QueryLanguage(org.eclipse.rdf4j.query.QueryLanguage) AbstractUpdate(org.eclipse.rdf4j.query.impl.AbstractUpdate) Update(org.eclipse.rdf4j.query.Update) RepositoryConnectionListenerAdapter(org.eclipse.rdf4j.repository.event.base.RepositoryConnectionListenerAdapter) Test(org.junit.Test)

Aggregations

Update (org.eclipse.rdf4j.query.Update)3 QueryLanguage (org.eclipse.rdf4j.query.QueryLanguage)2 AbstractUpdate (org.eclipse.rdf4j.query.impl.AbstractUpdate)2 Repository (org.eclipse.rdf4j.repository.Repository)2 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)2 Test (org.junit.Test)2 Binding (org.eclipse.rdf4j.query.Binding)1 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1 UpdateExecutionException (org.eclipse.rdf4j.query.UpdateExecutionException)1 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)1 InterceptingRepositoryConnectionWrapper (org.eclipse.rdf4j.repository.event.base.InterceptingRepositoryConnectionWrapper)1 NotifyingRepositoryConnectionWrapper (org.eclipse.rdf4j.repository.event.base.NotifyingRepositoryConnectionWrapper)1 RepositoryConnectionInterceptorAdapter (org.eclipse.rdf4j.repository.event.base.RepositoryConnectionInterceptorAdapter)1 RepositoryConnectionListenerAdapter (org.eclipse.rdf4j.repository.event.base.RepositoryConnectionListenerAdapter)1