本文整理汇总了Java中org.apache.jena.update.UpdateRequest类的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequest类的具体用法?Java UpdateRequest怎么用?Java UpdateRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UpdateRequest类属于org.apache.jena.update包,在下文中一共展示了UpdateRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runSparqlUpdate
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
/**
* @param sparql
* @return
*/
public boolean runSparqlUpdate(String sparql) {
if (logger.isDebugEnabled())
logger.debug("run SPARQL update: {}", sparql);
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
setCloudAuthHeaderIfConfigured(clientBuilder);
if (proxyHost != null && proxyPort != null) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
clientBuilder.setProxy(proxy);
}
try (CloseableHttpClient client = clientBuilder.build()) {
UpdateRequest update = UpdateFactory.create(sparql, Syntax.syntaxARQ);
UpdateProcessor processor = UpdateExecutionFactory.createRemoteForm(update, buildSPARQLUrl().toString(), client);
processor.execute();
} catch (IOException ioe) {
throw new RuntimeException("IOException.", ioe);
}
return true;
}
示例2: main2
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
public static void main2(String ...args) {
int PORT = 2020;
DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem();
RDFChanges changeLog = RDFPatchOps.textWriter(System.out);
DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog);
// Create a server with the changes-enables dataset.
// Plain server. No other registration necessary.
FusekiServer server =
FusekiServer.create()
.setPort(PORT)
.add("/ds", dsg)
.build();
server.start();
RDFConnection conn = RDFConnectionFactory.connect("http://localhost:"+PORT+"/ds");
UpdateRequest update = UpdateFactory.create("PREFIX : <http://example/> INSERT DATA { :s :p 123 }");
// Note - no prefix in changes. The SPARQL Update prefix is not a chnage to the dataset prefixes.
conn.update(update);
server.stop();
// // Server in the background so explicitly exit.
// System.exit(0);
}
示例3: testUpdateAction
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
@Test
public void testUpdateAction() {
DatasetGraph gs = getMarkLogicDatasetGraph();
UpdateRequest update = new UpdateRequest();
update.add("INSERT DATA { <s2> <p1> <o1> }");
update.add("DROP ALL")
.add("CREATE GRAPH <http://example/update1>")
.add("BASE <http://example.org/> INSERT DATA { GRAPH <http://example.org/update2> { <s1> <p1> <o1> } }")
.add("BASE <http://example.org/> INSERT DATA { GRAPH <http://example.org/update3> { <s1> <p1> <o1> } }");
UpdateAction.execute(update, gs);
QueryExecution askQuery = QueryExecutionFactory
.create("BASE <http://example.org/> ASK WHERE { GRAPH <update3> { <s1> <p1> <o1> }}",
DatasetFactory.wrap(gs));
assertTrue("update action must update database.", askQuery.execAsk());
}
示例4: call
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
@Override
public UpdateRun call() throws Exception {
UpdateRequest update = this.getUpdate();
logger.debug("Running update:\n" + update.toString());
// Create a remote update processor and configure it appropriately
UpdateProcessor processor = this.createUpdateProcessor(update);
this.customizeRequest(processor);
long startTime = System.nanoTime();
try {
// Execute the update
processor.execute();
} catch (HttpException e) {
// Make sure to categorize HTTP errors appropriately
logger.error("{}", FormatUtils.formatException(e));
return new UpdateRun(e.getMessage(), ErrorCategories.categorizeHttpError(e), System.nanoTime() - startTime);
}
if (this.isCancelled())
return null;
long endTime = System.nanoTime();
return new UpdateRun(endTime - startTime);
}
示例5: ex3
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
public static void ex3(Dataset dataset)
{
// Build up the request then execute it.
// This is the preferred way for complex sequences of operations.
UpdateRequest request = UpdateFactory.create() ;
request.add("DROP ALL")
.add("CREATE GRAPH <http://example/g2>") ;
// Different style.
// Equivalent to request.add("...")
UpdateFactory.parse(request, "LOAD <file:etc/update-data.ttl> INTO GRAPH <http://example/g2>") ;
// And perform the operations.
UpdateAction.execute(request, dataset) ;
System.out.println("# Debug format");
SSE.write(dataset) ;
System.out.println();
System.out.println("# N-Quads: S P O G") ;
RDFDataMgr.write(System.out, dataset, Lang.NQUADS) ;
}
示例6: validateUpdateRequest
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
private static Collection<IllegalArgumentException> validateUpdateRequest(final UpdateRequest request) {
return request.getOperations().stream()
.flatMap(x -> {
if (x instanceof UpdateModify) {
final UpdateModify y = (UpdateModify) x;
return concat(y.getInsertQuads().stream(), y.getDeleteQuads().stream());
} else if (x instanceof UpdateData) {
return ((UpdateData) x).getQuads().stream();
} else if (x instanceof UpdateDeleteWhere) {
return ((UpdateDeleteWhere) x).getQuads().stream();
} else {
return empty();
}
})
.flatMap(FedoraResourceImpl::validateQuad)
.filter(x -> x != null)
.collect(Collectors.toList());
}
示例7: deleteLabelForLanguagePostCheck
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
private void deleteLabelForLanguagePostCheck(Label label) {
String sparql = "DELETE { ?conceptSchemeURI rdfs:label ?labelValue } WHERE { ?conceptSchemeURI rdfs:label ?labelValue . FILTER(STRLANG(?label) = STR(?labelLanguage)) }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("conceptSchemeURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(label.getValue(), label.getLanguageCode()));
UpdateRequest updateRequest = UpdateFactory.create(parameterizedSparql.getCommandText());
UpdateAction.execute(updateRequest, model);
}
示例8: deleteLabelPostCheck
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
private void deleteLabelPostCheck(Label label) {
String sparql = "DELETE { ?conceptSchemeURI rdfs:label ?labelValue } WHERE { }";
ParameterizedSparqlString parameterizedSparql = new ParameterizedSparqlString(model);
parameterizedSparql.setCommandText(sparql);
parameterizedSparql.setParam("conceptSchemeURI", resource);
parameterizedSparql.setParam("labelLanguage", model.createLiteral(label.getValue(), label.getLanguageCode()));
UpdateRequest updateRequest = UpdateFactory.create(parameterizedSparql.getCommandText());
UpdateAction.execute(updateRequest, model);
}
示例9: runModifySparql
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
private void runModifySparql(String sparql, String[] idxVals) throws Exception {
String updateService = Utils.getSdaProperty("com.pineone.icbms.sda.knowledgebase.sparql.endpoint") + "/update";
String madeQl = makeSparql(sparql, idxVals);
UpdateRequest ur = UpdateFactory.create(madeQl);
UpdateProcessor up = UpdateExecutionFactory.createRemote(ur, updateService);
up.execute();
}
示例10: sendUpdateQuery
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
@Override
public boolean sendUpdateQuery(String query) {
if (query == null) {
LOGGER.error("Can not send an update query that is null. Returning false.");
return false;
}
UpdateRequest update = UpdateFactory.create(query);
UpdateProcessor up = UpdateExecutionFactory.create(update, dataset);
up.execute();
// DatasetGraph dg = up.getDatasetGraph();
// return
// ModelFactory.createModelForGraph(dg.getGraph(NodeFactory.createURI(graphUri)));
return true;
}
示例11: createUpdateRequest
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
public UpdateRequest createUpdateRequest(String parsableString) {
UpdateRequest result = string2Update.get(parsableString);
if(result == null) {
result = UpdateFactoryFilter.get().create(parsableString);
if(useCaches) {
string2Update.put(parsableString, result);
}
}
return result;
}
示例12: clearGraphs
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
@After
public void clearGraphs() {
MarkLogicDatasetGraph markLogicDatasetGraph = getMarkLogicDatasetGraph();
UpdateAction.execute(new UpdateRequest().add("DROP SILENT ALL"),
markLogicDatasetGraph);
}
示例13: testUpdateTransactions
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
@Test
public void testUpdateTransactions() {
MarkLogicDatasetGraph dsg = getMarkLogicDatasetGraph();
UpdateRequest update = new UpdateRequest();
update.add("BASE <http://example.org/> INSERT DATA { GRAPH <transact3> { <s4882> <p132> <o12321> } }");
// insert a graph within a transaction, rollback
assertFalse(dsg.isInTransaction());
dsg.begin(ReadWrite.WRITE);
assertTrue(dsg.isInTransaction());
UpdateAction.execute(update, dsg);
dsg.abort();
assertFalse(dsg.isInTransaction());
QueryExecution queryExec = QueryExecutionFactory
.create("ASK WHERE { graph <http://example.org/transact3> { ?s ?p ?o }}",
dsg.toDataset());
assertFalse("transact3 graph must not exist after rollback",
queryExec.execAsk());
dsg.begin(ReadWrite.WRITE);
assertTrue(dsg.isInTransaction());
UpdateAction.execute(update, dsg);
dsg.commit();
assertFalse(dsg.isInTransaction());
queryExec = QueryExecutionFactory
.create("BASE <http://example.org/> ASK WHERE { GRAPH <transact3> { ?s ?p ?o }}",
dsg.toDataset());
assertTrue("transact3 graph must exist after commit",
queryExec.execAsk());
}
示例14: dropTransactGraph
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
@After
public void dropTransactGraph() {
MarkLogicDatasetGraph dsg = getMarkLogicDatasetGraph();
UpdateRequest update = new UpdateRequest();
update.add("BASE <http://example.org/> DROP SILENT GRAPH <transact3>")
.add("DROP SILENT GRAPH <http://example.org/update2>")
.add("DROP SILENT GRAPH <http://example.org/update3>")
.add("DROP SILENT GRAPH <http://example.org/gp2>");
UpdateAction.execute(update, dsg);
}
示例15: run
import org.apache.jena.update.UpdateRequest; //导入依赖的package包/类
private void run() {
dsg.clear();
String insertData = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "
+ "PREFIX : <http://example.org/> "
+"INSERT DATA {GRAPH :g1 {"
+ ":charles a foaf:Person ; "
+ " foaf:name \"Charles\" ;"
+ " foaf:knows :jim ."
+ ":jim a foaf:Person ;"
+ " foaf:name \"Jim\" ;"
+ " foaf:knows :charles ."
+ "} }";
System.out.println("Running SPARQL update");
UpdateRequest update = UpdateFactory.create(insertData);
UpdateProcessor processor = UpdateExecutionFactory.create(update, dsg);
processor.execute();
System.out.println("Examine the data as JSON-LD");
RDFDataMgr.write(System.out, dsg.getGraph(NodeFactory.createURI("http://example.org/g1")), RDFFormat.JSONLD_PRETTY);
System.out.println("Remove it.");
update = UpdateFactory.create("PREFIX : <http://example.org/> DROP GRAPH :g1");
processor = UpdateExecutionFactory.create(update, dsg);
processor.execute();
dsg.close();
}