类org.hibernate.envers.query.AuditEntity源码实例Demo

下面列出了怎么用org.hibernate.envers.query.AuditEntity的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public BuildConfigurationAudited findLatestById(int buildConfigurationId) {
    Object result = AuditReaderFactory.get(entityManager)
            .createQuery()
            .forRevisionsOfEntity(BuildConfiguration.class, false, false)
            .add(AuditEntity.id().eq(buildConfigurationId))
            .addOrder(AuditEntity.revisionNumber().desc())
            .setMaxResults(1)
            .getSingleResult();
    if (result == null) {
        return null;
    }

    Object[] parts = (Object[]) result;
    return createAudited(parts[0], parts[1]);
}
 
@Override
public List<IdRev> searchIdRevForBuildConfigurationNameOrProjectName(
        List<Project> projectsMatchingName,
        String name) {
    AuditDisjunction disjunction = AuditEntity.disjunction();
    projectsMatchingName.forEach(project -> {
        disjunction.add(AuditEntity.relatedId("project").eq(project.getId()));
    });
    disjunction.add(AuditEntity.property("name").like(name));

    List<Object[]> result = AuditReaderFactory.get(entityManager)
            .createQuery()
            .forRevisionsOfEntity(BuildConfiguration.class, false, false)
            .add(disjunction)
            .addOrder(AuditEntity.revisionNumber().desc())
            .getResultList();

    return result.stream().map(o -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) o[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) o[1];
        return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
    }).collect(Collectors.toList());
}
 
源代码3 项目: mojito   文件: CurrentVariantRollbackService.java
/**
 * 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;
}
 
源代码4 项目: HibernateDemos   文件: EnversDemo.java
public List getProjectRevisions(String property) {
	final Session s = openSession();
	final AuditReader ar = AuditReaderFactory.get( s );
	return ar.createQuery()
		    .forRevisionsOfEntity(Project.class, false, true)
		    .add(AuditEntity.property(property).hasChanged())
		    .getResultList();
}
 
源代码5 项目: pnc   文件: ArtifactAuditedRepositoryImpl.java
@Override
public List<ArtifactAudited> findAllByIdOrderByRevDesc(Integer artifactId) {

    List<Object[]> result = AuditReaderFactory.get(entityManager)
            .createQuery()
            .forRevisionsOfEntity(Artifact.class, false, false)
            .add(AuditEntity.id().eq(artifactId))
            .addOrder(AuditEntity.revisionNumber().desc())
            .getResultList();

    return result.stream().map(o -> createAudited(o[0], o[1])).collect(Collectors.toList());
}
 
@Override
public List<BuildConfigurationAudited> findAllByIdOrderByRevDesc(Integer buildConfigurationId) {

    List<Object[]> result = AuditReaderFactory.get(entityManager)
            .createQuery()
            .forRevisionsOfEntity(BuildConfiguration.class, false, false)
            .add(AuditEntity.id().eq(buildConfigurationId))
            .addOrder(AuditEntity.revisionNumber().desc())
            .getResultList();

    return result.stream().map(o -> createAudited(o[0], o[1])).collect(Collectors.toList());
}
 
@Override
public List<BuildConfigurationAudited> searchForBuildConfigurationName(String buildConfigurationName) {
    List<Object[]> result = AuditReaderFactory.get(entityManager)
            .createQuery()
            .forRevisionsOfEntity(BuildConfiguration.class, false, false)
            .add(AuditEntity.property("name").like(buildConfigurationName))
            .addOrder(AuditEntity.revisionNumber().desc())
            .getResultList();
    return result.stream().map(o -> createAudited(o[0], o[1])).collect(Collectors.toList());
}
 
@Override
public List<IdRev> searchIdRevForBuildConfigurationName(String buildConfigurationName) {
    List<Object[]> result = AuditReaderFactory.get(entityManager)
            .createQuery()
            .forRevisionsOfEntity(BuildConfiguration.class, false, false)
            .add(AuditEntity.property("name").like(buildConfigurationName))
            .addOrder(AuditEntity.revisionNumber().desc())
            .getResultList();

    return result.stream().map(o -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) o[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) o[1];
        return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
    }).collect(Collectors.toList());
}
 
@Override
public List<IdRev> searchIdRevForProjectId(Integer projectId) {
    List<Object[]> result = AuditReaderFactory.get(entityManager)
            .createQuery()
            .forRevisionsOfEntity(BuildConfiguration.class, false, false)
            .add(AuditEntity.relatedId("project").eq(projectId))
            .addOrder(AuditEntity.revisionNumber().desc())
            .getResultList();

    return result.stream().map(o -> {
        BuildConfiguration buildConfiguration = (BuildConfiguration) o[0];
        DefaultRevisionEntity revisionEntity = (DefaultRevisionEntity) o[1];
        return new IdRev(buildConfiguration.getId(), revisionEntity.getId());
    }).collect(Collectors.toList());
}
 
源代码10 项目: pnc   文件: BuildConfigurationTest.java
private BuildConfiguration getByIdRev(Integer buildConfigurationId, Integer revision) {
    return (BuildConfiguration) AuditReaderFactory.get(em)
            .createQuery()
            .forEntitiesAtRevision(BuildConfiguration.class, revision)
            .add(AuditEntity.id().eq(buildConfigurationId))
            .addOrder(AuditEntity.revisionNumber().desc())
            .getSingleResult();
}
 
源代码11 项目: pnc   文件: BasicModelTest.java
private BuildConfigurationAudited findBuildConfigurationAudited(EntityManager em) {
    List<Object[]> result = AuditReaderFactory.get(em)
            .createQuery()
            .forRevisionsOfEntity(BuildConfiguration.class, false, false)
            .addOrder(AuditEntity.revisionNumber().desc())
            .getResultList();

    Object[] second = result.get(1);
    BuildConfiguration buildConfiguration = (BuildConfiguration) second[0];
    return BuildConfigurationAudited
            .fromBuildConfiguration(buildConfiguration, ((DefaultRevisionEntity) second[1]).getId());
}
 
源代码12 项目: ankush   文件: ConfigurationManager.java
/**
 * Gets the configuration.
 * 
 * @param clusterId
 *            the cluster id
 * @return the configuration
 */
public List getConfiguration(Long clusterId) {
	try {
		AuditReader reader = AuditReaderFactory.get(HibernateUtils
				.getEntityManager());
		AuditQuery query = reader.createQuery().forRevisionsOfEntity(
				Configuration.class, false, true);

		// filter results besed on cluster id.
		query.add(AuditEntity.property(
				com.impetus.ankush2.constant.Constant.Keys.CLUSTERID).eq(
				clusterId));
		query.addOrder(AuditEntity.revisionProperty(
				com.impetus.ankush2.constant.Constant.Keys.TIMESTAMP)
				.desc());

		// Getting Result list.
		List list = query.getResultList();

		// Creating List Object.
		List result = new ArrayList();
		for (Object object : list) {
			Object[] obj = (Object[]) object;
			Map map = new HashMap();
			// Mapping Revision Entity.
			DefaultRevisionEntity ri = (DefaultRevisionEntity) obj[1];
			map.putAll(JsonMapperUtil.mapFromObject(obj[0]));
			map.put(com.impetus.ankush2.constant.Constant.Keys.DATE,
					ri.getRevisionDate());
			map.put(com.impetus.ankush2.constant.Constant.Keys.REVISIONID,
					ri.getId());
			map.put(com.impetus.ankush2.constant.Constant.Keys.TYPE, obj[2]);
			result.add(map);
		}
		return result;
	} catch (Exception e) {
		LOG.error(e.getMessage(), e);
	}
	return null;

}
 
源代码13 项目: hibernate-demos   文件: EnversDemo.java
public List getProjectRevisions(String property) {
	final Session s = openSession();
	final AuditReader ar = AuditReaderFactory.get( s );
	return ar.createQuery()
		    .forRevisionsOfEntity(Project.class, false, true)
		    .add(AuditEntity.property(property).hasChanged())
		    .getResultList();
}
 
 类所在包
 同包方法