rafael 2012-08-31 20:10:28 +00:00
parent 0114cbc3e7
commit 2cd884e910
6 changed files with 121 additions and 63 deletions

View File

@ -1,6 +1,10 @@
package com.rjconsultores.ventaboletos.dao;
public interface SeguroKmDAO {
import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente;
import com.rjconsultores.ventaboletos.entidad.SeguroKm;
import java.util.List;
public interface SeguroKmDAO extends GenericDAO<SeguroKm, Integer> {
/**
* Indica se existe seguroKm para o orgaoConcedenteId informado
@ -10,4 +14,6 @@ public interface SeguroKmDAO {
*/
public boolean existe(Integer orgaoConcedenteId);
public List<SeguroKm> buscarPorOrgao(OrgaoConcedente orgao);
}

View File

@ -1,5 +1,7 @@
package com.rjconsultores.ventaboletos.dao.hibernate;
import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
@ -21,7 +23,7 @@ public class SeguroKmHibernateDAO extends GenericHibernateDAO<SeguroKm, Integer>
@Override
public boolean existe(Integer orgaoConcedenteId) {
Criteria c= makeCriteria();
Criteria c = makeCriteria();
c.add(Restrictions.eq("orgaoconcedente.orgaoConcedenteId", orgaoConcedenteId));
c.add(Restrictions.eq("activo", Boolean.TRUE));
c.setProjection(Projections.rowCount());
@ -30,5 +32,11 @@ public class SeguroKmHibernateDAO extends GenericHibernateDAO<SeguroKm, Integer>
return HibernateFix.count(c.list()) > 0;
}
public List<SeguroKm> buscarPorOrgao(OrgaoConcedente orgao) {
Criteria c = makeCriteria();
c.add(Restrictions.eq("orgaoconcedente", orgao));
c.add(Restrictions.eq("activo", Boolean.TRUE));
return c.list();
}
}

View File

@ -11,26 +11,29 @@ import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author gleimar
*/
@Entity
@SequenceGenerator(name = "SEGURO_KM_SEQ", sequenceName = "SEGURO_KM_SEQ", allocationSize = 1)
@Table(name = "SEGURO_KM")
public class SeguroKm implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEGURO_KM_SEQ")
@Column(name = "SEGUROKM_ID")
private Integer segurokmId;
@Column(name = "KMATE")
@ -79,8 +82,6 @@ public class SeguroKm implements Serializable {
this.valortaxa = valortaxa;
}
@Override
public int hashCode() {
int hash = 0;
@ -137,5 +138,4 @@ public class SeguroKm implements Serializable {
public void setUsuarioId(Integer usuarioId) {
this.usuarioId = usuarioId;
}
}

View File

@ -1,6 +1,12 @@
package com.rjconsultores.ventaboletos.service;
import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente;
import com.rjconsultores.ventaboletos.entidad.SeguroKm;
import java.util.List;
public interface SeguroKmService {
public interface SeguroKmService extends GenericService<SeguroKm, Integer>{
public List<SeguroKm> buscarPorOrgao(OrgaoConcedente orgao);
}

View File

@ -0,0 +1,55 @@
package com.rjconsultores.ventaboletos.service.impl;
import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente;
import com.rjconsultores.ventaboletos.entidad.SeguroKm;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rjconsultores.ventaboletos.dao.SeguroKmDAO;
import com.rjconsultores.ventaboletos.service.SeguroKmService;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import java.util.Calendar;
import org.springframework.transaction.annotation.Transactional;
@Service("seguroKmService")
public class SeguroKmServiceImpl implements SeguroKmService {
@Autowired
private SeguroKmDAO seguroKmDAO;
public List<SeguroKm> buscarPorOrgao(OrgaoConcedente orgao) {
return seguroKmDAO.buscarPorOrgao(orgao);
}
public List<SeguroKm> obtenerTodos() {
return seguroKmDAO.obtenerTodos();
}
public SeguroKm obtenerID(Integer id) {
return seguroKmDAO.obtenerID(id);
}
@Transactional
public SeguroKm suscribir(SeguroKm entidad) {
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.TRUE);
return seguroKmDAO.suscribir(entidad);
}
@Transactional
public SeguroKm actualizacion(SeguroKm entidad) {
return seguroKmDAO.actualizacion(entidad);
}
@Transactional
public void borrar(SeguroKm entidad) {
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.FALSE);
seguroKmDAO.borrar(entidad);
}
}

View File

@ -1,17 +0,0 @@
package com.rjconsultores.ventaboletos.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.rjconsultores.ventaboletos.dao.SeguroKmDAO;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.SeguroKmService;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
@Service("seguroKmService")
public class SeguroServiceKmImpl implements SeguroKmService{
@Autowired
private SeguroKmDAO seguroKmDAO;
}