Skip to content

Package: OwlapiPreparedStatement

OwlapiPreparedStatement

nameinstructionbranchcomplexitylinemethod
OwlapiPreparedStatement(StatementExecutorFactory, OwlapiConnection, String)
M: 5 C: 19
79%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 5
83%
M: 0 C: 1
100%
clearParameters()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
executeQuery()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
executeUpdate()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setObject(String, Object)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: * <p>
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: * <p>
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.ontodriver.owlapi.query;
16:
17: import cz.cvut.kbss.ontodriver.PreparedStatement;
18: import cz.cvut.kbss.ontodriver.ResultSet;
19: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
20: import cz.cvut.kbss.ontodriver.owlapi.OwlapiConnection;
21: import cz.cvut.kbss.ontodriver.util.StatementHolder;
22:
23: import java.util.Objects;
24:
25: import static cz.cvut.kbss.ontodriver.util.ErrorUtils.getNPXMessageSupplier;
26:
27: public class OwlapiPreparedStatement extends OwlapiStatement implements PreparedStatement {
28:
29: private final StatementHolder statementHolder;
30:
31: public OwlapiPreparedStatement(StatementExecutorFactory executorFactory, OwlapiConnection connection,
32: String statement) {
33: super(executorFactory, connection);
34: this.statementHolder = new StatementHolder(statement);
35:• if (statementHolder.getStatement().isEmpty()) {
36: throw new IllegalArgumentException("Statement cannot be empty.");
37: }
38: statementHolder.analyzeStatement();
39: }
40:
41: @Override
42: public ResultSet executeQuery() throws OntoDriverException {
43: ensureOpen();
44: closeExistingResultSet();
45: this.resultSet = getExecutor().executeQuery(statementHolder.assembleStatement(), this);
46: return resultSet;
47: }
48:
49: @Override
50: public void executeUpdate() throws OntoDriverException {
51: ensureOpen();
52: getExecutor().executeUpdate(statementHolder.assembleStatement());
53: connection.commitIfAuto();
54: }
55:
56: @Override
57: public void setObject(String binding, Object value) {
58: ensureOpen();
59: Objects.requireNonNull(binding, getNPXMessageSupplier("binding"));
60: Objects.requireNonNull(value, getNPXMessageSupplier("value"));
61: statementHolder.setParameter(binding, value.toString());
62: }
63:
64: @Override
65: public void clearParameters() {
66: ensureOpen();
67: statementHolder.clearParameters();
68: }
69: }