public T getObject()

in src/main/java/org/mariadb/jdbc/internal/com/read/resultset/SelectResultSet.java [1181:1310]


  public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
    if (type == null) {
      throw new SQLException("Class type cannot be null");
    }
    checkObjectRange(columnIndex);
    if (row.lastValueWasNull()) {
      return null;
    }
    ColumnDefinition col = columnsInformation[columnIndex - 1];

    if (type.equals(String.class)) {
      return (T) row.getInternalString(col, null, timeZone);

    } else if (type.equals(Integer.class)) {
      return (T) (Integer) row.getInternalInt(col);

    } else if (type.equals(Long.class)) {
      return (T) (Long) row.getInternalLong(col);

    } else if (type.equals(Short.class)) {
      return (T) (Short) row.getInternalShort(col);

    } else if (type.equals(Double.class)) {
      return (T) (Double) row.getInternalDouble(col);

    } else if (type.equals(Float.class)) {
      return (T) (Float) row.getInternalFloat(col);

    } else if (type.equals(Byte.class)) {
      return (T) (Byte) row.getInternalByte(col);

    } else if (type.equals(byte[].class)) {
      byte[] data = new byte[row.getLengthMaxFieldSize()];
      System.arraycopy(row.buf, row.pos, data, 0, row.getLengthMaxFieldSize());
      return (T) data;

    } else if (type.equals(Date.class) || type.equals(java.util.Date.class)) {
      return (T) row.getInternalDate(col, null, timeZone);

    } else if (type.equals(Time.class)) {
      return (T) row.getInternalTime(col, null, timeZone);

    } else if (type.equals(Timestamp.class) || type.equals(java.util.Date.class)) {
      return (T) row.getInternalTimestamp(col, null, timeZone);

    } else if (type.equals(Boolean.class)) {
      return (T) (Boolean) row.getInternalBoolean(col);

    } else if (type.equals(Calendar.class)) {
      Calendar calendar =
          timeZone == null ? Calendar.getInstance() : Calendar.getInstance(timeZone);
      Timestamp timestamp = row.getInternalTimestamp(col, null, timeZone);
      if (timestamp == null) {
        return null;
      }
      calendar.setTimeInMillis(timestamp.getTime());
      return type.cast(calendar);

    } else if (type.equals(Clob.class) || type.equals(NClob.class)) {
      return (T) new MariaDbClob(row.buf, row.pos, row.getLengthMaxFieldSize());

    } else if (type.equals(InputStream.class)) {
      return (T) new ByteArrayInputStream(row.buf, row.pos, row.getLengthMaxFieldSize());

    } else if (type.equals(Reader.class)) {
      String value = row.getInternalString(col, null, timeZone);
      if (value == null) {
        return null;
      }
      return (T) new StringReader(value);

    } else if (type.equals(BigDecimal.class)) {
      return (T) row.getInternalBigDecimal(col);

    } else if (type.equals(BigInteger.class)) {
      return (T) row.getInternalBigInteger(col);
    } else if (type.equals(BigDecimal.class)) {
      return (T) row.getInternalBigDecimal(col);

    } else if (type.equals(LocalDateTime.class)) {
      ZonedDateTime zonedDateTime =
          row.getInternalZonedDateTime(col, LocalDateTime.class, timeZone);
      return zonedDateTime == null
          ? null
          : type.cast(zonedDateTime.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime());

    } else if (type.equals(ZonedDateTime.class)) {
      ZonedDateTime zonedDateTime =
          row.getInternalZonedDateTime(col, ZonedDateTime.class, timeZone);
      if (zonedDateTime == null) {
        return null;
      }
      return type.cast(row.getInternalZonedDateTime(col, ZonedDateTime.class, timeZone));

    } else if (type.equals(OffsetDateTime.class)) {
      ZonedDateTime tmpZonedDateTime =
          row.getInternalZonedDateTime(col, OffsetDateTime.class, timeZone);
      return tmpZonedDateTime == null ? null : type.cast(tmpZonedDateTime.toOffsetDateTime());

    } else if (type.equals(OffsetDateTime.class)) {
      LocalDate localDate = row.getInternalLocalDate(col, timeZone);
      if (localDate == null) {
        return null;
      }
      return type.cast(localDate);

    } else if (type.equals(LocalDate.class)) {
      LocalDate localDate = row.getInternalLocalDate(col, timeZone);
      if (localDate == null) {
        return null;
      }
      return type.cast(localDate);

    } else if (type.equals(LocalTime.class)) {
      LocalTime localTime = row.getInternalLocalTime(col, timeZone);
      if (localTime == null) {
        return null;
      }
      return type.cast(localTime);

    } else if (type.equals(OffsetTime.class)) {
      OffsetTime offsetTime = row.getInternalOffsetTime(col, timeZone);
      if (offsetTime == null) {
        return null;
      }
      return type.cast(offsetTime);
    }
    throw ExceptionFactory.INSTANCE.notSupported(
        "Type class '" + type.getName() + "' is not supported");
  }