当前位置: 首页>>代码示例>>Java>>正文


Java AuditReader类代码示例

本文整理汇总了Java中org.hibernate.envers.AuditReader的典型用法代码示例。如果您正苦于以下问题:Java AuditReader类的具体用法?Java AuditReader怎么用?Java AuditReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuditReader类属于org.hibernate.envers包,在下文中一共展示了AuditReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.hibernate.envers.AuditReader; //导入依赖的package包/类
@Override
protected Object process(HttpServletRequest req, WxSession session) throws Exception {
    int first;
    int limit;
    Date start;
    Date end;
    first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
    limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
    start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
    end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
    end = DateUtils.addDays(end, 1);
    try (Session s = SQLCore.sf.openSession()) {
        AuditReader reader = TableTicket.getAuditReader(s);
        return reader.createQuery()
                .forRevisionsOfEntity(Ticket.class, false, true)
                .addOrder(AuditEntity.revisionNumber().desc())
                .add(AuditEntity.revisionProperty("timestamp").between(start.getTime(), end.getTime()))
                .setFirstResult(first)
                .setMaxResults(limit)
                .getResultList();
    }
}
 
开发者ID:ZSCNetSupportDept,项目名称:WechatTicketSystem,代码行数:23,代码来源:TicketLog.java

示例2: update1

import org.hibernate.envers.AuditReader; //导入依赖的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());
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:25,代码来源:EnversActuatorIntegrationTest.java

示例3: 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);
    }
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:26,代码来源:HistoricStore.java

示例4: listCustomerRevisions

import org.hibernate.envers.AuditReader; //导入依赖的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());
}
 
开发者ID:bytefish,项目名称:VersioningWithEnvers,代码行数:20,代码来源:CustomerHistoryRepository.java

示例5: persist2

import org.hibernate.envers.AuditReader; //导入依赖的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());
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:21,代码来源:EnversActuatorIntegrationTest.java

示例6: delete1

import org.hibernate.envers.AuditReader; //导入依赖的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());
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:24,代码来源:EnversActuatorIntegrationTest.java

示例7: 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;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:28,代码来源:JobNotificationDao.java

示例8: 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;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:24,代码来源:BaseDao.java

示例9: 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;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:27,代码来源:BaseDao.java

示例10: 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;
	}
 
开发者ID:tlin-fei,项目名称:ds4p,代码行数:18,代码来源:AuditServiceImpl.java

示例11: getDelta

import org.hibernate.envers.AuditReader; //导入依赖的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;
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:25,代码来源:EnversReplicationProvider.java

示例12: isUnknown

import org.hibernate.envers.AuditReader; //导入依赖的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();
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:22,代码来源:EnversReplicationProvider.java

示例13: getAll

import org.hibernate.envers.AuditReader; //导入依赖的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));

}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:20,代码来源:EnversReplicationProvider.java

示例14: 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));
}
 
开发者ID:zakyalvan,项目名称:spring-envers-audit,代码行数:21,代码来源:DefaultRevisionAwareJpaRepository.java

示例15: 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());
}
 
开发者ID:zakyalvan,项目名称:spring-envers-audit,代码行数:20,代码来源:DefaultRevisionAwareJpaRepository.java


注:本文中的org.hibernate.envers.AuditReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。