Skip to content

Package: ResultRow

ResultRow

Coverage

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