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