Skip to content

Package: SparqlQueryFactory

SparqlQueryFactory

nameinstructionbranchcomplexitylinemethod
SparqlQueryFactory(UnitOfWorkImpl, ConnectionWrapper)
M: 8 C: 33
80%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 8
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: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createQuery(String, Class)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createQueryImpl(String, Class, QueryParser)
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
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) 2022 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.query.parameter.ParameterValueFactory;
23: import cz.cvut.kbss.jopa.query.soql.SoqlQueryParser;
24: import cz.cvut.kbss.jopa.sessions.ConnectionWrapper;
25: import cz.cvut.kbss.jopa.sessions.QueryFactory;
26: import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
27: import cz.cvut.kbss.jopa.utils.ErrorUtils;
28:
29: import java.util.Objects;
30:
31: public class SparqlQueryFactory implements QueryFactory {
32:
33: private final UnitOfWorkImpl uow;
34: private final ConnectionWrapper connection;
35:
36: private final QueryParser queryParser;
37: private final SoqlQueryParser soqlQueryParser;
38:
39: public SparqlQueryFactory(UnitOfWorkImpl uow, ConnectionWrapper connection) {
40:• assert uow != null;
41:• assert connection != null;
42: this.uow = uow;
43: this.connection = connection;
44: this.queryParser = new SparqlQueryParser(new ParameterValueFactory(uow));
45: this.soqlQueryParser = new SoqlQueryParser(queryParser, uow.getMetamodel());
46: }
47:
48: @Override
49: public QueryImpl createNativeQuery(String sparql) {
50: Objects.requireNonNull(sparql);
51:
52: final QueryImpl q = new QueryImpl(queryParser.parseQuery(sparql), connection);
53: q.useBackupOntology(uow.useBackupOntologyForQueryProcessing());
54: return q;
55: }
56:
57: @Override
58: public <T> TypedQueryImpl<T> createNativeQuery(String sparql, Class<T> resultClass) {
59: Objects.requireNonNull(sparql, ErrorUtils.getNPXMessageSupplier("sparql"));
60:
61: return createQueryImpl(sparql, resultClass, queryParser);
62: }
63:
64: private <T> TypedQueryImpl<T> createQueryImpl(String query, Class<T> resultClass, QueryParser parser) {
65: Objects.requireNonNull(resultClass, ErrorUtils.getNPXMessageSupplier("resultClass"));
66:
67: final TypedQueryImpl<T> tq = new TypedQueryImpl<>(parser.parseQuery(query), resultClass, connection, uow);
68: tq.setUnitOfWork(uow);
69: tq.useBackupOntology(uow.useBackupOntologyForQueryProcessing());
70: return tq;
71: }
72:
73: @Override
74: public QueryImpl createNativeQuery(String sparql, String resultSetMapping) {
75: Objects.requireNonNull(sparql, ErrorUtils.getNPXMessageSupplier("sparql"));
76: Objects.requireNonNull(resultSetMapping, ErrorUtils.getNPXMessageSupplier("resultSetMapping"));
77:
78: final SparqlResultMapper mapper = uow.getResultSetMappingManager().getMapper(resultSetMapping);
79: final ResultSetMappingQuery q = new ResultSetMappingQuery(queryParser.parseQuery(sparql), connection, mapper,
80: uow);
81: q.useBackupOntology(uow.useBackupOntologyForQueryProcessing());
82: return q;
83: }
84:
85: @Override
86: public QueryImpl createQuery(String query) {
87: Objects.requireNonNull(query);
88:
89: final QueryImpl q = new QueryImpl(soqlQueryParser.parseQuery(query), connection);
90: q.useBackupOntology(uow.useBackupOntologyForQueryProcessing());
91: return q;
92: }
93:
94: @Override
95: public <T> TypedQueryImpl<T> createQuery(String query, Class<T> resultClass) {
96: Objects.requireNonNull(query, ErrorUtils.getNPXMessageSupplier("query"));
97: return createQueryImpl(query, resultClass, soqlQueryParser);
98: }
99:
100: @Override
101: public QueryImpl createNamedQuery(String name) {
102: final String query = uow.getNamedQueryManager().getQuery(name);
103: return createNativeQuery(query);
104: }
105:
106: @Override
107: public <T> TypedQueryImpl<T> createNamedQuery(String name, Class<T> resultClass) {
108: final String query = uow.getNamedQueryManager().getQuery(name);
109: return createNativeQuery(query, resultClass);
110: }
111: }