Search in sources :

Example 96 with UpdateRequest

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

the class RDFLinkHTTP method updateExec.

private void updateExec(UpdateRequest update, String updateString) {
    checkUpdate();
    if (update == null && updateString == null)
        throw new InternalErrorException("Both update request and update string are null");
    UpdateRequest actual = null;
    if (update == null) {
        if (parseCheckUpdates)
            actual = UpdateFactory.create(updateString);
    }
    // Use the update string as provided if possible, otherwise serialize the update.
    String updateStringToSend = (updateString != null) ? updateString : update.toString();
    createUExecBuilder().updateString(updateStringToSend).build().execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException)

Example 97 with UpdateRequest

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

the class Test_SPARQL_TDB method update.

private void update(Dataset dataset, String string) {
    UpdateRequest req = UpdateFactory.create(string);
    UpdateExec.newBuilder().update(req).dataset(dataset.asDatasetGraph()).execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest)

Example 98 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)

Example 99 with UpdateRequest

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

the class load method execUpdate.

@Override
protected void execUpdate(DatasetGraph dataset) {
    if (loadFiles.size() == 0)
        throw new CmdException("Nothing to do");
    UpdateRequest req = new UpdateRequest();
    for (String filename : loadFiles) {
        UpdateLoad loadReq = new UpdateLoad(filename, graphName);
        req.add(loadReq);
    }
    if (true) {
        // Need a better way
        monitor(dataset.getDefaultGraph());
        for (Iterator<Node> iter = dataset.listGraphNodes(); iter.hasNext(); ) {
            Graph g = dataset.getGraph(iter.next());
            monitor(g);
        }
    }
    UpdateExec.newBuilder().update(req).dataset(dataset).execute();
    if (dump) {
        IndentedWriter out = IndentedWriter.stdout;
        SSE.write(dataset);
        out.flush();
    }
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) CmdException(org.apache.jena.cmd.CmdException) UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateLoad(org.apache.jena.sparql.modify.request.UpdateLoad) Node(org.apache.jena.graph.Node)

Example 100 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;
    try {
        LogCtl.disable(QueryParserBase.ParserLoggerName);
        checkUpdate(req, syntax);
    } catch (UpdateCheckException ex) {
        System.err.println();
        System.err.println("**** Check failure: " + ex.getMessage());
        if (ex.getCause() != null)
            ex.getCause().printStackTrace(System.err);
    } finally {
        LogCtl.setLevel(QueryParserBase.ParserLoggerName, "INFO");
    }
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) QueryParseException(org.apache.jena.query.QueryParseException)

Aggregations

UpdateRequest (org.apache.jena.update.UpdateRequest)130 Test (org.junit.Test)85 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)20 UpdateProcessor (org.apache.jena.update.UpdateProcessor)14 UpdateProcessRemoteBase (org.apache.jena.sparql.modify.UpdateProcessRemoteBase)13 Model (org.apache.jena.rdf.model.Model)10 Dataset (org.apache.jena.query.Dataset)9 UpdateExecution (org.apache.jena.update.UpdateExecution)9 Node (org.apache.jena.graph.Node)7 RDFNode (org.apache.jena.rdf.model.RDFNode)6 Resource (org.apache.jena.rdf.model.Resource)6 HttpTest (org.apache.jena.fuseki.test.HttpTest)5 URI (java.net.URI)4 HashMap (java.util.HashMap)4 Syntax (org.apache.jena.query.Syntax)4 Context (org.apache.jena.sparql.util.Context)4 AuthScope (org.apache.http.auth.AuthScope)3 Literal (org.apache.jena.rdf.model.Literal)3 Update (org.apache.jena.update.Update)3 StringWriter (java.io.StringWriter)2