本文整理汇总了Java中org.hibernate.envers.AuditReaderFactory.get方法的典型用法代码示例。如果您正苦于以下问题:Java AuditReaderFactory.get方法的具体用法?Java AuditReaderFactory.get怎么用?Java AuditReaderFactory.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.envers.AuditReaderFactory
的用法示例。
在下文中一共展示了AuditReaderFactory.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update1
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
@Test
public void update1() throws Exception {
if (!JBOSS.equals(APPSERVER)) {
return;
}
log.info("start update1()");
AuditedTComplexEntity ce = createAuditedTComplexEntity();
applEman.persist(ce);
applEman.getTransaction().commit();
applEman.getTransaction().begin();
ce.setOwner("new owner");
ce = applEman.merge(ce);
applEman.getTransaction().commit();
applEman.getTransaction().begin();
AuditReader ar = AuditReaderFactory.get(applEman);
AuditQuery query = ar.createQuery().forRevisionsOfEntity(AuditedTComplexEntity.class, true, true);
List<AuditedTComplexEntity> resList = query.getResultList();
Assert.assertEquals(1, resList.size());
AuditedTComplexEntity ce2 = resList.get(0);
Assert.assertEquals("new owner", ce2.getOwner());
}
示例2: listCustomerRevisions
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
@Transactional(readOnly = true)
public List<CustomerHistory> listCustomerRevisions(Long customerId) {
// Create the Audit Reader. It uses the EntityManager, which will be opened when
// starting the new Transation and closed when the Transaction finishes.
AuditReader auditReader = AuditReaderFactory.get(entityManager);
// Create the Query:
AuditQuery auditQuery = auditReader.createQuery()
.forRevisionsOfEntity(Customer.class, false, true)
.add(AuditEntity.id().eq(customerId));
// We don't operate on the untyped Results, but cast them into a List of AuditQueryResult:
return AuditQueryUtils.getAuditQueryResults(auditQuery, Customer.class).stream()
// Turn into the CustomerHistory Domain Object:
.map(x -> getCustomerHistory(x))
// And collect the Results:
.collect(Collectors.toList());
}
示例3: persist2
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
@Test
public void persist2() throws Exception {
if (!JBOSS.equals(APPSERVER)) {
return;
}
log.info("start persist2()");
AuditedTComplexEntity ce = createAuditedTComplexEntity();
applEman.persist(ce);
applEman.getTransaction().commit();
applEman.getTransaction().begin();
List<Archive> archList = ArchiveLoader.loadArchivesByPrimaryKeyId(AuditedTComplexEntity.class.getName(),
String.valueOf(ce.getId()));
Assert.assertEquals(0, archList.size());
AuditReader ar = AuditReaderFactory.get(applEman);
AuditQuery query = ar.createQuery().forRevisionsOfEntity(AuditedTComplexEntity.class, true, true);
List<AuditedTComplexEntity> resList = query.getResultList();
Assert.assertEquals(0, resList.size());
}
示例4: delete1
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
@Test
public void delete1() throws Exception {
if (!JBOSS.equals(APPSERVER)) {
return;
}
log.info("start delete1()");
AuditedTComplexEntity ce = createAuditedTComplexEntity();
applEman.persist(ce);
applEman.getTransaction().commit();
applEman.getTransaction().begin();
applEman.remove(ce);
applEman.getTransaction().commit();
applEman.getTransaction().begin();
AuditReader ar = AuditReaderFactory.get(applEman);
AuditQuery query = ar.createQuery().forRevisionsOfEntity(AuditedTComplexEntity.class, true, true);
List<AuditedTComplexEntity> resList = query.getResultList();
Assert.assertEquals(1, resList.size());
AuditedTComplexEntity ce2 = resList.get(0);
log.debug(ce2);
Assert.assertEquals(2, ce2.getEagerList().size());
}
示例5: findRevision
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的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;
}
示例6: getHeadRevisionNumber
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的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;
}
示例7: findRevision
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的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;
}
示例8: findAllHistory
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的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;
}
示例9: getDelta
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
/**
* @param clazz
* @param lastId
* @return
*/
@SuppressWarnings("unchecked")
private <T extends Shareable> Bundle<T> getDelta(Class<T> clazz,
String lastId) {
AuditReader ar = AuditReaderFactory.get(getSession());
Number number = getLastId(clazz, lastId);
List<Object[]> entities = ar.createQuery()
.forRevisionsOfEntity(clazz, false, false)
.add(AuditEntity.revisionNumber().gt(number)).getResultList();
Bundle<T> bundle = new Bundle<T>(lastId);
for (Object[] o : entities) {
if (o == null) {
continue;
}
bundle.add((T) notNull(o[0]), notNull(getId(o[1])));
}
return bundle;
}
示例10: isUnknown
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
/**
* @param clazz
* @param reader
* @param lastId
* @return
*/
@SuppressWarnings("unchecked")
private <T extends Shareable> boolean isUnknown(Class<T> clazz,
String lastId) {
if (Bundle.FIRST_CHANGE.equals(lastId)) {
return false;
}
AuditReader reader = AuditReaderFactory.get(getSession());
List<T> entitiesAtRevision = reader.createQuery()
.forRevisionsOfEntity(clazz, false, false)
.add(AuditEntity.revisionNumber().eq(getLastId(clazz, lastId)))
.getResultList();
return (entitiesAtRevision == null) || entitiesAtRevision.isEmpty();
}
示例11: getAll
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
@Nonnull
private <T extends Shareable> Bundle<T> getAll(@Nonnull Class<T> clazz) {
AuditReader reader = AuditReaderFactory.get(getSession());
Number prior = (Number) reader.createQuery()
.forRevisionsOfEntity(clazz, false, true)
.addProjection(AuditEntity.revisionNumber().max())
.getSingleResult();
String lastId;
// previous revision, la actual no será persistida.
if (prior == null) {
lastId = Bundle.FIRST_CHANGE;
} else {
lastId = String.valueOf(prior);
}
return firstChangeProviderHandler.getAll(clazz, notNull(lastId));
}
示例12: findLastChangeRevision
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的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));
}
示例13: findRevisions
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的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());
}
示例14: getHistoryChanges
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的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;
}
示例15: buildInsertAuditQuery
import org.hibernate.envers.AuditReaderFactory; //导入方法依赖的package包/类
/**
* Builds the query to insert new {@link com.box.l10n.mojito.entity.TMTextUnitCurrentVariant}s
* as they were at the rollback date.
*
* @param rollbackDateTime Date at which the {@link TMTextUnitCurrentVariant}s will be rollbacked to
* @param tmId ID of the TM the {@link TMTextUnitCurrentVariant}s to be rolled back should belong to
* @param extraParameters Extra parameters to filter what to rollback
* @return The insert audit query
*/
protected AuditQuery buildInsertAuditQuery(DateTime rollbackDateTime, Long tmId, CurrentVariantRollbackParameters extraParameters) {
logger.trace("Building the insert tmTextUnitCurrentVariants audit query");
AuditReader auditReader = AuditReaderFactory.get(entityManager);
Number revNumberAtDate = auditReader.getRevisionNumberForDate(rollbackDateTime.toDate());
AuditQuery auditQuery = auditReader.createQuery()
.forEntitiesAtRevision(TMTextUnitCurrentVariant.class, TMTextUnitCurrentVariant.class.getName(), revNumberAtDate, true)
.add(AuditEntity.property("tm_id").eq(tmId));
List<Long> localeIdsToRollback = extraParameters.getLocaleIds();
if (localeIdsToRollback != null && !localeIdsToRollback.isEmpty()) {
// Using "in" does not work with relatedId() nor property() so using loop instead
for (Long localeIdToRollback : localeIdsToRollback) {
auditQuery.add(AuditEntity.relatedId("locale").eq(localeIdToRollback));
}
}
List<Long> tmTextUnitIdsToRollback = extraParameters.getTmTextUnitIds();
if (tmTextUnitIdsToRollback != null && !tmTextUnitIdsToRollback.isEmpty()) {
// Using "in" does not work with relatedId() nor property() so using loop instead
for (Long tmTextUnitIdToRollback : tmTextUnitIdsToRollback) {
auditQuery.add(AuditEntity.relatedId("tmTextUnit").eq(tmTextUnitIdToRollback));
}
}
return auditQuery;
}