Rev 762 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 760 | blopes | 1 | package br.com.sl.repository.jpa; |
| 2 | |||
| 3 | import javax.persistence.NoResultException; |
||
| 4 | |||
| 5 | import org.springframework.stereotype.Repository; |
||
| 6 | |||
| 7 | import br.com.sl.domain.model.Ativo; |
||
| 8 | import br.com.sl.repository.AtivoRepository; |
||
| 9 | import br.com.sl.repository.SistemaAbstractRepository; |
||
| 10 | |||
| 11 | @Repository |
||
| 12 | public class AtivoRepositoryJpaImpl extends SistemaAbstractRepository<Ativo> implements AtivoRepository { |
||
| 13 | |||
| 14 | private static final String ATIVO_INFORMADO_NAO_EXISTE_PARA_ESTA_DESCRICAO = "Ativo informado não existe para esta descrição"; |
||
| 15 | |||
| 16 | @Override |
||
| 771 | blopes | 17 | protected String getColunaOrdenadora() { |
| 18 | return "nome"; |
||
| 19 | } |
||
| 20 | |||
| 21 | @Override |
||
| 762 | blopes | 22 | public Ativo consultarPorNome(String nome) { |
| 760 | blopes | 23 | StringBuilder jpql = new StringBuilder(); |
| 24 | jpql.append("SELECT e FROM Ativo e "); |
||
| 762 | blopes | 25 | jpql.append("WHERE e.nome LIKE :nome"); |
| 760 | blopes | 26 | try { |
| 27 | return getEntityManager().createQuery(jpql.toString(), Ativo.class) |
||
| 762 | blopes | 28 | .setParameter("nome", nome) |
| 760 | blopes | 29 | .getSingleResult(); |
| 30 | } catch(NoResultException nre) { |
||
| 31 | nre.printStackTrace(); |
||
| 32 | } |
||
| 33 | return null; |
||
| 34 | } |
||
| 35 | |||
| 36 | } |