1 19 package com.mysql.jdbc; 20 21 import java.io.IOException ; 22 23 import java.sql.SQLException ; 24 25 26 32 public class RowDataDynamic implements RowData { 33 private MysqlIO io; 34 private byte[][] nextRow; 35 private boolean isAfterEnd = false; 36 private boolean isAtEnd = false; 37 private boolean streamerClosed = false; 38 private int columnCount; 39 private int index = -1; 40 private long lastSuccessfulReadTimeMs = 0; 41 private long netWriteTimeoutMs = 0; 42 private ResultSet owner; 43 44 52 public RowDataDynamic(MysqlIO io, int colCount) throws SQLException { 53 this.io = io; 54 this.columnCount = colCount; 55 nextRecord(); 56 } 57 58 65 public boolean isAfterLast() throws SQLException { 66 return isAfterEnd; 67 } 68 69 78 public byte[][] getAt(int index) throws SQLException { 79 notSupported(); 80 81 return null; 82 } 83 84 91 public boolean isBeforeFirst() throws SQLException { 92 return index < 0; 93 } 94 95 102 public void setCurrentRow(int rowNumber) throws SQLException { 103 notSupported(); 104 } 105 106 109 public void setOwner(ResultSet rs) { 110 this.owner = rs; 111 } 112 113 116 public ResultSet getOwner() { 117 return this.owner; 118 } 119 120 127 public int getCurrentRowNumber() throws SQLException { 128 notSupported(); 129 130 return -1; 131 } 132 133 139 public boolean isDynamic() { 140 return true; 141 } 142 143 150 public boolean isEmpty() throws SQLException { 151 notSupported(); 152 153 return false; 154 } 155 156 163 public boolean isFirst() throws SQLException { 164 notSupported(); 165 166 return false; 167 } 168 169 176 public boolean isLast() throws SQLException { 177 notSupported(); 178 179 return false; 180 } 181 182 189 public void addRow(byte[][] row) throws SQLException { 190 notSupported(); 191 } 192 193 198 public void afterLast() throws SQLException { 199 notSupported(); 200 } 201 202 207 public void beforeFirst() throws SQLException { 208 notSupported(); 209 } 210 211 216 public void beforeLast() throws SQLException { 217 notSupported(); 218 } 219 220 225 public void close() throws SQLException { 226 int count = 0; 228 229 while (this.hasNext()) { 230 this.next(); 231 232 count++; 233 234 if (count == 100) { 235 Thread.yield(); 236 count = 0; 237 } 238 } 239 } 240 241 248 public boolean hasNext() throws SQLException { 249 boolean hasNext = (nextRow != null); 250 251 if (!hasNext && !streamerClosed) { 252 io.closeStreamer(this); 253 streamerClosed = true; 254 } 255 256 return hasNext; 257 } 258 259 266 public void moveRowRelative(int rows) throws SQLException { 267 notSupported(); 268 } 269 270 277 public byte[][] next() throws SQLException { 278 index++; 279 280 byte[][] ret = nextRow; 281 nextRecord(); 282 283 return ret; 284 } 285 286 293 public void removeRow(int index) throws SQLException { 294 notSupported(); 295 } 296 297 302 public int size() { 303 return RESULT_SET_SIZE_UNKNOWN; 304 } 305 306 private void nextRecord() throws SQLException { 307 try { 308 if (!isAtEnd) { 309 nextRow = io.nextRow((int) columnCount); 310 311 if (nextRow == null) { 312 isAtEnd = true; 313 } 314 315 this.lastSuccessfulReadTimeMs = System.currentTimeMillis(); 316 } else { 317 isAfterEnd = true; 318 } 319 } catch (SQLException sqlEx) { 320 throw sqlEx; 322 } catch (IOException ioEx) { 323 long timeSinceLastReadMs = System.currentTimeMillis() - this.lastSuccessfulReadTimeMs; 324 325 String exceptionType = ioEx.getClass().getName(); 326 String exceptionMessage = ioEx.getMessage(); 327 328 exceptionMessage += "\n\nNested Stack Trace:\n"; 329 exceptionMessage += Util.stackTraceToString(ioEx); 330 331 throw new java.sql.SQLException ( 332 "IOException while retrieving next record in streaming result set." 333 + "(Check for deadlock " 334 + " or retrieval exceeding 'net_write_timeout' seconds. Last " 335 + "successful record read was " + timeSinceLastReadMs + " ms ago, and" 336 + "'net_write_timeout' is configured in the server as " + this.netWriteTimeoutMs 337 + " ms.) : " 338 + exceptionType + " message given: " + exceptionMessage, SQLError.SQL_STATE_GENERAL_ERROR); 339 } catch (Exception ex) { 340 String exceptionType = ex.getClass().getName(); 341 String exceptionMessage = ex.getMessage(); 342 343 exceptionMessage += "\n\nNested Stack Trace:\n"; 344 exceptionMessage += Util.stackTraceToString(ex); 345 346 throw new java.sql.SQLException ( 347 "Error retrieving record: Unexpected Exception: " 348 + exceptionType + " message given: " + exceptionMessage, SQLError.SQL_STATE_GENERAL_ERROR); 349 } 350 } 351 352 private void notSupported() throws SQLException { 353 throw new OperationNotSupportedException(); 354 } 355 356 class OperationNotSupportedException extends SQLException { 357 OperationNotSupportedException() { 358 super("Operation not supported for streaming result sets", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 359 } 360 } 361 } 362 | Popular Tags |