Subversion Repositories Integrator Subversion

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

package br.com.ec.repository;

import java.text.Normalizer;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import br.com.ec.core.consulta.ParametrosConsulta;
import br.com.ec.core.generic.AbstractRepository;
import br.com.ec.core.generic.GenericRepository;

public abstract class SistemaAbstractRepository<ENTIDADE> extends AbstractRepository<ENTIDADE> implements GenericRepository<ENTIDADE> {

        @PersistenceContext(unitName = "sisPU")
        private EntityManager entityManager;
       
        @Override
        public EntityManager getEntityManager() {
                return entityManager;
        }
       
        @Override
        protected void setarStringParametrosConsultar(StringBuilder sql, ENTIDADE entidade) {}

        @Override
        protected void setarQueryParametrosConsultar(Query query, ENTIDADE entidade) {}

        @Override
        protected void setarStringParametrosConsulta(StringBuilder sql, ParametrosConsulta<ENTIDADE> parametros) {}

        @Override
        protected void setarQueryParametrosConsulta(Query query, ParametrosConsulta<ENTIDADE> parametros) {}
       
        @Override
        protected String getColunaOrdenadora() {
                return "";
        }
       
        @Override
        protected boolean adicionarDistinct() {
                return true;
        }
       
        protected static String removerAcento(String texto) {
                texto = Normalizer.normalize(texto, Normalizer.Form.NFD);
                texto = removerAcentuacao(texto);
                texto = texto.replace( "." , "");
                texto = texto.replace( "/" , "");
                texto = texto.replace( "-" , "");
            return texto.trim();
        }
       
        protected static String removerAcentuacao(String texto) {
                texto = Normalizer.normalize(texto, Normalizer.Form.NFD);
                texto = texto.replaceAll("[^\\p{ASCII}]", "");
            return texto.trim();
        }
       
        protected static String sqlConsultarSemAcento(String coluna) {
                StringBuilder texto = new StringBuilder();
                texto = texto.append("UPPER(TRANSLATE(");
                texto = texto.append(coluna);
                texto = texto.append(", 'Ã?ÀÃÂÄÉÈÊËÃ?ÌÎÃ?ÓÒÕÔÖÚÙÛÜÇáàãâäéèêëíìîïóòõôöúùûüç', 'AAAAAEEEEIIIIOOOOOUUUUCaaaaaeeeeiiiiooooouuuuc'))");
                return texto.toString();
        }
       
        protected static String removerAcentuacaoParaBuscaGenerica(String texto) {
                return "%" + removerAcentuacao(texto) + "%";
        }
       
}