Skip to content

Package: AskResultSet

AskResultSet

nameinstructionbranchcomplexitylinemethod
AskResultSet(boolean, Statement)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
ensureState()
M: 5 C: 6
55%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
findColumn(String)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getBoolean(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getBoolean(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getByte(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getByte(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getColumnCount()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDouble(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getDouble(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getFloat(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getFloat(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getInt(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getInt(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getLong(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getLong(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getObject(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getObject(String, Class)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getObject(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getObject(int, Class)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getShort(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getShort(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getString(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getString(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
hasNext()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
isBound(String)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isBound(int)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toType(Class)
M: 22 C: 10
31%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 3 C: 2
40%
M: 0 C: 1
100%
unsupported(String)
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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.ontodriver.rdf4j.query;
16:
17: import cz.cvut.kbss.ontodriver.Statement;
18: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
19: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
20:
21: public class AskResultSet extends AbstractResultSet {
22:
23: private final boolean result;
24:
25: public AskResultSet(boolean result, Statement statement) {
26: super(statement);
27: this.result = result;
28: }
29:
30: @Override
31: public int findColumn(String columnLabel) {
32: return 0;
33: }
34:
35: @Override
36: public int getColumnCount() {
37: return 1;
38: }
39:
40: @Override
41: public boolean isBound(int variableIndex) {
42: // Return always true, as we do not care about index/name for ASK results
43: return true;
44: }
45:
46: @Override
47: public boolean isBound(String variableName) {
48: // Return always true, as we do not care about index/name for ASK results
49: return true;
50: }
51:
52: // We discard column index and column name, because in a boolean result, there is no such concept. Therefore,
53: // the result is returned for any column index and column name.
54:
55: @Override
56: public boolean getBoolean(int columnIndex) {
57: ensureState();
58: return result;
59: }
60:
61: private void ensureState() {
62: ensureOpen();
63:• if (!isFirst()) {
64: throw new IllegalStateException("Must call next before getting the first value.");
65: }
66: }
67:
68: @Override
69: public boolean getBoolean(String columnLabel) {
70: ensureState();
71: return result;
72: }
73:
74: @Override
75: public byte getByte(int columnIndex) {
76: ensureState();
77: throw unsupported("byte");
78: }
79:
80: private static UnsupportedOperationException unsupported(String type) {
81: return new UnsupportedOperationException("ASK query results cannot return " + type + "values.");
82: }
83:
84: @Override
85: public byte getByte(String columnLabel) {
86: ensureState();
87: throw unsupported("byte");
88: }
89:
90: @Override
91: public double getDouble(int columnIndex) {
92: ensureState();
93: throw unsupported("double");
94: }
95:
96: @Override
97: public double getDouble(String columnLabel) {
98: ensureState();
99: throw unsupported("double");
100: }
101:
102: @Override
103: public float getFloat(int columnIndex) {
104: ensureState();
105: throw unsupported("float");
106: }
107:
108: @Override
109: public float getFloat(String columnLabel) {
110: ensureState();
111: throw unsupported("float");
112: }
113:
114: @Override
115: public int getInt(int columnIndex) {
116: ensureState();
117: throw unsupported("int");
118: }
119:
120: @Override
121: public int getInt(String columnLabel) {
122: ensureState();
123: throw unsupported("int");
124: }
125:
126: @Override
127: public long getLong(int columnIndex) {
128: ensureState();
129: throw unsupported("long");
130: }
131:
132: @Override
133: public long getLong(String columnLabel) {
134: ensureState();
135: throw unsupported("long");
136: }
137:
138: @Override
139: public Object getObject(int columnIndex) {
140: ensureState();
141: return result;
142: }
143:
144: @Override
145: public Object getObject(String columnLabel) {
146: ensureState();
147: return result;
148: }
149:
150: @Override
151: public <T> T getObject(int columnIndex, Class<T> cls) throws OntoDriverException {
152: ensureState();
153: return toType(cls);
154: }
155:
156: @Override
157: public <T> T getObject(String columnLabel, Class<T> cls) throws OntoDriverException {
158: ensureState();
159: return toType(cls);
160: }
161:
162: private <T> T toType(Class<T> type) throws Rdf4jDriverException {
163:• if (type.isAssignableFrom(Boolean.class)) {
164: return type.cast(result);
165: }
166:• if (type.isAssignableFrom(String.class)) {
167: return type.cast(getString(0));
168: }
169: throw new Rdf4jDriverException("Unable to return boolean result as type " + type);
170: }
171:
172: @Override
173: public short getShort(int columnIndex) {
174: ensureState();
175: throw unsupported("short");
176: }
177:
178: @Override
179: public short getShort(String columnLabel) {
180: ensureState();
181: throw unsupported("short");
182: }
183:
184: @Override
185: public String getString(int columnIndex) {
186: ensureState();
187: return Boolean.toString(result);
188: }
189:
190: @Override
191: public String getString(String columnLabel) {
192: ensureState();
193: return Boolean.toString(result);
194: }
195:
196: @Override
197: public boolean hasNext() throws OntoDriverException {
198: ensureOpen();
199:• return !isFirst();
200: }
201: }