Package in.partake.model.dao.postgres9

Source Code of in.partake.model.dao.postgres9.Postgres9IdMapper

package in.partake.model.dao.postgres9;

import in.partake.model.dao.DAOException;
import in.partake.model.dao.DataMapper;
import in.partake.model.dto.PartakeModel;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Postgres9IdMapper<T extends PartakeModel<T>> implements DataMapper<ResultSet, T> {
    private Postgres9Connection con;
    private Postgres9EntityDataMapper<T> mapper;
    private Postgres9EntityDao entityDao;
   
    public Postgres9IdMapper(Postgres9Connection con, Postgres9EntityDataMapper<T> mapper, Postgres9EntityDao entityDao) {
        this.con = con;
        this.mapper = mapper;
        this.entityDao = entityDao;
    }
   
    @Override
    public T map(ResultSet rs) throws DAOException {
        try {
            String id = rs.getString("id");
            if (id == null)
                return null;
           
            return mapper.map(entityDao.find(con, id));
        } catch (SQLException e) {
            throw new DAOException(e);
        }
    }

    @Override
    public ResultSet unmap(T t) throws DAOException {
        throw new UnsupportedOperationException();
    }
}
TOP

Related Classes of in.partake.model.dao.postgres9.Postgres9IdMapper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.