Search in sources :

Example 1 with UpdateExecution

use of org.apache.jena.update.UpdateExecution in project jena by apache.

the class AbstractTestDatasetWithTextIndexBase method doUpdate.

protected void doUpdate(String updateString) {
    dataset.begin(ReadWrite.WRITE);
    UpdateRequest request = UpdateFactory.create(updateString);
    UpdateExecution proc = UpdateExecutionFactory.create(request, dataset);
    proc.execute();
    dataset.commit();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution)

Example 2 with UpdateExecution

use of org.apache.jena.update.UpdateExecution in project jena by apache.

the class TestParameterizedSparqlString method test_param_string_bnode_3.

@Test
public void test_param_string_bnode_3() {
    // Test case related to treatment of blank nodes when injecting into
    // SPARQL updates using _: syntax
    Model model = ModelFactory.createDefaultModel();
    Resource bnode = model.createResource();
    bnode.addProperty(RDF.type, OWL.Thing);
    Assert.assertEquals(1, model.size());
    Dataset ds = DatasetFactory.wrap(model);
    // Use a parameterized query to check the data can be found
    ParameterizedSparqlString pq = new ParameterizedSparqlString();
    pq.setCommandText("SELECT * WHERE { ?s ?p ?o }");
    pq.setIri("s", "_:" + bnode.getId());
    Query q = pq.asQuery();
    try (QueryExecution qe = QueryExecutionFactory.create(q, ds)) {
        ResultSet rset = qe.execSelect();
        Assert.assertEquals(1, ResultSetFormatter.consume(rset));
    }
    // Use a parameterized update to modify the data
    ParameterizedSparqlString s = new ParameterizedSparqlString();
    s.setCommandText("INSERT { ?o ?p ?s } WHERE { ?s ?p ?o }");
    s.setIri("s", "_:" + bnode.getId());
    UpdateRequest query = s.asUpdate();
    UpdateExecution proc = UpdateExecutionFactory.create(query, ds);
    proc.execute();
    // This should be true because this was present in the intial model set
    // up
    Assert.assertEquals(1, model.listStatements(bnode, null, (RDFNode) null).toList().size());
    // This should return 0 because the INSERT should result in a new blank
    // node being created rather than the existing one being reused becaue
    // of the semantics of blank nodes usage in templates
    Assert.assertEquals(0, model.listStatements(null, null, bnode).toList().size());
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution) Test(org.junit.Test)

Example 3 with UpdateExecution

use of org.apache.jena.update.UpdateExecution in project jena by apache.

the class TestAuthUpdate_JDK method update_authenv_01_good.

@Test
public void update_authenv_01_good() {
    // Auth credentials for valid user with correct password
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateExecution ue = UpdateExecutionHTTP.create().endpoint(databaseURL()).update(updates).build();
    String dsURL = databaseURL();
    URI uri = URI.create(dsURL);
    AuthEnv.get().registerUsernamePassword(uri, "allowed", "password");
    try {
        ue.execute();
    } finally {
        AuthEnv.get().unregisterUsernamePassword(uri);
    }
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution) URI(java.net.URI) Test(org.junit.Test)

Example 4 with UpdateExecution

use of org.apache.jena.update.UpdateExecution in project jena by apache.

the class TestAuthUpdate_JDK method update_with_auth_04.

@Test
public void update_with_auth_04() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateExecution ue = withAuthJDK(UpdateExecutionHTTP.create().endpoint(databaseURL()).update(updates), "allowed", "password");
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution) Test(org.junit.Test)

Example 5 with UpdateExecution

use of org.apache.jena.update.UpdateExecution in project jena by apache.

the class ExTDB_Txn2 method execUpdate.

public static void execUpdate(String sparqlUpdateString, Dataset dataset) {
    UpdateRequest request = UpdateFactory.create(sparqlUpdateString);
    UpdateExecution proc = UpdateExecutionFactory.create(request, dataset);
    proc.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateExecution(org.apache.jena.update.UpdateExecution)

Aggregations

UpdateExecution (org.apache.jena.update.UpdateExecution)10 UpdateRequest (org.apache.jena.update.UpdateRequest)9 Test (org.junit.Test)7 URI (java.net.URI)1 HttpException (org.apache.jena.atlas.web.HttpException)1 UpdateExecutionBuilder (org.apache.jena.update.UpdateExecutionBuilder)1