11package tech .ydb .jdbc .context ;
22
3+ import java .sql .ResultSet ;
34import java .sql .SQLException ;
5+ import java .sql .SQLFeatureNotSupportedException ;
46import java .sql .Statement ;
57import java .util .ArrayList ;
68import java .util .Arrays ;
@@ -276,11 +278,11 @@ public void addResultSet(ResultSetReader rsr) throws InterruptedException {
276278
277279 @ Override
278280 protected ValueReader getValue (int columnIndex ) throws SQLException {
279- try {
280- return current .getColumn (columnIndex );
281- } catch (IllegalStateException ex ) {
281+ if (current == null ) {
282282 throw new SQLException (YdbConst .INVALID_ROW + rowIndex );
283283 }
284+
285+ return current .getColumn (columnIndex );
284286 }
285287
286288 @ Override
@@ -296,6 +298,10 @@ public boolean next() throws SQLException {
296298 }
297299
298300 if (isCompleted && readers .isEmpty ()) {
301+ current = null ;
302+ if (rowsCount .get () > 0 ) {
303+ rowIndex = rowsCount .intValue () + 1 ;
304+ }
299305 return false ;
300306 }
301307
@@ -337,67 +343,69 @@ public boolean isClosed() throws SQLException {
337343
338344 @ Override
339345 public boolean isBeforeFirst () throws SQLException {
340- throw new SQLException ( YdbConst . FORWARD_ONLY_MODE ) ;
346+ return rowsCount . get () > 0 && rowIndex < 1 ;
341347 }
342348
343349 @ Override
344350 public boolean isAfterLast () throws SQLException {
345- throw new SQLException ( YdbConst . FORWARD_ONLY_MODE );
351+ return isCompleted && rowsCount . get () > 0 && rowIndex > rowsCount . intValue ( );
346352 }
347353
348354 @ Override
349355 public boolean isFirst () throws SQLException {
350- throw new SQLException ( YdbConst . FORWARD_ONLY_MODE ) ;
356+ return rowIndex == 1 ;
351357 }
352358
353359 @ Override
354360 public boolean isLast () throws SQLException {
355- throw new SQLException ( YdbConst . FORWARD_ONLY_MODE );
361+ return isCompleted && rowsCount . get () > 0 && rowIndex == rowsCount . intValue ( );
356362 }
357363
358364 @ Override
359365 public void beforeFirst () throws SQLException {
360- throw new SQLException (YdbConst .FORWARD_ONLY_MODE );
366+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
361367 }
362368
363369 @ Override
364370 public void afterLast () throws SQLException {
365- throw new SQLException (YdbConst .FORWARD_ONLY_MODE );
371+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
366372 }
367373
368374 @ Override
369375 public boolean first () throws SQLException {
370- throw new SQLException (YdbConst .FORWARD_ONLY_MODE );
376+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
371377 }
372378
373379 @ Override
374380 public boolean last () throws SQLException {
375- throw new SQLException (YdbConst .FORWARD_ONLY_MODE );
381+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
376382 }
377383
378384 @ Override
379385 public boolean absolute (int row ) throws SQLException {
380- throw new SQLException (YdbConst .FORWARD_ONLY_MODE );
386+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
381387 }
382388
383389 @ Override
384390 public boolean relative (int rows ) throws SQLException {
385- throw new SQLException (YdbConst .FORWARD_ONLY_MODE );
391+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
386392 }
387393
388394 @ Override
389395 public boolean previous () throws SQLException {
390- throw new SQLException (YdbConst .FORWARD_ONLY_MODE );
396+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
391397 }
392398
393399 @ Override
394400 public void setFetchDirection (int direction ) throws SQLException {
395- throw new UnsupportedOperationException ("Not supported yet." );
401+ if (direction != ResultSet .FETCH_FORWARD ) {
402+ throw new SQLFeatureNotSupportedException (YdbConst .FORWARD_ONLY_MODE );
403+ }
396404 }
397405
398406 @ Override
399407 public int getFetchDirection () throws SQLException {
400- throw new UnsupportedOperationException ( "Not supported yet." ) ;
408+ return ResultSet . FETCH_FORWARD ;
401409 }
402410 }
403411}
0 commit comments