List of usage examples for org.hibernate.envers AuditReader createQuery
AuditQueryCreator createQuery();
From source file:org.jboss.pressgang.ccms.filter.utils.EntityUtilities.java
License:Open Source License
@SuppressWarnings("unchecked") public static <T extends AuditedEntity> List<Integer> getEditedBy(final EntityManager entityManager, final Class<T> clazz, final String idName, final String username) { final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQuery query = reader.createQuery().forRevisionsOfEntity(clazz, true, false) .addProjection(AuditEntity.property("originalId." + idName).distinct()) .add(AuditEntity.revisionProperty("userName").eq(username)) .add(AuditEntity.revisionType().eq(RevisionType.MOD)); return query.getResultList(); }
From source file:org.jboss.pressgang.ccms.model.contentspec.ContentSpecToPropertyTag.java
License:Open Source License
@Override protected boolean testUnique(final EntityManager entityManager, final Number revision) { if (propertyTag.getPropertyTagIsUnique()) { /*/* w w w.j a v a2s . c o m*/ * Since having to iterate over thousands of entities is slow, use a HQL query to find the count for us. */ final Long count; if (revision == null) { final String query = ContentSpecToPropertyTag.SELECT_SIZE_QUERY + " WHERE contentSpecToPropertyTag.propertyTag" + ".propertyTagId = :propertyTagId AND contentSpecToPropertyTag.value = :value"; final Query entityQuery = entityManager.createQuery(query); entityQuery.setParameter("value", getValue()); entityQuery.setParameter("propertyTagId", getPropertyTag().getId()); count = (Long) entityQuery.getSingleResult(); } else { final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQueryCreator queryCreator = reader.createQuery(); final AuditQuery query = queryCreator .forEntitiesAtRevision(ContentSpecToPropertyTag.class, revision) .addProjection(AuditEntity.id().count("contentSpecToPropertyTagId")) .add(AuditEntity.relatedId("propertyTag").eq(getPropertyTag().getId())) .add(AuditEntity.property("value").eq(getValue())); query.setCacheable(true); count = (Long) query.getSingleResult(); } if (count > 1) return false; } return true; }
From source file:org.jboss.pressgang.ccms.model.contentspec.CSNodeToPropertyTag.java
License:Open Source License
@Override protected boolean testUnique(final EntityManager entityManager, final Number revision) { if (propertyTag.getPropertyTagIsUnique()) { /*/*w w w. j a v a2 s . co m*/ * Since having to iterate over thousands of entities is slow, use a HQL query to find the count for us. */ final Long count; if (revision == null) { final String query = CSNodeToPropertyTag.SELECT_SIZE_QUERY + " WHERE csNodeToPropertyTag.propertyTag = :propertyTagId AND" + " csNodeToPropertyTag.value = :value"; final Query entityQuery = entityManager.createQuery(query); entityQuery.setParameter("value", getValue()); entityQuery.setParameter("propertyTagId", getPropertyTag().getId()); count = (Long) entityQuery.getSingleResult(); } else { final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQueryCreator queryCreator = reader.createQuery(); final AuditQuery query = queryCreator.forEntitiesAtRevision(CSNodeToPropertyTag.class, revision) .addProjection(AuditEntity.id().count("csNodeToPropertyTagId")) .add(AuditEntity.relatedId("propertyTag").eq(getPropertyTag().getId())) .add(AuditEntity.property("value").eq(getValue())); query.setCacheable(true); count = (Long) query.getSingleResult(); } if (count > 1) return false; } return true; }
From source file:org.jboss.pressgang.ccms.model.contentspec.TranslatedContentSpec.java
License:Open Source License
@Transient public ContentSpec getEnversContentSpec(final EntityManager entityManager) { if (enversContentSpec == null) { /* Find the envers contentSpec */ final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQuery query = reader.createQuery() .forEntitiesAtRevision(ContentSpec.class, contentSpecRevision) .add(AuditEntity.id().eq(contentSpecId)); enversContentSpec = (ContentSpec) query.getSingleResult(); }/*from w ww . ja va 2s.co m*/ return enversContentSpec; }
From source file:org.jboss.pressgang.ccms.model.contentspec.TranslatedCSNode.java
License:Open Source License
@Transient public CSNode getEnversCSNode(final EntityManager entityManager) { if (enversCSNode == null) { /* Find the envers topic */ final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQuery query = reader.createQuery() .forEntitiesAtRevision(CSNode.class, contentSpecNodeRevision) .add(AuditEntity.id().eq(contentSpecNodeId)); enversCSNode = (CSNode) query.getSingleResult(); }/*from ww w .j a v a2 s .c o m*/ return enversCSNode; }
From source file:org.jboss.pressgang.ccms.model.TagToPropertyTag.java
License:Open Source License
@Override protected boolean testUnique(final EntityManager entityManager, final Number revision) { if (propertyTag.getPropertyTagIsUnique()) { /*//from w w w . j av a 2s .c o m * Since having to iterate over thousands of entities is slow, use a HQL query for the latest versions, for * revisions though we still have to do it the slow way since we don't know the revision number. */ final Long count; if (revision == null) { final String query = TagToPropertyTag.SELECT_SIZE_QUERY + " WHERE tagToPropertyTag.propertyTag.propertyTagId = " + ":propertyTagId AND tagToPropertyTag.value = :value"; final Query entityQuery = entityManager.createQuery(query); entityQuery.setParameter("value", getValue()); entityQuery.setParameter("propertyTagId", getPropertyTag().getId()); count = (Long) entityQuery.getSingleResult(); } else { final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQueryCreator queryCreator = reader.createQuery(); final AuditQuery query = queryCreator.forEntitiesAtRevision(TagToPropertyTag.class, revision) .addProjection(AuditEntity.id().count("tagToPropertyTagID")) .add(AuditEntity.relatedId("propertyTag").eq(propertyTag.getId())) .add(AuditEntity.property("value").eq(getValue())); count = (Long) query.getSingleResult(); } if (count > 1) return false; } return true; }
From source file:org.jboss.pressgang.ccms.model.TopicToPropertyTag.java
License:Open Source License
@Override protected boolean testUnique(final EntityManager entityManager, final Number revision) { if (propertyTag.getPropertyTagIsUnique()) { /*/*from w w w .j a va 2 s . c om*/ * Since having to iterate over thousands of entities is slow, use a HQL query to find the count for us. */ final Long count; if (revision == null) { final String query = TopicToPropertyTag.SELECT_SIZE_QUERY + " WHERE topicToPropertyTag.propertyTag.propertyTagId = " + ":propertyTagId AND topicToPropertyTag.value = :value"; final Query entityQuery = entityManager.createQuery(query); entityQuery.setParameter("value", getValue()); entityQuery.setParameter("propertyTagId", getPropertyTag().getId()); count = (Long) entityQuery.getSingleResult(); } else { final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQueryCreator queryCreator = reader.createQuery(); final AuditQuery query = queryCreator.forEntitiesAtRevision(TopicToPropertyTag.class, revision) .addProjection(AuditEntity.id().count("topicToPropertyTagID")) .add(AuditEntity.relatedId("propertyTag").eq(getPropertyTag().getId())) .add(AuditEntity.property("value").eq(getValue())); query.setCacheable(true); count = (Long) query.getSingleResult(); } if (count > 1) return false; } return true; }
From source file:org.jboss.pressgang.ccms.model.TranslatedTopic.java
License:Open Source License
@Transient public Topic getEnversTopic(final EntityManager entityManager) { if (enversTopic == null) { /* Find the envers topic */ final AuditReader reader = AuditReaderFactory.get(entityManager); final AuditQuery query = reader.createQuery().forEntitiesAtRevision(Topic.class, topicRevision) .add(AuditEntity.id().eq(topicId)); enversTopic = (Topic) query.getSingleResult(); }// w w w .ja v a 2 s .c o m return enversTopic; }
From source file:org.jboss.pressgang.ccms.model.utils.EnversUtilities.java
License:Open Source License
public static <T extends AuditedEntity> Number getClosestRevision(final AuditReader reader, final Class<T> entityClass, final Integer id, final Number revision) { // Find the closest revision that is less than or equal to the revision specified. final Number closestRevision = (Number) reader.createQuery().forRevisionsOfEntity(entityClass, false, true) .addProjection(AuditEntity.revisionNumber().max()).add(AuditEntity.id().eq(id)) .add(AuditEntity.revisionNumber().le(revision)).getSingleResult(); return closestRevision; }
From source file:org.tomitribe.tribestream.registryng.repository.Repository.java
License:Apache License
public <T> List<HistoryEntry<T>> getRevisions(final Class<T> entityClass, final String id, final int first, final int pageSize) throws NoResultException { AuditReader auditReader = AuditReaderFactory.get(em); AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(entityClass, false, true); query.add(AuditEntity.id().eq(id));// ww w.j a va 2 s. com query.addOrder(AuditEntity.revisionNumber().desc()); query.setFirstResult(first).setMaxResults(pageSize); List<Object[]> objects = query.getResultList(); return objects.stream().map(HistoryEntry<T>::new).collect(toList()); }