All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.db.ResultResultSet Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 Objectos, Fábrica de Software LTDA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package br.com.objectos.db;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.stream.Stream;

/**
 * @author [email protected] (Marcio Endo)
 */
class ResultResultSet implements Result {

  private final ResultSet rs;

  public ResultResultSet(ResultSet rs) {
    this.rs = rs;
  }

  @Override
  public boolean booleanValue(int index) {
    try {
      return rs.getBoolean(index);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public boolean booleanValue(String columnName) {
    try {
      return rs.getBoolean(columnName);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public void close() {
    try {
      rs.close();
    } catch (SQLException e) {

    }
  }

  @Override
  public double doubleValue(int index) {
    try {
      return rs.getDouble(index);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public float floatValue(int index) {
    try {
      return rs.getFloat(index);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public int intValue(int index) {
    try {
      return rs.getInt(index);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public int intValue(String columnName) {
    try {
      return rs.getInt(columnName);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public java.time.LocalDate localDate(int index) {
    try {
      Date date = rs.getDate(index);
      return date != null ? date.toLocalDate() : null;
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public LocalDateTime localDateTime(int index) {
    try {
      Timestamp timestamp = rs.getTimestamp(index);
      return timestamp != null ? timestamp.toLocalDateTime() : null;
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public long longValue(int index) {
    try {
      return rs.getLong(index);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public long longValue(String columnName) {
    try {
      return rs.getLong(columnName);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public String string(int index) {
    try {
      return rs.getString(index);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public String string(String columnName) {
    try {
      return rs.getString(columnName);
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public boolean next() {
    try {
      return rs.next();
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

  @Override
  public Stream stream() {
    return Results.stream(this);
  }

  @Override
  public boolean wasNull() {
    try {
      return rs.wasNull();
    } catch (SQLException e) {
      throw SqlRuntimeException.wrap(e);
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy