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