Skip to content

Commit 7f59fa7

Browse files
committed
GH2701: Fuseki Mod to list and abort running executions.
1 parent 56aca05 commit 7f59fa7

File tree

79 files changed

+5845
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+5845
-180
lines changed

jena-arq/src/main/java/org/apache/jena/http/sys/ExecHTTPBuilder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.jena.query.*;
2828
import org.apache.jena.sparql.core.Var;
2929
import org.apache.jena.sparql.engine.binding.Binding;
30+
import org.apache.jena.sparql.engine.dispatch.SparqlDispatcherRegistry;
3031
import org.apache.jena.sparql.exec.http.Params;
3132
import org.apache.jena.sparql.exec.http.QuerySendMode;
3233
import org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps;
@@ -44,7 +45,7 @@ public abstract class ExecHTTPBuilder<X, Y> {
4445
protected String serviceURL = null;
4546
private Query query = null;
4647
protected String queryString = null;
47-
protected boolean parseCheck = true;
48+
protected Boolean parseCheck = null;
4849
private HttpClient httpClient = null;
4950
protected Map<String, String> httpHeaders = new HashMap<>();
5051
protected Params params = Params.create();
@@ -79,6 +80,10 @@ public Y parseCheck(boolean parseCheck) {
7980
return thisBuilder();
8081
}
8182

83+
protected boolean effectiveParseCheck() {
84+
return SparqlDispatcherRegistry.effectiveParseCheck(parseCheck, contextAcc);
85+
}
86+
8287
/** Set the query - this also sets the query string to agree with the query argument. */
8388
public Y query(Query query) {
8489
Objects.requireNonNull(query);
@@ -93,14 +98,14 @@ public Y query(Query query) {
9398
*/
9499
public Y query(String queryStr) {
95100
Objects.requireNonNull(queryStr);
96-
Query query = parseCheck ? QueryFactory.create(queryStr) : null;
101+
Query query = effectiveParseCheck() ? QueryFactory.create(queryStr) : null;
97102
setQuery(query, queryStr);
98103
return thisBuilder();
99104
}
100105

101106
public Y query(String queryStr, Syntax syntax) {
102107
Objects.requireNonNull(queryStr);
103-
Query query = QueryFactory.create(queryStr, syntax);
108+
Query query = effectiveParseCheck() ? QueryFactory.create(queryStr, syntax) : null;
104109
setQuery(query, queryStr);
105110
return thisBuilder();
106111
}

jena-arq/src/main/java/org/apache/jena/http/sys/ExecUpdateHTTPBuilder.java

Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
import java.net.http.HttpClient;
2222
import java.util.*;
2323
import java.util.concurrent.TimeUnit;
24-
import java.util.stream.Collectors;
2524

2625
import org.apache.jena.graph.Node;
2726
import org.apache.jena.http.HttpEnv;
2827
import org.apache.jena.query.ARQ;
2928
import org.apache.jena.sparql.core.Var;
3029
import org.apache.jena.sparql.engine.binding.Binding;
30+
import org.apache.jena.sparql.engine.dispatch.SparqlDispatcherRegistry;
3131
import org.apache.jena.sparql.exec.http.Params;
3232
import org.apache.jena.sparql.exec.http.UpdateSendMode;
3333
import org.apache.jena.sparql.syntax.syntaxtransform.UpdateTransformOps;
@@ -37,110 +37,14 @@
3737
import org.apache.jena.sys.JenaSystem;
3838
import org.apache.jena.update.Update;
3939
import org.apache.jena.update.UpdateException;
40-
import org.apache.jena.update.UpdateFactory;
4140
import org.apache.jena.update.UpdateRequest;
4241

4342
public abstract class ExecUpdateHTTPBuilder<X, Y> {
4443

45-
/** Update element. Either an Update object or a string. */
46-
private record UpdateElt(Update update, String updateString) {
47-
UpdateElt(Update update) { this(Objects.requireNonNull(update), null); }
48-
UpdateElt(String updateString) { this(null, Objects.requireNonNull(updateString)); }
49-
boolean isParsed() { return update != null; }
50-
51-
@Override
52-
public String toString() {
53-
return isParsed()
54-
? new UpdateRequest(update()).toString() // Reuse UpdateRequest's serialization approach
55-
: updateString();
56-
}
57-
}
58-
59-
/** Accumulator for update elements. Can build an overall string or UpdateRequest from the elements. */
60-
private class UpdateEltAcc implements Iterable<UpdateElt> {
61-
/** Delimiter for joining multiple SPARQL update strings into a single one.
62-
* The delimiter takes into account that the last line of a statement may be a single-line-comment. */
63-
public static final String DELIMITER = "\n;\n";
64-
65-
private List<UpdateElt> updateOperations = new ArrayList<>();
66-
private List<UpdateElt> updateOperationsView = Collections.unmodifiableList(updateOperations);
67-
private boolean isParsed = true; // True iff there are no strings in updateOperations
68-
69-
public boolean isParsed() {
70-
return isParsed;
71-
}
72-
73-
public void add(UpdateElt updateElt) {
74-
isParsed = isParsed && updateElt.isParsed();
75-
updateOperations.add(updateElt);
76-
}
77-
78-
public void add(Update update) {
79-
add(new UpdateElt(update));
80-
}
81-
82-
/** Add a string by parsing it. */
83-
public void add(String updateRequestString) {
84-
UpdateRequest updateRequest = UpdateFactory.create(updateRequestString);
85-
add(updateRequest);
86-
}
87-
88-
public void add(UpdateRequest updateRequest) {
89-
updateRequest.getOperations().forEach(this::add);
90-
}
91-
92-
/** Add a string without parsing it. */
93-
public void addString(String updateRequestString) {
94-
add(new UpdateElt(updateRequestString));
95-
}
96-
97-
/** Attempt to build an UpdateRequest from the state of this accumulator. Attempts to parse any string elements. */
98-
public UpdateRequest buildUpdateRequest() {
99-
return addToUpdateRequest(new UpdateRequest());
100-
}
101-
102-
public UpdateRequest addToUpdateRequest(UpdateRequest updateRequest) {
103-
for (UpdateElt elt : updateOperations) {
104-
if (elt.isParsed()) {
105-
updateRequest.add(elt.update());
106-
} else {
107-
try {
108-
updateRequest.add(elt.updateString());
109-
} catch (Exception e) {
110-
// Expose the string that failed to parse
111-
e.addSuppressed(new RuntimeException("Failed to parse: " + elt.updateString()));
112-
throw e;
113-
}
114-
}
115-
}
116-
return updateRequest;
117-
}
118-
119-
public void clear() {
120-
updateOperations.clear();
121-
isParsed = true;
122-
}
123-
124-
public boolean isEmpty() {
125-
return updateOperations.isEmpty();
126-
}
127-
128-
@Override
129-
public Iterator<UpdateElt> iterator() {
130-
return updateOperationsView.iterator();
131-
}
132-
133-
public String buildString() {
134-
return updateOperations.stream()
135-
.map(UpdateElt::toString)
136-
.collect(Collectors.joining(DELIMITER));
137-
}
138-
}
139-
14044
static { JenaSystem.init(); }
14145

14246
protected String serviceURL;
143-
protected boolean parseCheck = true;
47+
protected Boolean parseCheck = null;
14448
private UpdateEltAcc updateEltAcc = new UpdateEltAcc();
14549

14650
protected Params params = Params.create();
@@ -173,7 +77,7 @@ public Y update(UpdateRequest updateRequest) {
17377

17478
public Y update(String updateRequestString) {
17579
Objects.requireNonNull(updateRequestString);
176-
if (parseCheck) {
80+
if (effectiveParseCheck()) {
17781
updateEltAcc.add(updateRequestString);
17882
} else {
17983
updateEltAcc.addString(updateRequestString);
@@ -205,6 +109,10 @@ public Y parseCheck(boolean parseCheck) {
205109
return thisBuilder();
206110
}
207111

112+
protected boolean effectiveParseCheck() {
113+
return SparqlDispatcherRegistry.effectiveParseCheck(parseCheck, contextAcc);
114+
}
115+
208116
public Y substitution(Binding binding) {
209117
binding.forEach(this.substitutionMap::put);
210118
return thisBuilder();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.jena.http.sys;
20+
21+
import java.util.Objects;
22+
23+
import org.apache.jena.update.Update;
24+
import org.apache.jena.update.UpdateRequest;
25+
26+
/** Update element. Either an Update object or a string. */
27+
record UpdateElt(Update update, String updateString) {
28+
UpdateElt(Update update) { this(Objects.requireNonNull(update), null); }
29+
UpdateElt(String updateString) { this(null, Objects.requireNonNull(updateString)); }
30+
boolean isParsed() { return update != null; }
31+
32+
@Override
33+
public String toString() {
34+
return isParsed()
35+
? new UpdateRequest(update()).toString() // Reuse UpdateRequest's serialization approach
36+
: updateString();
37+
}
38+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.jena.http.sys;
20+
21+
import java.util.ArrayList;
22+
import java.util.Collections;
23+
import java.util.Iterator;
24+
import java.util.List;
25+
import java.util.stream.Collectors;
26+
27+
import org.apache.jena.update.Update;
28+
import org.apache.jena.update.UpdateFactory;
29+
import org.apache.jena.update.UpdateRequest;
30+
31+
/** Accumulator for update elements. Can build an overall string or UpdateRequest from the elements. */
32+
public class UpdateEltAcc implements Iterable<UpdateElt> {
33+
/** Delimiter for joining multiple SPARQL update strings into a single one.
34+
* The delimiter takes into account that the last line of a statement may be a single-line-comment. */
35+
public static final String DELIMITER = "\n;\n";
36+
37+
private List<UpdateElt> updateOperations = new ArrayList<>();
38+
private List<UpdateElt> updateOperationsView = Collections.unmodifiableList(updateOperations);
39+
private boolean isParsed = true; // True iff there are no strings in updateOperations
40+
41+
public boolean isParsed() {
42+
return isParsed;
43+
}
44+
45+
public void add(UpdateElt updateElt) {
46+
isParsed = isParsed && updateElt.isParsed();
47+
updateOperations.add(updateElt);
48+
}
49+
50+
public void add(Update update) {
51+
add(new UpdateElt(update));
52+
}
53+
54+
/** Add a string by parsing it. */
55+
public void add(String updateRequestString) {
56+
UpdateRequest updateRequest = UpdateFactory.create(updateRequestString);
57+
add(updateRequest);
58+
}
59+
60+
public void add(UpdateRequest updateRequest) {
61+
updateRequest.getOperations().forEach(this::add);
62+
}
63+
64+
/** Add a string without parsing it. */
65+
public void addString(String updateRequestString) {
66+
add(new UpdateElt(updateRequestString));
67+
}
68+
69+
/** Attempt to build an UpdateRequest from the state of this accumulator. Attempts to parse any string elements. */
70+
public UpdateRequest buildUpdateRequest() {
71+
return addToUpdateRequest(new UpdateRequest());
72+
}
73+
74+
public UpdateRequest addToUpdateRequest(UpdateRequest updateRequest) {
75+
for (UpdateElt elt : updateOperations) {
76+
if (elt.isParsed()) {
77+
updateRequest.add(elt.update());
78+
} else {
79+
try {
80+
updateRequest.add(elt.updateString());
81+
} catch (Exception e) {
82+
// Expose the string that failed to parse
83+
e.addSuppressed(new RuntimeException("Failed to parse: " + elt.updateString()));
84+
throw e;
85+
}
86+
}
87+
}
88+
return updateRequest;
89+
}
90+
91+
public void clear() {
92+
updateOperations.clear();
93+
isParsed = true;
94+
}
95+
96+
public boolean isEmpty() {
97+
return updateOperations.isEmpty();
98+
}
99+
100+
@Override
101+
public Iterator<UpdateElt> iterator() {
102+
return updateOperationsView.iterator();
103+
}
104+
105+
public String buildString() {
106+
return updateOperations.stream()
107+
.map(UpdateElt::toString)
108+
.collect(Collectors.joining(DELIMITER));
109+
}
110+
}

jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFOps.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public static void sendGraphToStream(Graph graph, StreamRDF stream, String baseU
104104
stream.base(baseURI);
105105
if ( prefixMap != null )
106106
sendPrefixesToStream(prefixMap, stream) ;
107+
sendGraphTriplesToStream(graph, stream);
108+
}
109+
110+
/** Send only the triples of graph to a StreamRDF */
111+
public static void sendGraphTriplesToStream(Graph graph, StreamRDF stream) {
107112
ExtendedIterator<Triple> iter = graph.find(null, null, null) ;
108113
try {
109114
StreamRDFOps.sendTriplesToStream(iter, stream) ;

jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ public class ARQConstants
317317
public static final Symbol registryExtensions =
318318
SystemARQ.allocSymbol("registryExtensions") ;
319319

320-
public static void init() {}
320+
public static final Symbol registrySparqlDispatchers =
321+
SystemARQ.allocSymbol("registrySparqlDispatchers") ;
322+
323+
/** Symbol for use with dataset contexts for disabling parse checks for queries and updates */
324+
public static final Symbol parseCheck =
325+
SystemARQ.allocSymbol("parseCheck") ;
321326

327+
public static void init() {}
322328
}

jena-arq/src/main/java/org/apache/jena/sparql/engine/Timeouts.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,23 @@ public static String toString(Timeout timeout) {
233233
return result;
234234
}
235235

236-
// Set times from context if not set directly. e..g Context provides default values.
237-
// Contrast with SPARQLQueryProcessor where the context is limiting values of the protocol parameter.
236+
/**
237+
* Update unset values in the builder with values from the context.
238+
*
239+
* Set times from context if not set directly, i.e. context provides default values.
240+
* Contrast with SPARQLQueryProcessor where the context is limiting values of the protocol parameter.
241+
*/
238242
public static void applyDefaultQueryTimeoutFromContext(TimeoutBuilderImpl builder, Context cxt) {
239243
Timeout queryTimeout = extractQueryTimeout(cxt);
240244
applyDefaultTimeout(builder, queryTimeout);
241245
}
242246

247+
/** Update unset values in the builder with values from the context. */
248+
public static void applyDefaultUpdateTimeoutFromContext(TimeoutBuilderImpl builder, Context cxt) {
249+
Timeout queryTimeout = extractUpdateTimeout(cxt);
250+
applyDefaultTimeout(builder, queryTimeout);
251+
}
252+
243253
/** Returns milliseconds if the given time unit is null. */
244254
private static TimeUnit nullToMillis(TimeUnit unit) {
245255
return unit != null ? unit : TimeUnit.MILLISECONDS;

0 commit comments

Comments
 (0)