public class UpdatePatient implements CaseRules{
@Override
public ResponseExecution executeOperation(Object entity, EntityManager em) throws BaseException {
Patient patient = (Patient) entity;
ResponseExecution response = new ResponseExecution();
em.merge(patient);
...
public class PatientListener {
private PatientServicesLocal patientService;
@PrePersist
public void prePersist(Patient patient) throws BaseException {
...
}
@PreUpdate
public void preUpdate(Patient patient) throws BaseException {
//Realiza a chamada da classe responsável pela consulta...
patientService = (PatientServicesLocal) ServicesProviderByLookup
.getServicesByClassServices(PatientService.class);
patientService.execute(Constants.VERIFY_EXISTS_PATIENT_RULE, patient);
}
@PreRemove
public void preRemove(Patient patient) throws BaseException {
...
}
}
public class VerifyExistsPatient implements CaseRules {
@Override
public ResponseExecution executeOperation(Object entity, EntityManager em)
throws BaseException {
ResponseExecution response = new ResponseExecution();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Patient> cq = builder.createQuery(Patient.class);
Root<Patient> patientRoot = cq.from(Patient.class);
List<Predicate> predicate = new ArrayList<Predicate>();
// Obtém por reflection os atributos que foram preenchidos em tela
ReflectionUtil ru = new ReflectionUtil(entity);
Map<Object, Object> filledAttrs = ru.getFilledAttributes();
// Preenchendo dinamicamente as condições da consulta
for (Object key : filledAttrs.keySet()) {
predicate.add(builder.equal(patientRoot.get(key.toString()),
filledAttrs.get(key)));
}
cq.where(predicate.toArray(new Predicate[predicate.size()]));
List<Patient> result = em.createQuery(cq).getResultList();
...
Alguém já passou por isso, ou sabe o que está acontecendo ??