/*
* Copyright Massimiliano Dess� (desmax74@yahoo.it)
*
* Licensed under Apache License Version 2.0
* (http://www.apache.org/licenses/LICENSE-2.0),
*
* for commercial use, under
* GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*/
package org.magicbox.ibatis;
import java.util.List;
import java.util.Map;
import javolution.util.FastMap;
import org.magicbox.dao.AnnunciDao;
import org.magicbox.domain.Annuncio;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
/**
* Implementazione per l' accesso al repository degli annunci
*
* @author Massimiliano Dess� (desmax74@yahoo.it)
* @since jdk 1.6.0
* @version 3.0
*/
@SuppressWarnings("unchecked")
public class AnnunciDaoImpl extends SqlMapClientDaoSupport implements AnnunciDao {
public List<Annuncio> getAnnunci(int tipo) throws DataAccessException {
return getSqlMapClientTemplate().queryForList("getAnnunci", tipo);
}
public List<Annuncio> getAnnunci(int tipo, int pageNo, long centro) throws DataAccessException {
Map params = new FastMap();
params.put("tipo", tipo);
params.put("limit", offset);
params.put("offset", offset * pageNo);
params.put("idCentro", centro);
return getSqlMapClientTemplate().queryForList("getAnnunciCentro", params);
}
public Annuncio getAnnuncio(long id) throws DataAccessException {
return (Annuncio) getSqlMapClientTemplate().queryForObject("getAnnuncio", id);
}
public void insertAnnuncio(Annuncio annuncio) throws DataAccessException {
getSqlMapClientTemplate().insert("insertAnnuncio", annuncio);
}
public void deleteAnnuncio(long id) throws DataAccessException {
getSqlMapClientTemplate().delete("deleteAnnuncio", id);
}
public int getAnnunciPerPagina() {
return offset;
}
public void setAnnunciPerPagina(int offset) {
this.offset = offset;
}
private int offset;
}