Skip to content

Commit 8338bc2

Browse files
committed
GH-5828: cleanup deprecated code usages in FedX module
- converting exception is not required (iterations are fine to propagate runtime exceptions) - iteration closing is handled abstract class (no need to duplicate) - use URI.toUrl() replacement in EndpointFactory
1 parent f6582f0 commit 8338bc2

5 files changed

Lines changed: 17 additions & 67 deletions

File tree

tools/federation/src/main/java/org/eclipse/rdf4j/federated/FedXConnection.java

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
1818
import org.eclipse.rdf4j.common.iteration.DistinctIteration;
1919
import org.eclipse.rdf4j.common.iteration.EmptyIteration;
20-
import org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration;
2120
import org.eclipse.rdf4j.common.iteration.Iterations;
2221
import org.eclipse.rdf4j.common.transaction.TransactionSetting;
2322
import org.eclipse.rdf4j.federated.algebra.PassThroughTupleExpr;
@@ -266,14 +265,7 @@ public void cancel() {
266265
// execute the union in a separate thread
267266
federationContext.getManager().getExecutor().execute(union);
268267
CollectionFactory cf = federation.getCollectionFactory().get();
269-
ExceptionConvertingIteration<Resource, SailException> conv = new ExceptionConvertingIteration<>(union) {
270-
271-
@Override
272-
protected SailException convert(RuntimeException e) {
273-
return new SailException(e);
274-
}
275-
};
276-
return new DistinctIteration<Resource>(conv, cf::createSet) {
268+
return new DistinctIteration<Resource>(union, cf::createSet) {
277269

278270
@Override
279271
protected void handleClose() {
@@ -305,36 +297,12 @@ protected CloseableIteration<? extends Namespace> getNamespacesInternal() throws
305297
protected CloseableIteration<? extends Statement> getStatementsInternal(Resource subj, IRI pred,
306298
Value obj, boolean includeInferred, Resource... contexts) throws SailException {
307299

308-
try {
309-
Dataset dataset = new SimpleDataset();
310-
FederationEvaluationStrategy strategy = federationContext.createStrategy(dataset);
311-
QueryInfo queryInfo = new QueryInfo(subj, pred, obj, 0, includeInferred, federationContext, strategy,
312-
dataset);
313-
federationContext.getMonitoringService().monitorQuery(queryInfo);
314-
CloseableIteration<Statement> res = null;
315-
try {
316-
res = strategy.getStatements(queryInfo, subj, pred, obj, contexts);
317-
return new ExceptionConvertingIteration<>(res) {
318-
@Override
319-
protected SailException convert(RuntimeException e) {
320-
return new SailException(e);
321-
}
322-
};
323-
} catch (Throwable t) {
324-
if (res != null) {
325-
res.close();
326-
}
327-
throw t;
328-
}
329-
330-
} catch (RuntimeException e) {
331-
throw e;
332-
} catch (Exception e) {
333-
if (e instanceof InterruptedException) {
334-
Thread.currentThread().interrupt();
335-
}
336-
throw new SailException(e);
337-
}
300+
Dataset dataset = new SimpleDataset();
301+
FederationEvaluationStrategy strategy = federationContext.createStrategy(dataset);
302+
QueryInfo queryInfo = new QueryInfo(subj, pred, obj, 0, includeInferred, federationContext, strategy,
303+
dataset);
304+
federationContext.getMonitoringService().monitorQuery(queryInfo);
305+
return strategy.getStatements(queryInfo, subj, pred, obj, contexts);
338306
}
339307

340308
@Override

tools/federation/src/main/java/org/eclipse/rdf4j/federated/endpoint/EndpointFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import java.io.File;
1414
import java.io.FileReader;
1515
import java.net.MalformedURLException;
16-
import java.net.URL;
16+
import java.net.URI;
17+
import java.net.URISyntaxException;
1718
import java.util.ArrayList;
1819
import java.util.List;
1920

@@ -86,12 +87,12 @@ public static Endpoint loadSPARQLEndpoint(String name, String endpoint) throws F
8687
*/
8788
public static Endpoint loadSPARQLEndpoint(String endpoint) throws FedXException {
8889
try {
89-
String id = new URL(endpoint).getHost();
90+
String id = new URI(endpoint).toURL().getHost();
9091
if (id.equals("localhost")) {
91-
id = id + "_" + new URL(endpoint).getPort();
92+
id = id + "_" + new URI(endpoint).toURL().getPort();
9293
}
9394
return loadSPARQLEndpoint("http://" + id, endpoint);
94-
} catch (MalformedURLException e) {
95+
} catch (URISyntaxException | MalformedURLException e) {
9596
throw new FedXException("Malformed URL: " + endpoint);
9697
}
9798
}

tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/SailTripleSource.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
1414
import org.eclipse.rdf4j.common.iteration.EmptyIteration;
15-
import org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration;
1615
import org.eclipse.rdf4j.federated.FederationContext;
1716
import org.eclipse.rdf4j.federated.algebra.FilterValueExpr;
1817
import org.eclipse.rdf4j.federated.algebra.PrecompiledQueryNode;
@@ -117,16 +116,7 @@ public CloseableIteration<Statement> getStatements(
117116
repoResult = conn.getStatements(subj, pred, obj,
118117
queryInfo.getIncludeInferred(), contexts);
119118

120-
// XXX implementation remark and TODO taken from Sesame
121-
// The same variable might have been used multiple times in this
122-
// StatementPattern, verify value equality in those cases.
123-
124-
resultHolder.set(new ExceptionConvertingIteration<>(repoResult) {
125-
@Override
126-
protected QueryEvaluationException convert(RuntimeException arg0) {
127-
return new QueryEvaluationException(arg0);
128-
}
129-
});
119+
resultHolder.set(repoResult);
130120
} catch (Throwable t) {
131121
if (repoResult != null) {
132122
repoResult.close();

tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/SparqlTripleSource.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.eclipse.rdf4j.federated.evaluation;
1212

1313
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
14-
import org.eclipse.rdf4j.common.iteration.ExceptionConvertingIteration;
1514
import org.eclipse.rdf4j.federated.FederationContext;
1615
import org.eclipse.rdf4j.federated.algebra.ExclusiveTupleExpr;
1716
import org.eclipse.rdf4j.federated.algebra.FilterValueExpr;
@@ -191,15 +190,7 @@ public CloseableIteration<Statement> getStatements(
191190
try {
192191
repoResult = conn.getStatements(subj, pred, obj,
193192
queryInfo.getIncludeInferred(), contexts);
194-
resultHolder.set(new ExceptionConvertingIteration<>(repoResult) {
195-
@Override
196-
protected QueryEvaluationException convert(RuntimeException ex) {
197-
if (ex instanceof QueryEvaluationException) {
198-
return (QueryEvaluationException) ex;
199-
}
200-
return new QueryEvaluationException(ex);
201-
}
202-
});
193+
resultHolder.set(repoResult);
203194
} catch (Throwable t) {
204195
if (repoResult != null) {
205196
repoResult.close();

tools/federation/src/main/java/org/eclipse/rdf4j/federated/evaluation/iterator/FedXPathIteration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public static final BiConsumer<Value, MutableBindingSet> getSet(String s) {
147147
case END:
148148
return (v, vp) -> ((ValuePair) vp).endValue = v;
149149
default:
150-
return (v, vp) -> {
150+
return (_, _) -> {
151151
throw new IllegalStateException("A value is being asked to be set where we never expected one");
152152
};
153153
}
@@ -166,7 +166,7 @@ public static final Function<BindingSet, Value> getGet(String s) {
166166
case END:
167167
return (vp) -> ((ValuePair) vp).endValue;
168168
default:
169-
return (vp) -> {
169+
return (_) -> {
170170
throw new IllegalStateException("A value is being asked to be set where we never expected one");
171171
};
172172
}
@@ -185,7 +185,7 @@ public static final Predicate<BindingSet> getHas(String s) {
185185
case END:
186186
return (vp) -> ((ValuePair) vp).endValue != null;
187187
default:
188-
return (vp) -> {
188+
return (_) -> {
189189
throw new IllegalStateException("A value is being asked to be set where we never expected one");
190190
};
191191
}

0 commit comments

Comments
 (0)