Skip to content

Package: GraphDBStatementLoaderFactory

GraphDBStatementLoaderFactory

nameinstructionbranchcomplexitylinemethod
GraphDBStatementLoaderFactory()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
create(Connector, Resource, AxiomBuilder)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isRepositoryGraphDB(Connector)
M: 4 C: 28
88%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 6
75%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.ontodriver.rdf4j.loader;
2:
3: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
4: import cz.cvut.kbss.ontodriver.rdf4j.connector.Connector;
5: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
6: import cz.cvut.kbss.ontodriver.rdf4j.util.AxiomBuilder;
7: import org.eclipse.rdf4j.model.Resource;
8: import org.eclipse.rdf4j.model.ValueFactory;
9: import org.eclipse.rdf4j.query.BooleanQuery;
10: import org.eclipse.rdf4j.repository.Repository;
11: import org.eclipse.rdf4j.repository.RepositoryConnection;
12:
13: /**
14: * Builds statement loaders for GraphDB repository access.
15: */
16: public class GraphDBStatementLoaderFactory implements StatementLoaderFactory {
17:
18: /**
19: * Property representing internal entity IDs in GraphDB.
20: */
21: static final String GRAPHDB_INTERNAL_ID_PROPERTY = "http://www.ontotext.com/owlim/entity#id";
22:
23: @Override
24: public StatementLoader create(Connector connector, Resource subject, AxiomBuilder axiomBuilder) {
25: return new GraphDBStatementLoader(connector, subject, axiomBuilder);
26: }
27:
28: /**
29: * Checks whether the underlying repository is in fact GraphDB.
30: * <p>
31: * It asks the repository if any subject has an internal GraphDB entity ID (represented by the {@link
32: * #GRAPHDB_INTERNAL_ID_PROPERTY}). Such a triple does not normally show in the data, but is accessing in GraphDB.
33: * If, for some reason, data stored in a non-GraphDB repository explicitly use these identifiers, this method will
34: * return false positive result.
35: *
36: * @param connector Connector to the repository
37: * @return {@code true} if repository is determined to be GraphDB, {@code false} otherwise
38: */
39: public static boolean isRepositoryGraphDB(Connector connector) throws Rdf4jDriverException {
40: try {
41: final Repository repository = connector.unwrap(Repository.class);
42: try (final RepositoryConnection connection = repository.getConnection()) {
43: final ValueFactory vf = connection.getValueFactory();
44: // Have to use a SPARQL query, because RDF4J API hasStatement call ended with an error
45: // See https://graphdb.ontotext.com/documentation/standard/query-behaviour.html#how-to-access-internal-identifiers-for-entities
46: final BooleanQuery query = connection.prepareBooleanQuery("ASK { ?x ?internalId ?y }");
47: query.setBinding("internalId", vf.createIRI(GRAPHDB_INTERNAL_ID_PROPERTY));
48: return query.evaluate();
49: }
50: } catch (OntoDriverException e) {
51: throw (Rdf4jDriverException) e;
52: }
53: }
54: }