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: 6 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: 6 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: 6 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: 6 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: 6 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: 6 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: 6 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: 6 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: 6 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: 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)
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: 6 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: 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(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%
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) 2016 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.ontodriver.sesame.query;
14:
15: import cz.cvut.kbss.ontodriver.Statement;
16: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
17: import cz.cvut.kbss.ontodriver.sesame.exceptions.SesameDriverException;
18:
19: public class AskResultSet extends AbstractResultSet {
20:
21: private final boolean result;
22:
23: public AskResultSet(boolean result, Statement statement) {
24: super(statement);
25: this.result = result;
26: }
27:
28: @Override
29: public int findColumn(String columnLabel) {
30: return 0;
31: }
32:
33: @Override
34: public int getColumnCount() {
35: return 1;
36: }
37:
38: // We discard column index and column name, because in a boolean result, there is no such concept. Therefore,
39: // the result is returned for any column index and column name.
40:
41: @Override
42: public boolean getBoolean(int columnIndex) throws OntoDriverException {
43: ensureState();
44: return result;
45: }
46:
47: private void ensureState() throws OntoDriverException {
48: ensureOpen();
49:• if (!isFirst()) {
50: throw new IllegalStateException("Must call next before getting the first value.");
51: }
52: }
53:
54: @Override
55: public boolean getBoolean(String columnLabel) throws OntoDriverException {
56: ensureState();
57: return result;
58: }
59:
60: @Override
61: public byte getByte(int columnIndex) throws OntoDriverException {
62: ensureState();
63: throw unsupported("byte");
64: }
65:
66: private UnsupportedOperationException unsupported(String type) {
67: return new UnsupportedOperationException("ASK query results cannot return " + type + "values.");
68: }
69:
70: @Override
71: public byte getByte(String columnLabel) throws OntoDriverException {
72: ensureState();
73: throw unsupported("byte");
74: }
75:
76: @Override
77: public double getDouble(int columnIndex) throws OntoDriverException {
78: ensureState();
79: throw unsupported("double");
80: }
81:
82: @Override
83: public double getDouble(String columnLabel) throws OntoDriverException {
84: ensureState();
85: throw unsupported("double");
86: }
87:
88: @Override
89: public float getFloat(int columnIndex) throws OntoDriverException {
90: ensureState();
91: throw unsupported("float");
92: }
93:
94: @Override
95: public float getFloat(String columnLabel) throws OntoDriverException {
96: ensureState();
97: throw unsupported("float");
98: }
99:
100: @Override
101: public int getInt(int columnIndex) throws OntoDriverException {
102: ensureState();
103: throw unsupported("int");
104: }
105:
106: @Override
107: public int getInt(String columnLabel) throws OntoDriverException {
108: ensureState();
109: throw unsupported("int");
110: }
111:
112: @Override
113: public long getLong(int columnIndex) throws OntoDriverException {
114: ensureState();
115: throw unsupported("long");
116: }
117:
118: @Override
119: public long getLong(String columnLabel) throws OntoDriverException {
120: ensureState();
121: throw unsupported("long");
122: }
123:
124: @Override
125: public Object getObject(int columnIndex) throws OntoDriverException {
126: ensureState();
127: return result;
128: }
129:
130: @Override
131: public Object getObject(String columnLabel) throws OntoDriverException {
132: ensureState();
133: return result;
134: }
135:
136: @Override
137: public <T> T getObject(int columnIndex, Class<T> cls) throws OntoDriverException {
138: ensureState();
139: return toType(cls);
140: }
141:
142: @Override
143: public <T> T getObject(String columnLabel, Class<T> cls) throws OntoDriverException {
144: ensureState();
145: return toType(cls);
146: }
147:
148: private <T> T toType(Class<T> type) throws OntoDriverException {
149:• if (type.isAssignableFrom(Boolean.class)) {
150: return type.cast(result);
151: }
152:• if (type.isAssignableFrom(String.class)) {
153: return type.cast(getString(0));
154: }
155: throw new SesameDriverException("Unable to return booelan result as type " + type);
156: }
157:
158: @Override
159: public short getShort(int columnIndex) throws OntoDriverException {
160: ensureState();
161: throw unsupported("short");
162: }
163:
164: @Override
165: public short getShort(String columnLabel) throws OntoDriverException {
166: ensureState();
167: throw unsupported("short");
168: }
169:
170: @Override
171: public String getString(int columnIndex) throws OntoDriverException {
172: ensureState();
173: return Boolean.toString(result);
174: }
175:
176: @Override
177: public String getString(String columnLabel) throws OntoDriverException {
178: ensureState();
179: return Boolean.toString(result);
180: }
181:
182: @Override
183: public boolean hasNext() throws OntoDriverException {
184: ensureOpen();
185:• return !isFirst();
186: }
187: }