本文整理汇总了Java中org.hibernate.envers.AuditReader.getRevisions方法的典型用法代码示例。如果您正苦于以下问题:Java AuditReader.getRevisions方法的具体用法?Java AuditReader.getRevisions怎么用?Java AuditReader.getRevisions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.envers.AuditReader
的用法示例。
在下文中一共展示了AuditReader.getRevisions方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRevisions
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
public List<Revision> getRevisions(String id, Params params) {
AuditReader reader = getAuditReader();
List<Number> revisionNumbers = reader.getRevisions(type, id);
Map<Number, Revision> revisionMap = reader.findRevisions(Revision.class, asSet(revisionNumbers));
Collection<Revision> revisions = revisionMap.values();
Comparator<Revision> timestampComparator = Comparator.comparingLong(Revision::getTimestamp);
Comparator<Revision> authorComparator = Comparator.comparing(Revision::getAuthor);
Comparator<Revision> comparator;
if (AUTHOR.equals(params.getSort())) {
comparator = authorComparator;
} else {
comparator = timestampComparator;
}
if (params.getOrder() == Order.DESC) {
comparator = comparator.reversed();
}
return Ordering.from(comparator)
.sortedCopy(revisions);
}
示例2: getHeadRevisionNumber
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
/**
*
* @param id
* @return
*/
public int getHeadRevisionNumber(int id) {
int result = 0;
try {
begin();
AuditReader reader = AuditReaderFactory.get(getEntityManager());
List<Number> revisions = reader.getRevisions(entityClass, id);
if (!revisions.isEmpty()) {
result = revisions.get(revisions.size() - 1).intValue();
}
commit();
} catch (NoResultException e) {
rollback();
LOG.warn("No result for revision with id of " + id);
} finally {
cleanup();
}
return result;
}
示例3: findAllHistory
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
public List<HistoryDto> findAllHistory(String username) {
Patient patientA = patientRepository.findByUsername(username);
Long patientId = patientA.getId();
EntityManager em = entityManagerFactory.createEntityManager();
AuditReader reader = AuditReaderFactory.get(em);
List<Number> revisions = reader.getRevisions(Patient.class, patientId);
List<HistoryDto> historyList = findHistoryDetails(revisions);
List<HistoryDto> legalHistoryList = findLegalHistoryByPatient(patientId);
historyList.addAll(legalHistoryList);
Collections.sort(historyList);
List<HistoryDto> historyListReverse = getReversed(historyList);
em.close();
return historyListReverse;
}
示例4: findLastChangeRevision
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Revision<N, T> findLastChangeRevision(ID id) {
Class<T> type = entityInformation.getJavaType();
AuditReader reader = AuditReaderFactory.get(entityManager);
List<Number> revisions = reader.getRevisions(type, id);
if (revisions.isEmpty()) {
return null;
}
N latestRevision = (N) revisions.get(revisions.size() - 1);
Class<?> revisionEntityClass = revisionEntityInformation.getRevisionEntityClass();
Object revisionEntity = reader.findRevision(revisionEntityClass, latestRevision);
RevisionMetadata<N> metadata = (RevisionMetadata<N>) getRevisionMetadata(revisionEntity);
return new Revision<N, T>(metadata, reader.find(type, id, latestRevision));
}
示例5: findRevisions
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Page<Revision<N, T>> findRevisions(ID id, Pageable pageable) {
Class<T> type = entityInformation.getJavaType();
AuditReader reader = AuditReaderFactory.get(entityManager);
List<Number> revisionNumbers = reader.getRevisions(type, id);
if (pageable.getOffset() > revisionNumbers.size()) {
return new PageImpl<Revision<N, T>>(Collections.<Revision<N, T>> emptyList(), pageable, 0);
}
int upperBound = pageable.getOffset() + pageable.getPageSize();
upperBound = upperBound > revisionNumbers.size() ? revisionNumbers.size() : upperBound;
List<? extends Number> subList = revisionNumbers.subList(pageable.getOffset(), upperBound);
Revisions<N, T> revisions = getEntitiesForRevisions((List<N>) subList, id, reader);
return new PageImpl<Revision<N, T>>(revisions.getContent(), pageable, revisionNumbers.size());
}
示例6: getHistoryChanges
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
@Override
public List<DefiniteResult> getHistoryChanges(ProcessResult processResultImpl) {
List<DefiniteResult> history = new ArrayList<>();
AuditReader auditReader = AuditReaderFactory.get(this.entityManager);
Long id = processResultImpl.getId();
if (id == null) {
return new ArrayList<>();
}
List<Number> revisions = auditReader.getRevisions(processResultImpl.getClass(), id);
DefiniteResult find = null;
for (int i = 0; i < revisions.size(); i++) {
Number revision = revisions.get(i);
find = auditReader.find(DefiniteResultImpl.class, id, revision);
history.add(find);
}
return history;
}
示例7: getRevisionHistoryMetadata
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public List<RevisionMetadata> getRevisionHistoryMetadata(Object id) {
AuditReader auditReader = getAuditReader();
List<Number> revisionList = auditReader.getRevisions(getEntityClass(), id);
List<RevisionMetadata> result = new ArrayList<RevisionMetadata>();
for (Number revision : revisionList) {
Long revisionLong = Long.valueOf(revision.longValue());
result.add(new LazyRevisionMetadata(this.persistenceManager, revisionLong));
}
return result;
}
示例8: findRevisions
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
public List<RevisionInfo> findRevisions(String id) {
List<RevisionInfo> list = new ArrayList<>();
AuditReader reader = AuditReaderFactory.get(getEntityManager());
List<Number> revisions = reader.getRevisions(getEntityClass(), id);
for (Number n : revisions) {
CustomRevisionEntity revEntity = reader.findRevision(CustomRevisionEntity.class, n);
list.add(new RevisionInfo(n, revEntity));
}
return list;
}
示例9: findRevision
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
public E findRevision(String id, Number revision) {
AuditReader reader = AuditReaderFactory.get(getEntityManager());
List<Number> revisions = reader.getRevisions(getEntityClass(), id);
if (!revisions.contains(revision)) {
return null;
}
E entity = reader.find(getEntityClass(), id, revision);
return entity;
}
示例10: findLegalHistoryByPatient
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
public List<HistoryDto> findLegalHistoryByPatient(long patientId) {
EntityManager em2 = entityManagerFactory.createEntityManager();
AuditReader reader2 = AuditReaderFactory.get(em2);
Set<Number> legalList = new HashSet<Number>();
List<ModifiedEntityTypeEntity> metes = modifiedEntityTypeEntityRepository
.findAll();
for (ModifiedEntityTypeEntity m : metes) {
String entityname = m.getEntityClassName()
.substring(m.getEntityClassName().lastIndexOf('.') + 1)
.trim();
if (entityname.equals("PatientLegalRepresentativeAssociation")) {
long revisionId = m.getRevision().getId();
Byte bt = m.getRevisionType();
if (bt != 2) {
AuditQuery query = reader2
.createQuery()
.forEntitiesAtRevision(
PatientLegalRepresentativeAssociation.class,
revisionId);
List<PatientLegalRepresentativeAssociation> psList = (List<PatientLegalRepresentativeAssociation>) query.getResultList();
for (PatientLegalRepresentativeAssociation ps : psList) {
PatientLegalRepresentativeAssociationPk pks=ps.getPatientLegalRepresentativeAssociationPk();
Patient pl=pks.getPatient();
if(pl!=null)
{
if (patientId == pl.getId()) {
Long LegalId = ps.getId();
List<Number> revisionListLegal = reader2
.getRevisions(
PatientLegalRepresentativeAssociation.class,
LegalId);
legalList.addAll(revisionListLegal);
Long LegalRepId = ps
.getPatientLegalRepresentativeAssociationPk()
.getLegalRepresentative().getId();
List<Number> revisionListLegal2 = reader2
.getRevisions(Patient.class, LegalRepId);
legalList.addAll(revisionListLegal2);
}
}
}
}
}
}
Set<Number> removeLegalList = new HashSet<Number>();
for (Number a : legalList) {
RevisionInfoEntity patientRevisionEntity = patientRevisionEntityRepository
.findOneById(a);
List<ModifiedEntityTypeEntity> meteLegalLists = modifiedEntityTypeEntityRepository
.findAllByRevision(patientRevisionEntity);
for (ModifiedEntityTypeEntity meteLegal : meteLegalLists) {
if (meteLegal.getRevisionType() == 0) {
String en = new String(meteLegal.getEntityClassName());
if (en.substring(en.lastIndexOf('.') + 1).trim()
.equals("Patient")) {
removeLegalList.add(a);
}
}
}
}
legalList.removeAll(removeLegalList);
em2.close();
List<Number> legalList2 = new ArrayList<Number>(legalList);
List<HistoryDto> historyLegals = (List<HistoryDto>) findLegalHistoryDetails(legalList2);
return historyLegals;
}
示例11: getRevisions
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
public Map<Number, DefaultRevisionEntity> getRevisions(long id) {
Session s = hibernateUtil.getSession();
AuditReader reader = AuditReaderFactory.get(s);
List<Number> revisionNums = reader.getRevisions( DataPoint.class, id );
return reader.findRevisions( DefaultRevisionEntity.class, new HashSet<Number>(revisionNums) );
}
示例12: testRegion
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
@Test
public void testRegion() {
entityManager.getTransaction().begin();
RegionDao regionDao = injector.getInstance(RegionDao.class);
Region germany = new Region(Region.GERMANY);
String id1 = regionDao.save(germany);
Assert.assertNotNull("ID expected", id1);
List<Region> all = regionDao.findAll();
Assert.assertTrue("1 Region expected", all.size()==1);
Region europe = new Region(Region.EUROPE);
String id2 = regionDao.save(europe);
all = regionDao.findAll();
Assert.assertTrue("2 Regions expected", all.size()==2);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
Region loadedGermany = regionDao.findByExactName(Region.GERMANY);
Assert.assertNotNull(loadedGermany);
Assert.assertEquals(loadedGermany.getId(), id1);
Assert.assertEquals(loadedGermany, germany);
Region loadedEurope = regionDao.findByExactName(Region.EUROPE);
Assert.assertNotNull(loadedEurope);
Assert.assertEquals(loadedEurope.getId(), id2);
Assert.assertEquals(loadedEurope, europe);
loadedEurope.setDescription("this is changed europe");
regionDao.save(loadedEurope);
all = regionDao.findAll();
Assert.assertTrue("2 Regions expected", all.size()==2);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
Region loadedEurope2 = regionDao.findByExactName(Region.EUROPE);
loadedEurope2.setDescription("this is twice changed europe");
regionDao.save(loadedEurope);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
AuditReader auditReader = AuditReaderFactory.get(entityManager);
List<Number> revisionNumbers = auditReader.getRevisions(Region.class, loadedEurope.getId());
// System.out.println(revisionNumbers + " revisions found.");
for (Number number : revisionNumbers) {
// System.out.println("RevisionNumber: " + number);
Region regionWithRevision = auditReader.find(Region.class, loadedEurope.getId(), number);
// try {
// System.out.println("Region with revision " + number + "\n"
// + new ObjectMapper().writeValueAsString(regionWithRevision));
// } catch (JsonProcessingException e) {
// Assert.fail(e.getMessage());
// }
Assert.assertNotNull(regionWithRevision);
}
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
regionDao.delete(loadedEurope);
regionDao.delete(loadedGermany);
List<Region> regionList = regionDao.findAll();
Assert.assertEquals(0, regionList.size());
entityManager.getTransaction().commit();
}