List of usage examples for org.hibernate.envers AuditReaderFactory get
public static AuditReader get(EntityManager entityManager) throws AuditException
From source file:org.jboss.pressgang.ccms.filter.utils.EntityUtilities.java
License:Open Source License
@SuppressWarnings("unchecked") public static <T extends AuditedEntity> List<Integer> getCreatedBy(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.ADD)); return query.getResultList(); }
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()) { /*// ww w.jav 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 = 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()) { /*//from www. j a va 2 s . com * 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 . j av a 2 s . c o 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 www.j a v a 2 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()) { /*// w ww . j a va 2s.c om * 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 ww w .java 2 s.com*/ * 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 . j a va 2s .c om*/ return enversTopic; }
From source file:org.jboss.pressgang.ccms.model.utils.EnversUtilities.java
License:Open Source License
/** * @return Returns the latest Envers revision number *//*from w w w. j ava2s . co m*/ public static <T extends AuditedEntity> Date getLatestRevisionDate(final EntityManager entityManager, final T entity) { final AuditReader reader = AuditReaderFactory.get(entityManager); return reader.getRevisionDate(getLatestRevision(entityManager, entity)); }