Rev 216 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 216 | espaco | 1 | package br.com.ec.repository; |
| 2 | |||
| 3 | import java.text.Normalizer; |
||
| 4 | |||
| 5 | import javax.persistence.EntityManager; |
||
| 6 | import javax.persistence.PersistenceContext; |
||
| 7 | import javax.persistence.Query; |
||
| 8 | |||
| 9 | import br.com.ec.core.consulta.ParametrosConsulta; |
||
| 10 | import br.com.ec.core.generic.AbstractRepository; |
||
| 11 | import br.com.ec.core.generic.GenericRepository; |
||
| 12 | |||
| 13 | public abstract class SistemaAbstractRepository<ENTIDADE> extends AbstractRepository<ENTIDADE> implements GenericRepository<ENTIDADE> { |
||
| 14 | |||
| 15 | @PersistenceContext(unitName = "sisPU") |
||
| 16 | private EntityManager entityManager; |
||
| 17 | |||
| 18 | @Override |
||
| 19 | public EntityManager getEntityManager() { |
||
| 20 | return entityManager; |
||
| 21 | } |
||
| 22 | |||
| 23 | @Override |
||
| 24 | protected void setarStringParametrosConsultar(StringBuilder sql, ENTIDADE entidade) {} |
||
| 25 | |||
| 26 | @Override |
||
| 27 | protected void setarQueryParametrosConsultar(Query query, ENTIDADE entidade) {} |
||
| 28 | |||
| 29 | @Override |
||
| 30 | protected void setarStringParametrosConsulta(StringBuilder sql, ParametrosConsulta<ENTIDADE> parametros) {} |
||
| 31 | |||
| 32 | @Override |
||
| 33 | protected void setarQueryParametrosConsulta(Query query, ParametrosConsulta<ENTIDADE> parametros) {} |
||
| 34 | |||
| 35 | @Override |
||
| 36 | protected String getColunaOrdenadora() { |
||
| 37 | return ""; |
||
| 38 | } |
||
| 39 | |||
| 40 | @Override |
||
| 41 | protected boolean adicionarDistinct() { |
||
| 42 | return true; |
||
| 43 | } |
||
| 44 | |||
| 45 | protected static String removerAcento(String texto) { |
||
| 46 | texto = Normalizer.normalize(texto, Normalizer.Form.NFD); |
||
| 47 | texto = removerAcentuacao(texto); |
||
| 48 | texto = texto.replace( "." , ""); |
||
| 49 | texto = texto.replace( "/" , ""); |
||
| 50 | texto = texto.replace( "-" , ""); |
||
| 51 | return texto.trim(); |
||
| 52 | } |
||
| 53 | |||
| 54 | protected static String removerAcentuacao(String texto) { |
||
| 55 | texto = Normalizer.normalize(texto, Normalizer.Form.NFD); |
||
| 56 | texto = texto.replaceAll("[^\\p{ASCII}]", ""); |
||
| 57 | return texto.trim(); |
||
| 58 | } |
||
| 59 | |||
| 60 | protected static String sqlConsultarSemAcento(String coluna) { |
||
| 61 | StringBuilder texto = new StringBuilder(); |
||
| 62 | texto = texto.append("UPPER(TRANSLATE("); |
||
| 63 | texto = texto.append(coluna); |
||
| 234 | espaco | 64 | texto = texto.append(", 'ÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÔÖÚÙÛÜÇáàãâäéèêëíìîïóòõôöúùûüç', 'AAAAAEEEEIIIIOOOOOUUUUCaaaaaeeeeiiiiooooouuuuc'))"); |
| 216 | espaco | 65 | return texto.toString(); |
| 66 | } |
||
| 67 | |||
| 68 | protected static String removerAcentuacaoParaBuscaGenerica(String texto) { |
||
| 69 | return "%" + removerAcentuacao(texto) + "%"; |
||
| 70 | } |
||
| 71 | |||
| 72 | } |