package com.bonus.canteen.core.nutrition.handler;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DoubleTwoHandler extends BaseTypeHandler<Double> {
   public void setNonNullParameter(PreparedStatement ps, int i, Double parameter, JdbcType jdbcType) throws SQLException {
      ps.setDouble(i, parameter);
   }

   public Double getNullableResult(ResultSet rs, String columnName) throws SQLException {
      return BigDecimal.valueOf(rs.getDouble(columnName)).doubleValue();
   }

   public Double getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
      return rs.getDouble(columnIndex);
   }

   public Double getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
      return cs.getDouble(columnIndex);
   }
}
