@Override public boolean advanceNextPosition() { if (closed) { return false; } try { return resultSet.next(); } catch (SQLException | RuntimeException e) { throw handleSqlException(e); } }
@Override public boolean isNull(int field) { checkState(!closed, "cursor is closed"); checkArgument(field < columnHandles.length, "Invalid field index"); try { // JDBC is kind of dumb: we need to read the field and then ask // if it was null, which means we are wasting effort here. // We could save the result of the field access if it matters. resultSet.getObject(field + 1); return resultSet.wasNull(); } catch (SQLException | RuntimeException e) { throw handleSqlException(e); } }
@Override public Slice getSlice(int field) { checkState(!closed, "cursor is closed"); try { return sliceReadFunctions[field].readSlice(resultSet, field + 1); } catch (SQLException | RuntimeException e) { throw handleSqlException(e); } }
@Override public long getLong(int field) { checkState(!closed, "cursor is closed"); try { return longReadFunctions[field].readLong(resultSet, field + 1); } catch (SQLException | RuntimeException e) { throw handleSqlException(e); } }
@Override public double getDouble(int field) { checkState(!closed, "cursor is closed"); try { return doubleReadFunctions[field].readDouble(resultSet, field + 1); } catch (SQLException | RuntimeException e) { throw handleSqlException(e); } }
@Override public boolean getBoolean(int field) { checkState(!closed, "cursor is closed"); try { return booleanReadFunctions[field].readBoolean(resultSet, field + 1); } catch (SQLException | RuntimeException e) { throw handleSqlException(e); } }
@Override public boolean getBoolean(int field) { checkState(!closed, "cursor is closed"); try { return resultSet.getBoolean(field + 1); } catch (SQLException e) { throw handleSqlException(e); } }
@Override public double getDouble(int field) { checkState(!closed, "cursor is closed"); try { return resultSet.getDouble(field + 1); } catch (SQLException e) { throw handleSqlException(e); } }
@Override public boolean isNull(int field) { checkState(!closed, "cursor is closed"); checkArgument(field < columnHandles.size(), "Invalid field index"); try { // JDBC is kind of dumb: we need to read the field and then ask // if it was null, which means we are wasting effort here. // We could save the result of the field access if it matters. resultSet.getObject(field + 1); return resultSet.wasNull(); } catch (SQLException e) { throw handleSqlException(e); } }
@Override public boolean advanceNextPosition() { if (closed) { return false; } try { boolean result = resultSet.next(); if (!result) { close(); } return result; } catch (SQLException e) { throw handleSqlException(e); } }
public JdbcRecordCursor(JdbcClient jdbcClient, JdbcSplit split, List<JdbcColumnHandle> columnHandles) { this.columnHandles = ImmutableList.copyOf(requireNonNull(columnHandles, "columnHandles is null")); try { connection = jdbcClient.getConnection(split); statement = jdbcClient.buildSql(split, columnHandles); log.debug("Executing: %s", statement.toString()); resultSet = statement.executeQuery(); } catch (SQLException e) { throw handleSqlException(e); } }
@Override public Slice getSlice(int field) { checkState(!closed, "cursor is closed"); try { Type type = getType(field); if (type.equals(VarcharType.VARCHAR)) { return utf8Slice(resultSet.getString(field + 1)); } if (type.equals(VarbinaryType.VARBINARY)) { return wrappedBuffer(resultSet.getBytes(field + 1)); } throw new PrestoException(INTERNAL_ERROR, "Unhandled type for slice: " + type.getTypeSignature()); } catch (SQLException e) { throw handleSqlException(e); } }