List of usage examples for org.hibernate.envers AuditReaderFactory get
public static AuditReader get(EntityManager entityManager) throws AuditException
From source file:dao.ApostaDao.java
public List<Aposta> listarAuditoria() throws Exception { try {/*ww w .ja v a 2s. c o m*/ Session sessao = Hibernate4Util.getSessionFactory(); Transaction transacao = sessao.beginTransaction(); AuditReader reader = AuditReaderFactory.get(sessao); List<Object[]> resultList = reader.createQuery().forRevisionsOfEntity(Aposta.class, false, true) .getResultList(); List<Aposta> listaAuditada = new ArrayList<>(); int contador = 0; for (Object[] objTmp : resultList) { Aposta apostaTmp = (Aposta) objTmp[0]; apostaTmp.setRevType(objTmp[2].toString()); if (apostaTmp.getApostador() != null) { apostaTmp.getApostador().getCodigo(); } if (apostaTmp.getJogo() != null) { apostaTmp.getJogo().getCodigo(); } listaAuditada.add(contador, apostaTmp); contador++; } transacao.commit(); return listaAuditada; } catch (HibernateException e) { throw new Exception("No foi possvel buscar a auditoria. Erro: " + e.getMessage()); } }
From source file:dao.ApostadorDao.java
public List<Apostador> listarAuditoria() throws Exception { try {/*from w ww . j ava2s . c o m*/ Session sessao = Hibernate4Util.getSessionFactory(); Transaction transacao = sessao.beginTransaction(); AuditReader reader = AuditReaderFactory.get(sessao); List<Object[]> resultList = reader.createQuery().forRevisionsOfEntity(Apostador.class, false, true) .getResultList(); List<Apostador> listaAuditada = new ArrayList<>(); int contador = 0; for (Object[] objTmp : resultList) { Apostador apostadorTmp = (Apostador) objTmp[0]; apostadorTmp.setRevType(objTmp[2].toString()); if (apostadorTmp.getGrupo() != null) { apostadorTmp.getGrupo().getCodigo(); } if (apostadorTmp.getTimeDePreferencia() != null) { apostadorTmp.getTimeDePreferencia().getCodigo(); } listaAuditada.add(contador, apostadorTmp); contador++; } transacao.commit(); return listaAuditada; } catch (HibernateException e) { throw new Exception("No foi possvel buscar a auditoria. Erro: " + e.getMessage()); } }
From source file:dao.CompeticaoDao.java
public List<Competicao> listarAuditoria() throws Exception { try {// ww w . jav a 2 s. c o m Session sessao = Hibernate4Util.getSessionFactory(); Transaction transacao = sessao.beginTransaction(); AuditReader reader = AuditReaderFactory.get(sessao); List<Object[]> resultList = reader.createQuery().forRevisionsOfEntity(Competicao.class, false, true) .getResultList(); List<Competicao> listaAuditada = new ArrayList<>(); int contador = 0; for (Object[] objTmp : resultList) { Competicao competicaoTmp = (Competicao) objTmp[0]; competicaoTmp.setRevType(objTmp[2].toString()); listaAuditada.add(contador, competicaoTmp); contador++; } transacao.commit(); return listaAuditada; } catch (HibernateException e) { throw new Exception("No foi possvel buscar a auditoria. Erro: " + e.getMessage()); } }
From source file:dao.RodadaDao.java
public List<Rodada> listarAuditoria() throws Exception { try {/*from ww w . j a v a 2 s.c om*/ Session sessao = Hibernate4Util.getSessionFactory(); Transaction transacao = sessao.beginTransaction(); AuditReader reader = AuditReaderFactory.get(sessao); List<Object[]> resultList = reader.createQuery().forRevisionsOfEntity(Rodada.class, false, true) .getResultList(); List<Rodada> listaAuditada = new ArrayList<>(); int contador = 0; for (Object[] objTmp : resultList) { Rodada rodadaTmp = (Rodada) objTmp[0]; rodadaTmp.setRevType(objTmp[2].toString()); if (rodadaTmp.getCompeticao() != null) { rodadaTmp.getCompeticao().getCodigo(); } listaAuditada.add(contador, rodadaTmp); contador++; } transacao.commit(); return listaAuditada; } catch (HibernateException e) { throw new Exception("No foi possvel buscar a auditoria. Erro: " + e.getMessage()); } }
From source file:dao.TimeCompeticaoDao.java
public List<TimeCompeticao> listarAuditoria() throws Exception { try {// w w w .j av a 2 s . co m Session sessao = Hibernate4Util.getSessionFactory(); Transaction transacao = sessao.beginTransaction(); AuditReader reader = AuditReaderFactory.get(sessao); List<Object[]> resultList = reader.createQuery().forRevisionsOfEntity(TimeCompeticao.class, false, true) .getResultList(); List<TimeCompeticao> listaAuditada = new ArrayList<>(); int contador = 0; for (Object[] objTmp : resultList) { TimeCompeticao tcTmp = (TimeCompeticao) objTmp[0]; tcTmp.setRevType(objTmp[2].toString()); if (tcTmp.getCompeticao() != null) { tcTmp.getCompeticao().getCodigo(); } if (tcTmp.getTime() != null) { tcTmp.getTime().getCodigo(); } listaAuditada.add(contador, tcTmp); contador++; } transacao.commit(); return listaAuditada; } catch (HibernateException e) { throw new Exception( "No foi possvel buscar os vinculos de time por competio. Erro: " + e.getMessage()); } }
From source file:dao.TimeDao.java
public List<Time> listarAuditoria() throws Exception { try {//from www.jav a2s . c om Session sessao = Hibernate4Util.getSessionFactory(); Transaction transacao = sessao.beginTransaction(); AuditReader reader = AuditReaderFactory.get(sessao); List<Object[]> resultList = reader.createQuery().forRevisionsOfEntity(Time.class, false, true) .getResultList(); List<Time> listaAuditada = new ArrayList<>(); int contador = 0; for (Object[] objTmp : resultList) { Time timeTmp = (Time) objTmp[0]; timeTmp.setRevType(objTmp[2].toString()); listaAuditada.add(contador, timeTmp); contador++; } transacao.commit(); return listaAuditada; } catch (HibernateException e) { throw new Exception("No foi possvel buscar a auditoria. Erro: " + e.getMessage()); } }
From source file:de.crowdcode.bitemporal.example.AddressRepository.java
License:Apache License
public AuditReader getAuditReader() { if (ar == null) { return AuditReaderFactory.get(em); } else { return ar; } }
From source file:de.iteratec.iteraplan.persistence.dao.HistoryDAOImpl.java
License:Open Source License
/** * Gets a new AuditReader from the current session */ public AuditReader getAuditReader() { return AuditReaderFactory.get(this.getSession()); }
From source file:de.rs.scrumit.dao.BaseEntityAuditDao.java
License:Open Source License
@Transactional(readOnly = true) public <T extends BaseEntityAuditModel> T getByRevision(Class<T> modelClass, Number revision) { AuditReader reader = AuditReaderFactory.get(entityManager); T model = reader.findRevision(modelClass, revision); return model; }
From source file:de.rs.scrumit.dao.BaseEntityAuditDao.java
License:Open Source License
@Transactional(readOnly = true) public <T extends BaseEntityAuditModel> void printChangeHistory(Class<T> modelClass, String code) { AuditReader reader = AuditReaderFactory.get(entityManager); List<?> results = reader.createQuery().forRevisionsOfEntity(modelClass, false, true) .add(AuditEntity.property("code").eq(code)).addOrder(AuditEntity.property("changedAt").asc()) .getResultList();//from w ww .ja v a2s . com SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); for (Object entry : results) { BaseEntityAuditModel model = (BaseEntityAuditModel) ((Object[]) entry)[0]; RevisionType type = (RevisionType) ((Object[]) entry)[2]; String msg = type + " entry with code " + model.getCode() + " at time: " + format.format(model.getChangedAt()); LOGGER.debug(msg); System.out.println(msg); } }