package com.zhyc.module.feed.mapper.TypeHandler;

import com.alibaba.fastjson2.JSON;
import com.zhyc.module.base.domain.DaSheepfold;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@MappedTypes(List.class)
public class DaSheepfoldHandler extends BaseTypeHandler<List<DaSheepfold>> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i,
                                    List<DaSheepfold> parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, JSON.toJSONString(parameter));
    }

    @Override
    public List<DaSheepfold> getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return JSON.parseArray(rs.getString(columnName), DaSheepfold.class);
    }

    @Override
    public List<DaSheepfold> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return JSON.parseArray(rs.getString(columnIndex), DaSheepfold.class);
    }

    @Override
    public List<DaSheepfold> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return JSON.parseArray(cs.getString(columnIndex), DaSheepfold.class);
    }
}

