Search in sources :

Example 41 with UpdateRequest

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

the class UpdateTransformOps method transform.

public static UpdateRequest transform(UpdateRequest update, ElementTransform transform, ExprTransform exprTransform) {
    UpdateRequest req = new UpdateRequest();
    req.getPrefixMapping().setNsPrefixes(update.getPrefixMapping());
    for (Update up : update.getOperations()) {
        up = transform(up, transform, exprTransform);
        req.add(up);
    }
    return req;
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) Update(org.apache.jena.update.Update)

Example 42 with UpdateRequest

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

the class uparse method execOne.

private void execOne(String updateString, Syntax syntax) {
    UpdateRequest req;
    try {
        req = UpdateFactory.create(updateString, syntax);
    } catch (QueryParseException ex) {
        System.err.print("Parse error: ");
        System.err.println(ex.getMessage());
        return;
    }
    //req.output(IndentedWriter.stderr) ;
    if (printUpdate)
        System.out.print(req);
    if (printNone)
        return;
    // And some checking.
    IndentedLineBuffer w = new IndentedLineBuffer();
    UpdateWriter.output(req, w);
    String updateString2 = w.asString();
    UpdateRequest req2 = null;
    try {
        req2 = UpdateFactory.create(updateString2, syntax);
    } catch (QueryParseException ex) {
        System.err.println("Can not reparse update after serialization");
        System.err.println(updateString2);
    }
    if (!req.equalTo(req2))
        System.err.println("Reparsed update does not .equalTo original parsed request");
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) QueryParseException(org.apache.jena.query.QueryParseException) IndentedLineBuffer(org.apache.jena.atlas.io.IndentedLineBuffer)

Example 43 with UpdateRequest

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

the class sdbupdate method execOneFile.

private void execOneFile(String filename, Dataset store) {
    UpdateRequest req = UpdateFactory.read(filename, Syntax.syntaxARQ);
    UpdateExecutionFactory.create(req, store).execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest)

Example 44 with UpdateRequest

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

the class TestSyntaxTransform method testUpdateModel.

private void testUpdateModel(String input, String output, String varStr, String valStr) {
    UpdateRequest req1 = UpdateFactory.create(PREFIX + input);
    UpdateRequest reqExpected = UpdateFactory.create(PREFIX + output);
    Map<String, RDFNode> map = new HashMap<>();
    Node n = SSE.parseNode(valStr);
    RDFNode x = ModelUtils.convertGraphNodeToRDFNode(n);
    map.put(varStr, x);
    UpdateRequest reqTrans = UpdateTransformOps.transformUpdate(req1, map);
    // Crude.
    String x1 = reqExpected.toString().replaceAll("[ \n\t]", "");
    String x2 = reqTrans.toString().replaceAll("[ \n\t]", "");
    //assertEquals(reqExpected, reqTrans) ;
    assertEquals(x1, x2);
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) HashMap(java.util.HashMap) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 45 with UpdateRequest

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

the class JenaStatement method executeUpdate.

@Override
public final int executeUpdate(String sql) throws SQLException {
    if (this.isClosed())
        throw new SQLException("The Statement is closed");
    if (this.connection.isReadOnly())
        throw new SQLException("The JDBC connection is currently in read-only mode, updates are not permitted");
    // Pre-process the command text
    LOGGER.info("Received input command text:\n {}", sql);
    sql = this.connection.applyPreProcessors(sql);
    LOGGER.info("Command text after pre-processing:\n {}", sql);
    UpdateRequest u = null;
    try {
        u = UpdateFactory.create(sql);
    } catch (Exception e) {
        LOGGER.error("Invalid SPARQL update", e);
        throw new SQLException("Not a valid SPARQL Update", e);
    }
    if (u == null)
        throw new SQLException("Unable to create a SPARQL Update Request");
    return this.executeUpdate(u);
}
Also used : SQLException(java.sql.SQLException) UpdateRequest(org.apache.jena.update.UpdateRequest) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Aggregations

UpdateRequest (org.apache.jena.update.UpdateRequest)71 Test (org.junit.Test)46 UpdateProcessRemoteBase (org.apache.jena.sparql.modify.UpdateProcessRemoteBase)13 UpdateProcessor (org.apache.jena.update.UpdateProcessor)7 Node (org.apache.jena.graph.Node)6 RDFNode (org.apache.jena.rdf.model.RDFNode)5 HashMap (java.util.HashMap)4 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)4 Resource (org.apache.jena.rdf.model.Resource)4 AuthScope (org.apache.http.auth.AuthScope)3 Dataset (org.apache.jena.query.Dataset)3 QueryParseException (org.apache.jena.query.QueryParseException)3 Model (org.apache.jena.rdf.model.Model)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 Map (java.util.Map)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 CmdException (jena.cmd.CmdException)2 HttpClient (org.apache.http.client.HttpClient)2