Rev 524 | Rev 575 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 524 | Rev 543 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | 4 | ||
| - | 5 | import javax.persistence.NoResultException; |
|
| 5 | import javax.persistence.TypedQuery; |
6 | import javax.persistence.TypedQuery; |
| 6 | 7 | ||
| 7 | import org.springframework.stereotype.Repository; |
8 | import org.springframework.stereotype.Repository; |
| 8 | 9 | ||
| - | 10 | import br.com.ec.core.exception.NegocioException; |
|
| 9 | import br.com.ec.core.util.VerificadorUtil; |
11 | import br.com.ec.core.util.VerificadorUtil; |
| 10 | import br.com.ec.domain.dto.CompraProdutoDTO; |
12 | import br.com.ec.domain.dto.CompraProdutoDTO; |
| 11 | import br.com.ec.domain.dto.ProdutoDTO; |
13 | import br.com.ec.domain.dto.ProdutoDTO; |
| 12 | import br.com.ec.domain.model.Produto; |
14 | import br.com.ec.domain.model.Produto; |
| 13 | import br.com.ec.domain.util.CodigoBarraEAN; |
15 | import br.com.ec.domain.util.CodigoBarraEAN; |
| Line 32... | Line 34... | ||
| 32 | StringBuilder sql = new StringBuilder(); |
34 | StringBuilder sql = new StringBuilder(); |
| 33 | sql.append("SELECT e FROM Produto e "); |
35 | sql.append("SELECT e FROM Produto e "); |
| 34 | sql.append("WHERE e.codigo = :codigo"); |
36 | sql.append("WHERE e.codigo = :codigo"); |
| 35 | try { |
37 | try { |
| 36 | return getEntityManager().createQuery(sql.toString(), Produto.class).setParameter("codigo", codigoProduto).getSingleResult(); |
38 | return getEntityManager().createQuery(sql.toString(), Produto.class).setParameter("codigo", codigoProduto).getSingleResult(); |
| - | 39 | } catch(NoResultException ex) { |
|
| - | 40 | throw new NegocioException("NÃO EXISTE PRODUTO COM ESTE CÓDIGO"); |
|
| 37 | } catch(Exception ex) { |
41 | } catch(Exception ex) { |
| 38 | ex.printStackTrace(); |
42 | ex.printStackTrace(); |
| 39 | return null; |
43 | return null; |
| 40 | }
|
44 | }
|
| 41 | }
|
45 | }
|
| Line 55... | Line 59... | ||
| 55 | }
|
59 | }
|
| 56 | try { |
60 | try { |
| 57 | TypedQuery<ProdutoDTO> query = (TypedQuery<ProdutoDTO>) getEntityManager().createQuery(jpql.toString(), ProdutoDTO.class) |
61 | TypedQuery<ProdutoDTO> query = (TypedQuery<ProdutoDTO>) getEntityManager().createQuery(jpql.toString(), ProdutoDTO.class) |
| 58 | .setParameter("codigoOuEAN", codigoOuEAN); |
62 | .setParameter("codigoOuEAN", codigoOuEAN); |
| 59 | return query.getSingleResult(); |
63 | return query.getSingleResult(); |
| - | 64 | } catch(NoResultException ex) { |
|
| - | 65 | throw new NegocioException("NÃO EXISTE PRODUTO COM ESTE CÓDIGO"); |
|
| 60 | } catch(Exception ex) { |
66 | } catch(Exception ex) { |
| 61 | ex.printStackTrace(); |
67 | ex.printStackTrace(); |
| 62 | return null; |
68 | return null; |
| 63 | }
|
69 | }
|
| 64 | }
|
70 | }
|