Skip to content

Package: SparqlQueryFactory

SparqlQueryFactory

nameinstructionbranchcomplexitylinemethod
SparqlQueryFactory(UnitOfWorkImpl, ConnectionWrapper)
M: 8 C: 20
71%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 7
100%
M: 0 C: 1
100%
createNamedQuery(String)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createNamedQuery(String, Class)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createNativeQuery(String)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createNativeQuery(String, Class)
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createNativeQuery(String, String)
M: 0 C: 36
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createQuery(String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createQuery(String, Class)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.query.sparql;
16:
17: import cz.cvut.kbss.jopa.model.QueryImpl;
18: import cz.cvut.kbss.jopa.model.ResultSetMappingQuery;
19: import cz.cvut.kbss.jopa.model.TypedQueryImpl;
20: import cz.cvut.kbss.jopa.query.QueryParser;
21: import cz.cvut.kbss.jopa.query.mapper.SparqlResultMapper;
22: import cz.cvut.kbss.jopa.sessions.ConnectionWrapper;
23: import cz.cvut.kbss.jopa.sessions.QueryFactory;
24: import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
25: import cz.cvut.kbss.jopa.utils.ErrorUtils;
26:
27: import java.util.Objects;
28:
29: public class SparqlQueryFactory implements QueryFactory {
30:
31: private final UnitOfWorkImpl uow;
32: private final ConnectionWrapper connection;
33:
34: private final QueryParser queryParser;
35:
36: public SparqlQueryFactory(UnitOfWorkImpl uow, ConnectionWrapper connection) {
37:• assert uow != null;
38:• assert connection != null;
39: this.uow = uow;
40: this.connection = connection;
41: this.queryParser = new SparqlQueryParser();
42: }
43:
44: @Override
45: public QueryImpl createNativeQuery(String sparql) {
46: Objects.requireNonNull(sparql);
47:
48: final QueryImpl q = new QueryImpl(queryParser.parseQuery(sparql), connection);
49: q.useBackupOntology(uow.useBackupOntologyForQueryProcessing());
50: return q;
51: }
52:
53: @Override
54: public <T> TypedQueryImpl<T> createNativeQuery(String sparql, Class<T> resultClass) {
55: Objects.requireNonNull(sparql, ErrorUtils.getNPXMessageSupplier("sparql"));
56: Objects.requireNonNull(resultClass, ErrorUtils.getNPXMessageSupplier("resultClass"));
57:
58: final TypedQueryImpl<T> tq = new TypedQueryImpl<>(queryParser.parseQuery(sparql), resultClass, connection, uow);
59: tq.setUnitOfWork(uow);
60: tq.useBackupOntology(uow.useBackupOntologyForQueryProcessing());
61: return tq;
62: }
63:
64: @Override
65: public QueryImpl createNativeQuery(String sparql, String resultSetMapping) {
66: Objects.requireNonNull(sparql, ErrorUtils.getNPXMessageSupplier("sparql"));
67: Objects.requireNonNull(resultSetMapping, ErrorUtils.getNPXMessageSupplier("resultSetMapping"));
68:
69: final SparqlResultMapper mapper = uow.getResultSetMappingManager().getMapper(resultSetMapping);
70: final ResultSetMappingQuery q = new ResultSetMappingQuery(queryParser.parseQuery(sparql), connection, mapper, uow);
71: q.useBackupOntology(uow.useBackupOntologyForQueryProcessing());
72: return q;
73: }
74:
75: @Override
76: public QueryImpl createQuery(String query) {
77: Objects.requireNonNull(query);
78:
79: // We do not support any more abstract syntax, yet
80: return createNativeQuery(query);
81: }
82:
83: @Override
84: public <T> TypedQueryImpl<T> createQuery(String query, Class<T> resultClass) {
85: Objects.requireNonNull(query, ErrorUtils.getNPXMessageSupplier("query"));
86: Objects.requireNonNull(resultClass, ErrorUtils.getNPXMessageSupplier("resultClass"));
87:
88: // We do not support any more abstract syntax, yet
89: return createNativeQuery(query, resultClass);
90: }
91:
92: @Override
93: public QueryImpl createNamedQuery(String name) {
94: final String query = uow.getNamedQueryManager().getQuery(name);
95: return createNativeQuery(query);
96: }
97:
98: @Override
99: public <T> TypedQueryImpl<T> createNamedQuery(String name, Class<T> resultClass) {
100: final String query = uow.getNamedQueryManager().getQuery(name);
101: return createNativeQuery(query, resultClass);
102: }
103: }