Search in sources :

Example 1 with BuildRecord_

use of org.jboss.pnc.model.BuildRecord_ in project pnc by project-ncl.

the class BuildConfigurationAuditedRepositoryImpl method getBuildRecords.

/**
 * @param buildConfigurationId
 * @return List of BuildRecords where only id is fetched
 */
private List<BuildRecord> getBuildRecords(Integer buildConfigurationId) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Base32LongID> query = cb.createQuery(Base32LongID.class);
    Root<BuildRecord> root = query.from(BuildRecord.class);
    query.select(root.get(BuildRecord_.id));
    query.where(cb.equal(root.get(BuildRecord_.buildConfigurationId), buildConfigurationId));
    List<Base32LongID> buildRecordIds = entityManager.createQuery(query).getResultList();
    return buildRecordIds.stream().map(id -> BuildRecord.Builder.newBuilder().id(id).build()).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) Project(org.jboss.pnc.model.Project) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Logger(org.slf4j.Logger) BuildRecord_(org.jboss.pnc.model.BuildRecord_) Set(java.util.Set) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) AuditReaderFactory(org.hibernate.envers.AuditReaderFactory) AuditEntity(org.hibernate.envers.query.AuditEntity) Base32LongID(org.jboss.pnc.model.Base32LongID) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 2 with BuildRecord_

use of org.jboss.pnc.model.BuildRecord_ in project pnc by project-ncl.

the class BuildConfigurationAuditedRepositoryImpl method getBuildRecords.

/**
 * @param idRev
 * @return List of BuildRecords where only id is fetched
 */
private List<BuildRecord> getBuildRecords(IdRev idRev) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<Base32LongID> query = cb.createQuery(Base32LongID.class);
    Root<BuildRecord> root = query.from(BuildRecord.class);
    query.select(root.get(BuildRecord_.id));
    query.where(cb.and(cb.equal(root.get(BuildRecord_.buildConfigurationId), idRev.getId()), cb.equal(root.get(BuildRecord_.buildConfigurationRev), idRev.getRev())));
    List<Base32LongID> buildRecordIds = entityManager.createQuery(query).getResultList();
    return buildRecordIds.stream().map(id -> BuildRecord.Builder.newBuilder().id(id).build()).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) DefaultRevisionEntity(org.hibernate.envers.DefaultRevisionEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) Project(org.jboss.pnc.model.Project) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Logger(org.slf4j.Logger) BuildRecord_(org.jboss.pnc.model.BuildRecord_) Set(java.util.Set) BuildRecord(org.jboss.pnc.model.BuildRecord) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) IdRev(org.jboss.pnc.model.IdRev) List(java.util.List) AuditReaderFactory(org.hibernate.envers.AuditReaderFactory) AuditEntity(org.hibernate.envers.query.AuditEntity) Base32LongID(org.jboss.pnc.model.Base32LongID) Base32LongID(org.jboss.pnc.model.Base32LongID) BuildRecord(org.jboss.pnc.model.BuildRecord)

Aggregations

List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stateless (javax.ejb.Stateless)2 Inject (javax.inject.Inject)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)2 Root (javax.persistence.criteria.Root)2 AuditReaderFactory (org.hibernate.envers.AuditReaderFactory)2 DefaultRevisionEntity (org.hibernate.envers.DefaultRevisionEntity)2 AuditEntity (org.hibernate.envers.query.AuditEntity)2 AuditDisjunction (org.hibernate.envers.query.criteria.AuditDisjunction)2 Base32LongID (org.jboss.pnc.model.Base32LongID)2 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)2 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)2 BuildRecord (org.jboss.pnc.model.BuildRecord)2 BuildRecord_ (org.jboss.pnc.model.BuildRecord_)2 IdRev (org.jboss.pnc.model.IdRev)2