Skip to contentPackage: ResultRow
ResultRow
Coverage
1: /**
2: * Copyright (C) 2023 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.iteration;
16:
17: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
18:
19: /**
20: * Represents a single row in a {@link cz.cvut.kbss.ontodriver.ResultSet}.
21: * <p>
22: * This interface replicates the value retrieval API of {@code ResultSet} and serves as a view of the current row in a result set.
23: * <p>
24: * The main purpose of this interface is to support iteration over result sets.
25: */
26: public interface ResultRow {
27:
28: /**
29: * Retrieves index of a column with the specified label.
30: *
31: * @param columnLabel Label of the column
32: * @return index of the column or -1 if there is no such column
33: * @throws IllegalStateException If called on a closed result set
34: */
35: int findColumn(String columnLabel);
36:
37: /**
38: * Gets the count of available columns.
39: * <p>
40: * This number corresponds to the number of result variables bound in the query.
41: *
42: * @return Number of columns in the result set
43: * @throws IllegalStateException If called on a closed result set
44: */
45: int getColumnCount();
46:
47: /**
48: * Checks whether a value at the specified index is bound in the current result row.
49: * <p>
50: * Note that this method will return {@code false} also in case the index is out of range of the variables known to
51: * the result set as a whole.
52: *
53: * @param variableIndex Index of the variable
54: * @return {@code true} when value is bound in the current row, {@code false} otherwise
55: * @throws IllegalStateException If called on a closed result set
56: * @throws OntoDriverException When unable to resolve binding status
57: */
58: boolean isBound(int variableIndex) throws OntoDriverException;
59:
60: /**
61: * Checks whether a value of the specified variable is bound in the current result row.
62: * <p>
63: * Note that this method will return {@code false} also in case the variable is not known to the result set at all.
64: *
65: * @param variableName Variable name
66: * @return {@code true} when value is bound in the current row, {@code false} otherwise
67: * @throws IllegalStateException If called on a closed result set
68: * @throws OntoDriverException When unable to resolve binding status
69: */
70: boolean isBound(String variableName) throws OntoDriverException;
71:
72: /**
73: * Retrieves value from column at the specified index and returns it as a {@code boolean}.
74: *
75: * @param columnIndex Column index, the first column has index 0
76: * @return {@code boolean} value
77: * @throws IllegalStateException If called on a closed result set
78: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
79: * {@code boolean} or there occurs some other error
80: */
81: boolean getBoolean(int columnIndex) throws OntoDriverException;
82:
83: /**
84: * Retrieves value from column with the specified label and returns it as a {@code boolean}.
85: *
86: * @param columnLabel Label of the column
87: * @return {@code boolean} value
88: * @throws IllegalStateException If called on a closed result set
89: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
90: * boolean} or there occurs some other error
91: */
92: boolean getBoolean(String columnLabel) throws OntoDriverException;
93:
94: /**
95: * Retrieves value from column at the specified index and returns it as {@code byte}.
96: *
97: * @param columnIndex Column index, the first column has index 0
98: * @return {@code byte} value
99: * @throws IllegalStateException If called on a closed result set
100: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
101: * {@code byte} or there occurs some other error
102: */
103: byte getByte(int columnIndex) throws OntoDriverException;
104:
105: /**
106: * Retrieves value from column with the specified label and returns it as {@code byte}.
107: *
108: * @param columnLabel Label of the column
109: * @return {@code byte} value
110: * @throws IllegalStateException If called on a closed result set
111: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
112: * byte} or there occurs some other error
113: */
114: byte getByte(String columnLabel) throws OntoDriverException;
115:
116: /**
117: * Retrieves value from column at the specified index and returns it as {@code double}.
118: *
119: * @param columnIndex Column index, the first column has index 0
120: * @return {@code double} value
121: * @throws IllegalStateException If called on a closed result set
122: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
123: * {@code double} or there occurs some other error
124: */
125: double getDouble(int columnIndex) throws OntoDriverException;
126:
127: /**
128: * Retrieves value from column with the specified label and returns it as {@code double}.
129: *
130: * @param columnLabel Label of the column
131: * @return {@code double} value
132: * @throws IllegalStateException If called on a closed result set
133: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
134: * double} or there occurs some other error
135: */
136: double getDouble(String columnLabel) throws OntoDriverException;
137:
138: /**
139: * Retrieves value from column at the specified index and returns it as {@code float}.
140: *
141: * @param columnIndex Column index, the first column has index 0
142: * @return {@code float} value
143: * @throws IllegalStateException If called on a closed result set
144: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
145: * {@code float} or there occurs some other error
146: */
147: float getFloat(int columnIndex) throws OntoDriverException;
148:
149: /**
150: * Retrieves value from column with the specified label and returns it as {@code float}.
151: *
152: * @param columnLabel Label of the column
153: * @return {@code float} value
154: * @throws IllegalStateException If called on a closed result set
155: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
156: * float} or there occurs some other error
157: */
158: float getFloat(String columnLabel) throws OntoDriverException;
159:
160: /**
161: * Retrieves value from column at the specified index and returns it as {@code int}.
162: *
163: * @param columnIndex Column index, the first column has index 0
164: * @return {@code int} value
165: * @throws IllegalStateException If called on a closed result set
166: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
167: * {@code int} or there occurs some other error
168: */
169: int getInt(int columnIndex) throws OntoDriverException;
170:
171: /**
172: * Retrieves value from column with the specified label and returns it as {@code int}.
173: *
174: * @param columnLabel Label of the column
175: * @return {@code int} value
176: * @throws IllegalStateException If called on a closed result set
177: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
178: * int} or there occurs some other error
179: */
180: int getInt(String columnLabel) throws OntoDriverException;
181:
182: /**
183: * Retrieves value from column at the specified index and returns it as {@code long}.
184: *
185: * @param columnIndex Column index, the first column has index 0
186: * @return {@code long} value
187: * @throws IllegalStateException If called on a closed result set
188: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
189: * {@code long} or there occurs some other error
190: */
191: long getLong(int columnIndex) throws OntoDriverException;
192:
193: /**
194: * Retrieves value from column with the specified label and returns it as {@code long}.
195: *
196: * @param columnLabel Label of the column
197: * @return {@code long} value
198: * @throws IllegalStateException If called on a closed result set
199: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
200: * long} or there occurs some other error
201: */
202: long getLong(String columnLabel) throws OntoDriverException;
203:
204: /**
205: * Retrieves value from column at the specified index and returns it as {@code Object}.
206: *
207: * @param columnIndex Column index, the first column has index 0
208: * @return column value cast to {@code Object}
209: * @throws IllegalStateException If called on a closed result set
210: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index or there occurs some other
211: * error
212: */
213: Object getObject(int columnIndex) throws OntoDriverException;
214:
215: /**
216: * Retrieves value from column with the specified label and returns it as {@code Object}.
217: *
218: * @param columnLabel Label of the column
219: * @return column value cast to {@code Object}
220: * @throws IllegalStateException If called on a closed result set
221: * @throws OntoDriverException If there is no column with the specified label or there occurs some other error
222: */
223: Object getObject(String columnLabel) throws OntoDriverException;
224:
225: /**
226: * Retrieves value from column at the specified index and returns it as an instance of the specified class.
227: * <p>
228: * The mechanism of transforming the value to the specified class is not specified, it can be merely type casting or
229: * calling a constructor of the specified type.
230: *
231: * @param columnIndex Column index, the first column has index 0
232: * @param cls Requested class type
233: * @param <T> Return type
234: * @return Value of the column
235: * @throws IllegalStateException If called on a closed result set
236: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
237: * the specified type or there occurs some other error
238: */
239: <T> T getObject(int columnIndex, Class<T> cls) throws OntoDriverException;
240:
241: /**
242: * Retrieves value from column with the specified label and returns it as an instance of the specified class.
243: * <p>
244: * The mechanism of transforming the value to the specified class is not specified, it can be merely type casting or
245: * calling a constructor of the specified type.
246: *
247: * @param columnLabel Label of the column
248: * @param cls Requested class type
249: * @param <T> Return type
250: * @return Value of the column.
251: * @throws IllegalStateException If called on a closed result set
252: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to the
253: * specified type or there occurs some other error
254: */
255: <T> T getObject(String columnLabel, Class<T> cls) throws OntoDriverException;
256:
257: /**
258: * Retrieves value of column at the specified index and returns it as {@code short}.
259: *
260: * @param columnIndex Column index, the first column has index 0
261: * @return {@code short} value
262: * @throws IllegalStateException If called on a closed result set
263: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
264: * {@code short} or there occurs some other error
265: */
266: short getShort(int columnIndex) throws OntoDriverException;
267:
268: /**
269: * Retrieves value of column with the specified label and returns it as {@code short}.
270: *
271: * @param columnLabel Label of the column
272: * @return {@code short} value
273: * @throws IllegalStateException If called on a closed result set
274: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
275: * short} or there occurs some other error
276: */
277: short getShort(String columnLabel) throws OntoDriverException;
278:
279: /**
280: * Retrieves value of column at the specified index and returns it as {@code String}.
281: *
282: * @param columnIndex Column index, the first column has index 0
283: * @return {@code String} value
284: * @throws IllegalStateException If called on a closed result set
285: * @throws OntoDriverException If the {@code columnIndex} is not a valid column index, the value cannot be cast to
286: * {@code String} or there occurs some other error
287: */
288: String getString(int columnIndex) throws OntoDriverException;
289:
290: /**
291: * Retrieves value of column with the specified label and returns it as {@code String}.
292: *
293: * @param columnLabel Label of the column
294: * @return {@code String} value
295: * @throws IllegalStateException If called on a closed result set
296: * @throws OntoDriverException If there is no column with the specified label, the value cannot be cast to {@code
297: * String} or there occurs some other error
298: */
299: String getString(String columnLabel) throws OntoDriverException;
300:
301:
302: /**
303: * Gets the index of this row (first row has index 0).
304: *
305: * @return Index of this row
306: * @throws IllegalStateException If called on a closed result set
307: * @throws OntoDriverException If some other error occurs
308: */
309: int getIndex() throws OntoDriverException;
310: }