Package: AskResultSet
AskResultSet
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AskResultSet(boolean, Statement) |
|
|
|
|
|
||||||||||||||||||||
ensureState() |
|
|
|
|
|
||||||||||||||||||||
findColumn(String) |
|
|
|
|
|
||||||||||||||||||||
getBoolean(String) |
|
|
|
|
|
||||||||||||||||||||
getBoolean(int) |
|
|
|
|
|
||||||||||||||||||||
getByte(String) |
|
|
|
|
|
||||||||||||||||||||
getByte(int) |
|
|
|
|
|
||||||||||||||||||||
getColumnCount() |
|
|
|
|
|
||||||||||||||||||||
getDouble(String) |
|
|
|
|
|
||||||||||||||||||||
getDouble(int) |
|
|
|
|
|
||||||||||||||||||||
getFloat(String) |
|
|
|
|
|
||||||||||||||||||||
getFloat(int) |
|
|
|
|
|
||||||||||||||||||||
getInt(String) |
|
|
|
|
|
||||||||||||||||||||
getInt(int) |
|
|
|
|
|
||||||||||||||||||||
getLong(String) |
|
|
|
|
|
||||||||||||||||||||
getLong(int) |
|
|
|
|
|
||||||||||||||||||||
getObject(String) |
|
|
|
|
|
||||||||||||||||||||
getObject(String, Class) |
|
|
|
|
|
||||||||||||||||||||
getObject(int) |
|
|
|
|
|
||||||||||||||||||||
getObject(int, Class) |
|
|
|
|
|
||||||||||||||||||||
getShort(String) |
|
|
|
|
|
||||||||||||||||||||
getShort(int) |
|
|
|
|
|
||||||||||||||||||||
getString(String) |
|
|
|
|
|
||||||||||||||||||||
getString(int) |
|
|
|
|
|
||||||||||||||||||||
hasNext() |
|
|
|
|
|
||||||||||||||||||||
isBound(String) |
|
|
|
|
|
||||||||||||||||||||
isBound(int) |
|
|
|
|
|
||||||||||||||||||||
toType(Class) |
|
|
|
|
|
||||||||||||||||||||
unsupported(String) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2020 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: @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) throws OntoDriverException {
57: ensureState();
58: return result;
59: }
60:
61: private void ensureState() throws OntoDriverException {
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) throws OntoDriverException {
70: ensureState();
71: return result;
72: }
73:
74: @Override
75: public byte getByte(int columnIndex) throws OntoDriverException {
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) throws OntoDriverException {
86: ensureState();
87: throw unsupported("byte");
88: }
89:
90: @Override
91: public double getDouble(int columnIndex) throws OntoDriverException {
92: ensureState();
93: throw unsupported("double");
94: }
95:
96: @Override
97: public double getDouble(String columnLabel) throws OntoDriverException {
98: ensureState();
99: throw unsupported("double");
100: }
101:
102: @Override
103: public float getFloat(int columnIndex) throws OntoDriverException {
104: ensureState();
105: throw unsupported("float");
106: }
107:
108: @Override
109: public float getFloat(String columnLabel) throws OntoDriverException {
110: ensureState();
111: throw unsupported("float");
112: }
113:
114: @Override
115: public int getInt(int columnIndex) throws OntoDriverException {
116: ensureState();
117: throw unsupported("int");
118: }
119:
120: @Override
121: public int getInt(String columnLabel) throws OntoDriverException {
122: ensureState();
123: throw unsupported("int");
124: }
125:
126: @Override
127: public long getLong(int columnIndex) throws OntoDriverException {
128: ensureState();
129: throw unsupported("long");
130: }
131:
132: @Override
133: public long getLong(String columnLabel) throws OntoDriverException {
134: ensureState();
135: throw unsupported("long");
136: }
137:
138: @Override
139: public Object getObject(int columnIndex) throws OntoDriverException {
140: ensureState();
141: return result;
142: }
143:
144: @Override
145: public Object getObject(String columnLabel) throws OntoDriverException {
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 OntoDriverException {
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 SesameDriverException("Unable to return boolean result as type " + type);
170: }
171:
172: @Override
173: public short getShort(int columnIndex) throws OntoDriverException {
174: ensureState();
175: throw unsupported("short");
176: }
177:
178: @Override
179: public short getShort(String columnLabel) throws OntoDriverException {
180: ensureState();
181: throw unsupported("short");
182: }
183:
184: @Override
185: public String getString(int columnIndex) throws OntoDriverException {
186: ensureState();
187: return Boolean.toString(result);
188: }
189:
190: @Override
191: public String getString(String columnLabel) throws OntoDriverException {
192: ensureState();
193: return Boolean.toString(result);
194: }
195:
196: @Override
197: public boolean hasNext() throws OntoDriverException {
198: ensureOpen();
199:• return !isFirst();
200: }
201: }