本文整理汇总了Java中org.hibernate.envers.AuditReader.find方法的典型用法代码示例。如果您正苦于以下问题:Java AuditReader.find方法的具体用法?Java AuditReader.find怎么用?Java AuditReader.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.envers.AuditReader
的用法示例。
在下文中一共展示了AuditReader.find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findRevision
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
/**
* gets the entity at the specified revision
*
* @param id
* the id of the entity to fetch
* @param revisionNumber
* the revision number
* @return the entity or null if no entity can be found
*/
@Nullable
@Override
public JobNotification findRevision(int id, int revisionNumber) {
JobNotification result = null;
try {
begin();
AuditReader reader = AuditReaderFactory.get(getEntityManager());
result = reader.find(JobNotification.class, id, revisionNumber);
Hibernate.initialize(result.getLifecycleEvents());
result.getLifecycleEvents().contains(JobLifecycleEvent.QUEUE_ADD);
commit();
} catch (NoResultException e) {
LOG.warn("No result for revision " + revisionNumber + " with id of " + id);
} finally {
cleanup();
}
return result;
}
示例2: findRevision
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
/**
* gets the entity at the specified revision
*
* @param id
* the id of the entity to fetch
* @param revisionNumber
* the revision number
* @return the entity or null if no entity can be found
*/
@Nullable
public T_ENTITY findRevision(int id, int revisionNumber) {
T_ENTITY result = null;
try {
begin();
AuditReader reader = AuditReaderFactory.get(getEntityManager());
result = reader.find(entityClass, id, revisionNumber);
commit();
} catch (NoResultException e) {
rollback();
LOG.warn("No result for revision " + revisionNumber + " with id of " + id);
} finally {
cleanup();
}
return result;
}
示例3: 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));
}
示例4: 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;
}
示例5: 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;
}
示例6: testBasicUsage
import org.hibernate.envers.AuditReader; //导入方法依赖的package包/类
public void testBasicUsage() {
// create a couple of events
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist( new Event( "Our very first event!", new Date() ) );
entityManager.persist( new Event( "A follow up event", new Date() ) );
entityManager.getTransaction().commit();
entityManager.close();
// now lets pull events from the database and list them
entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
List<Event> result = entityManager.createQuery( "from Event", Event.class ).getResultList();
for ( Event event : result ) {
System.out.println( "Event (" + event.getDate() + ") : " + event.getTitle() );
}
entityManager.getTransaction().commit();
entityManager.close();
// so far the code is the same as we have seen in previous tutorials. Now lets leverage Envers...
// first lets create some revisions
entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
Event myEvent = entityManager.find( Event.class, 2L ); // we are using the increment generator, so we know 2 is a valid id
myEvent.setDate( new Date() );
myEvent.setTitle( myEvent.getTitle() + " (rescheduled)" );
entityManager.getTransaction().commit();
entityManager.close();
// and then use an AuditReader to look back through history
entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
myEvent = entityManager.find( Event.class, 2L );
assertEquals( "A follow up event (rescheduled)", myEvent.getTitle() );
AuditReader reader = AuditReaderFactory.get( entityManager );
Event firstRevision = reader.find( Event.class, 2L, 1 );
assertFalse( firstRevision.getTitle().equals( myEvent.getTitle() ) );
assertFalse( firstRevision.getDate().equals( myEvent.getDate() ) );
Event secondRevision = reader.find( Event.class, 2L, 2 );
assertTrue( secondRevision.getTitle().equals( myEvent.getTitle() ) );
assertTrue( secondRevision.getDate().equals( myEvent.getDate() ) );
entityManager.getTransaction().commit();
entityManager.close();
}
示例7: 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();
}