Search in sources :

Example 6 with UpdateProcessor

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

the class ExTDB_Txn2 method execUpdate.

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

Example 7 with UpdateProcessor

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

the class JenaStatement method executeUpdate.

private int executeUpdate(UpdateRequest u) 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");
    // Do we need transactions?
    boolean needsBegin = (!this.autoCommit && this.transactionLevel != Connection.TRANSACTION_NONE && !this.hasActiveTransaction());
    boolean needsCommit = (this.autoCommit && this.transactionLevel != Connection.TRANSACTION_NONE);
    try {
        // Start a Transaction if necessary
        if (needsCommit || needsBegin) {
            if (this.autoCommit) {
                LOGGER.info("Running update in auto-commit mode");
            } else {
                LOGGER.info("Starting a new transaction to run update, transaction will not be auto-committed");
            }
            this.beginTransaction(ReadWrite.WRITE);
        }
    } catch (Exception e) {
        LOGGER.error("Starting the new transaction failed", e);
        throw new SQLException("Failed to start a new query transaction", e);
    }
    try {
        // Pre-process the update
        u = this.connection.applyPreProcessors(u);
        // Execute updates
        UpdateProcessor processor = this.createUpdateProcessor(u);
        processor.execute();
        // If auto-committing can commit immediately
        if (needsCommit) {
            LOGGER.info("Auto-committing update transaction");
            this.commitTransaction();
        }
        return 0;
    } catch (SQLException e) {
        if (needsCommit) {
            LOGGER.warn("Rolling back failed update transaction", e);
            this.rollbackTransaction();
        }
        throw e;
    } catch (Exception e) {
        LOGGER.error("SPARQL Update evaluation failed", e);
        if (needsCommit) {
            LOGGER.warn("Rolling back failed update transaction");
            this.rollbackTransaction();
        }
        throw new SQLException("Error occurred during SPARQL update evaluation", e);
    }
}
Also used : SQLException(java.sql.SQLException) UpdateProcessor(org.apache.jena.update.UpdateProcessor) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 8 with UpdateProcessor

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

the class rupdate method exec.

private void exec(String endpoint, UpdateRequest req) {
    UpdateProcessor proc = UpdateExecutionFactory.createRemote(req, endpoint);
    proc.execute();
}
Also used : UpdateProcessor(org.apache.jena.update.UpdateProcessor)

Example 9 with UpdateProcessor

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

the class TestRemoteEndpointResultsWithAuth method cleanupTest.

/**
     * Clean up after each test by resetting the Fuseki instance
     */
@After
public void cleanupTest() {
    Update clearRequest = new UpdateDrop(Target.ALL);
    UpdateProcessor proc = UpdateExecutionFactory.createRemote(clearRequest, FusekiTestAuth.serviceUpdate(), client);
    proc.execute();
}
Also used : UpdateProcessor(org.apache.jena.update.UpdateProcessor) Update(org.apache.jena.update.Update) UpdateDrop(org.apache.jena.sparql.modify.request.UpdateDrop) After(org.junit.After)

Example 10 with UpdateProcessor

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

the class RDFConnectionRemote method update.

@Override
public void update(UpdateRequest update) {
    checkUpdate();
    UpdateProcessor proc = UpdateExecutionFactory.createRemote(update, svcUpdate, this.httpClient, this.httpContext);
    exec(() -> proc.execute());
}
Also used : UpdateProcessor(org.apache.jena.update.UpdateProcessor)

Aggregations

UpdateProcessor (org.apache.jena.update.UpdateProcessor)16 UpdateRequest (org.apache.jena.update.UpdateRequest)7 Test (org.junit.Test)7 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 UpdateDrop (org.apache.jena.sparql.modify.request.UpdateDrop)3 Update (org.apache.jena.update.Update)3 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 After (org.junit.After)1 Before (org.junit.Before)1