Skip to content

Commit 570820a

Browse files
committed
pull up getQueryExecution to superclass
1 parent 168548c commit 570820a

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

context-core/src/main/java/de/atb/context/persistence/common/RepositoryTDB.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
import de.atb.context.common.util.BusinessCase;
1919
import de.atb.context.common.util.IApplicationScenarioProvider;
2020
import de.atb.context.context.util.OntologyNamespace;
21+
import org.apache.jena.ontology.OntModel;
22+
import org.apache.jena.ontology.OntModelSpec;
2123
import org.apache.jena.query.Dataset;
24+
import org.apache.jena.query.QueryExecution;
25+
import org.apache.jena.query.QueryExecutionFactory;
2226
import org.apache.jena.query.ReadWrite;
27+
import org.apache.jena.rdf.model.Model;
28+
import org.apache.jena.rdf.model.ModelFactory;
2329
import org.apache.jena.tdb.TDB;
2430
import org.apache.jena.tdb.TDBFactory;
2531
import org.slf4j.Logger;
@@ -189,4 +195,22 @@ private synchronized Dataset initializeDataset(final BusinessCase bc) throws Con
189195
throw new ConfigurationException("Data directory for the TDB repository couldn't be created.");
190196
}
191197
}
198+
199+
protected QueryExecution getQueryExecution(String query, boolean useReasoner, Dataset dataset) {
200+
if (query == null) {
201+
throw new NullPointerException("Query may not be null!");
202+
}
203+
if (query.trim().length() == 0) {
204+
throw new IllegalArgumentException("Query may not be empty!");
205+
}
206+
String finalQuery = prepareSparqlQuery(query);
207+
Model model = dataset.getDefaultModel();
208+
OntModel ontModel;
209+
if (useReasoner) {
210+
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
211+
} else {
212+
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, model);
213+
}
214+
return QueryExecutionFactory.create(finalQuery, ontModel);
215+
}
192216
}

context-extraction/src/main/java/de/atb/context/persistence/context/ContextRepository.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import de.atb.context.common.util.BusinessCase;
2020
import de.atb.context.common.util.IApplicationScenarioProvider;
2121
import de.atb.context.common.util.TimeFrame;
22-
import de.atb.context.context.util.OntologyNamespace;
2322
import de.atb.context.extraction.ContextContainer;
2423
import de.atb.context.extraction.util.base.BaseDatatypeProperties;
2524
import de.atb.context.extraction.util.base.BaseOntologyClasses;
@@ -291,7 +290,7 @@ private <R> R executeSparql(BusinessCase businessCase, String query, boolean use
291290
Dataset dataset = getDataSet(businessCase);
292291
dataset.begin(ReadWrite.READ);
293292
try {
294-
QueryExecution queryExecution = getQueryExecution(businessCase, query, useReasoner, dataset);
293+
QueryExecution queryExecution = getQueryExecution(query, useReasoner, dataset);
295294
R result = executioner.apply(queryExecution);
296295
dataset.commit();
297296
return result;
@@ -304,24 +303,6 @@ private <R> R executeSparql(BusinessCase businessCase, String query, boolean use
304303
}
305304
}
306305

307-
private QueryExecution getQueryExecution(BusinessCase businessCase, String query, boolean useReasoner, Dataset dataset) {
308-
if (query == null) {
309-
throw new NullPointerException("Query may not be null!");
310-
}
311-
if (query.trim().length() == 0) {
312-
throw new IllegalArgumentException("Query may not be empty!");
313-
}
314-
String finalQuery = prepareSparqlQuery(query);
315-
Model model = dataset.getDefaultModel();
316-
OntModel ontModel;
317-
if (useReasoner) {
318-
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);
319-
} else {
320-
ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, model);
321-
}
322-
return QueryExecutionFactory.create(finalQuery, ontModel);
323-
}
324-
325306
/**
326307
* (non-Javadoc)
327308
*

context-monitoring/src/main/java/de/atb/context/persistence/monitoring/MonitoringDataRepository.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,11 @@ public synchronized ResultSet executeSparqlSelectQuery(final BusinessCase busine
453453
if (businessCase == null) {
454454
throw new NullPointerException("BusinessCase may not be null!");
455455
}
456-
if (query == null) {
457-
throw new NullPointerException("Query may not be null!");
458-
}
459-
if (query.trim().length() == 0) {
460-
throw new IllegalArgumentException("Query may not be empty!");
461-
}
462456

463-
final String finalQuery = prepareSparqlQuery(query);
464457
final Dataset dataset = getDataSet(businessCase);
465458

466459
return transactional(dataset, null, () -> {
467-
final Model model = dataset.getDefaultModel();
468-
final OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, model);
469-
final QueryExecution qexec = QueryExecutionFactory.create(finalQuery, ontModel);
460+
final QueryExecution qexec = getQueryExecution(query, false, dataset);
470461
return qexec.execSelect();
471462
});
472463
}

0 commit comments

Comments
 (0)