List of usage examples for org.hibernate.envers.query AuditQueryCreator forEntitiesAtRevision
public AuditQuery forEntitiesAtRevision(Class<?> c, Number revision)
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()) { /*/*from ww w.j ava 2s . 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()) { /*/*from ww w. j a va 2 s. 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 = 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.TagToPropertyTag.java
License:Open Source License
@Override protected boolean testUnique(final EntityManager entityManager, final Number revision) { if (propertyTag.getPropertyTagIsUnique()) { /*/* w ww .ja va2 s .co 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 ww w. jav a 2s . 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 = 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; }