List of usage examples for org.hibernate.envers.query AuditEntity relatedId
public static AuditRelatedId relatedId(String propertyName)
From source file:com.confighub.core.store.Store.java
License:Open Source License
public Pair<PropertyKey, Collection<Property>> getPropertiesForKey(final Repository repository, final Date date, String key) throws ConfigException { AuditReader reader = AuditReaderFactory.get(em); Number rev = reader.getRevisionNumberForDate(null == date ? new Date() : date); AuditQuery kq = reader.createQuery().forEntitiesAtRevision(PropertyKey.class, rev); kq.add(AuditEntity.property("repository").eq(repository)); kq.add(AuditEntity.property("key").eq(key)); PropertyKey propertyKey;// ww w.j ava 2 s. co m try { propertyKey = (PropertyKey) kq.getSingleResult(); } catch (NoResultException e) { return null; } AuditQuery query = reader.createQuery().forEntitiesAtRevision(Property.class, rev); query.add(AuditEntity.property("repository").eq(repository)); query.add(AuditEntity.relatedId("propertyKey").eq(propertyKey.getId())); Collection<Property> properties = query.getResultList(); propertyKey.propertyCount = properties.size(); return new Pair(propertyKey, properties); }
From source file:fr.mcc.ginco.audit.utils.AuditHelper.java
License:CeCILL license
/** * Gets the preferred term of the given concept at the given revision * @param revisionNumber//from w w w . j a v a 2 s . com * @param conceptId * @param lang * @return */ public ThesaurusTerm getPreferredTermAtRevision(Number revisionNumber, String conceptId, String lang) { AuditQuery query = reader.getAuditReader().createQuery() .forEntitiesAtRevision(ThesaurusTerm.class, revisionNumber) .add(AuditEntity.relatedId("concept").eq(conceptId)).add(AuditEntity.property("prefered").eq(true)) .addOrder(AuditEntity.revisionNumber().desc()).setMaxResults(1); if (lang != null) { auditQueryBuilder.addFilterOnLanguage(query, lang); } List results = query.getResultList(); if (results.isEmpty()) { return null; } else { return (ThesaurusTerm) results.get(0); } }
From source file:fr.mcc.ginco.audit.utils.AuditHelper.java
License:CeCILL license
/** * /*from w ww . j a v a2 s . c o m*/ * Gets the list of ThesaurusConcept revisions where parent id is the conceptId * @param revisionNumber * @param conceptId * @return */ public List<ThesaurusConcept> getConceptChildrenAtRevision(Number revisionNumber, ThesaurusConcept concept, List<ThesaurusConcept> allThesaurusConcepts) { //This type of relation is not supported by Envers yet //AuditQuery query = reader.getAuditReader().createQuery().forEntitiesAtRevision(ThesaurusConcept.class, revisionNumber) // .add(AuditEntity.relatedId("parentConcepts").eq(conceptId)); List<ThesaurusConcept> childrenConceptAtRevision = new ArrayList<ThesaurusConcept>(); if (allThesaurusConcepts.size() == 0) { AuditQuery query = reader.getAuditReader().createQuery() .forEntitiesAtRevision(ThesaurusConcept.class, revisionNumber) .add(AuditEntity.relatedId("thesaurus").eq(concept.getThesaurus().getIdentifier())); allThesaurusConcepts.addAll(query.getResultList()); } for (ThesaurusConcept curConcept : allThesaurusConcepts) { if (curConcept.getParentConcepts().contains(concept)) { childrenConceptAtRevision.add(curConcept); } } return childrenConceptAtRevision; }
From source file:fr.mcc.ginco.audit.utils.AuditHelper.java
License:CeCILL license
public List<ThesaurusTerm> getConceptTermsAtRevision(ThesaurusConcept conceptAtRevision, Number revision, String lang) {/* ww w.j a v a2 s . c o m*/ AuditQuery query = reader.getAuditReader().createQuery() .forEntitiesAtRevision(ThesaurusTerm.class, revision) .add(AuditEntity.relatedId("concept").eq(conceptAtRevision.getIdentifier())); if (lang != null) { auditQueryBuilder.addFilterOnLanguage(query, lang); } return query.getResultList(); }
From source file:fr.mcc.ginco.audit.utils.AuditQueryBuilder.java
License:CeCILL license
/** * @param reader/* ww w . j a v a2 s. c o m*/ * @param clazz * @param identifier * @param currentRevision * @return */ public AuditQuery getPreviousPreferredTermQuery(int currentRevision, String conceptId) { return readerService.getAuditReader().createQuery().forRevisionsOfEntity(ThesaurusTerm.class, false, true) .add(AuditEntity.revisionNumber().lt(currentRevision)) .add(AuditEntity.property("prefered").eq(true)).add(AuditEntity.relatedId("concept").eq(conceptId)); }
From source file:fr.mcc.ginco.audit.utils.AuditQueryBuilder.java
License:CeCILL license
/** * Adds a filter on the "language" property to the query * //from w w w. ja v a 2 s .c o m * @param query * the original query * @param lang * the language value to filter on */ public void addFilterOnLanguage(AuditQuery query, String languageId) { query.add(AuditEntity.relatedId("language").eq(languageId)); }
From source file:org.jboss.pnc.rest.provider.BuildRecordProvider.java
License:Open Source License
public CollectionInfo<BuildRecordRest> getAllForProject(int pageIndex, int pageSize, String sortingRsql, String query, Integer projectId) { List<Object[]> buildConfigurationRevisions = AuditReaderFactory.get(entityManager).createQuery() .forRevisionsOfEntity(BuildConfiguration.class, false, false) .add(AuditEntity.relatedId("project").eq(projectId)).addOrder(AuditEntity.revisionNumber().desc()) .getResultList();/*from w ww . j a v a2 s . c o m*/ return queryForBuildRecords(pageIndex, pageSize, sortingRsql, query, buildConfigurationRevisions); }
From source file:org.jboss.pnc.rest.provider.BuildRecordProvider.java
License:Open Source License
public CollectionInfo<BuildRecordRest> getAllForConfigurationOrProjectName(int pageIndex, int pageSize, String sortingRsql, String query, String name) { List<Project> projectsMatchingName = projectRepository .queryWithPredicates(ProjectPredicates.searchByProjectName(name)); AuditDisjunction disjunction = AuditEntity.disjunction(); projectsMatchingName.forEach(project -> { disjunction.add(AuditEntity.relatedId("project").eq(project.getId())); });//from ww w . j a va 2 s . c om disjunction.add(AuditEntity.property("name").like(name)); List<Object[]> buildConfigurationRevisions = AuditReaderFactory.get(entityManager).createQuery() .forRevisionsOfEntity(BuildConfiguration.class, false, false).add(disjunction) .addOrder(AuditEntity.revisionNumber().desc()).getResultList(); return queryForBuildRecords(pageIndex, pageSize, sortingRsql, query, buildConfigurationRevisions); }
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 w w w. ja va2 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()) { /*/* ww w . ja va 2 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; }