Example usage for org.hibernate.criterion Projections projectionList

List of usage examples for org.hibernate.criterion Projections projectionList

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections projectionList.

Prototype

public static ProjectionList projectionList() 

Source Link

Document

Create a new projection list.

Usage

From source file:com.romeikat.datamessie.core.base.dao.impl.CrawlingDao.java

License:Open Source License

public List<CrawlingDto> getAsDtos(final SharedSessionContract ssc, final Long projectId) {
    // Query: Crawling
    final EntityWithIdQuery<Crawling> crawlingQuery = new EntityWithIdQuery<>(Crawling.class);
    crawlingQuery.addRestriction(Restrictions.eqOrIsNull("projectId", projectId));
    crawlingQuery.addOrder(Order.desc("started"));
    crawlingQuery.setResultTransformer(new AliasToBeanResultTransformer(CrawlingDto.class));

    // Done//from w ww.  jav a2 s  . c  om
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("id"), "id");
    projectionList.add(Projections.property("started"), "started");
    projectionList.add(Projections.property("completed"), "completed");
    @SuppressWarnings("unchecked")
    final List<CrawlingDto> dtos = (List<CrawlingDto>) crawlingQuery.listForProjection(ssc, projectionList);

    // Set duration
    setDurationForDtos(dtos);

    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.CrawlingDao.java

License:Open Source License

public List<CrawlingOverviewDto> getAsOverviewDtos(final SharedSessionContract ssc, final Long projectId,
        final Long first, final Long count) {
    // Query: Crawling
    final EntityWithIdQuery<Crawling> crawlingQuery = new EntityWithIdQuery<>(Crawling.class);
    crawlingQuery.addRestriction(Restrictions.eqOrIsNull("projectId", projectId));
    crawlingQuery.setFirstResult(first == null ? null : first.intValue());
    crawlingQuery.setMaxResults(count == null ? null : count.intValue());
    crawlingQuery.addOrder(Order.desc("started"));
    crawlingQuery.setResultTransformer(new AliasToBeanResultTransformer(CrawlingOverviewDto.class));

    // Done/*ww w.j av  a 2s.c  o  m*/
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("id"), "id");
    projectionList.add(Projections.property("started"), "started");
    projectionList.add(Projections.property("completed"), "completed");
    @SuppressWarnings("unchecked")
    final List<CrawlingOverviewDto> dtos = (List<CrawlingOverviewDto>) crawlingQuery.listForProjection(ssc,
            projectionList);

    // Set duration
    setDurationForOverviewDtos(dtos);

    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.ProjectDao.java

License:Open Source License

public List<ProjectDto> getAllAsDtos(final SharedSessionContract ssc, final Long userId) {
    // Restrict to user
    final Collection<Long> projectIdsForUser = getIdsForUser(ssc, userId);
    if (projectIdsForUser.isEmpty()) {
        return Collections.emptyList();
    }//from  w ww  .  j ava 2 s  .  c om

    // Query: Project
    final EntityWithIdQuery<Project> projectQuery = new EntityWithIdQuery<>(Project.class);
    projectQuery.addIdRestriction(projectIdsForUser);
    projectQuery.addOrder(Order.asc("name"));
    projectQuery.setResultTransformer(new AliasToBeanResultTransformer(ProjectDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("name"), "name");
    projectionList.add(Projections.property("crawlingEnabled"), "crawlingEnabled");
    projectionList.add(Projections.property("crawlingInterval"), "crawlingInterval");
    projectionList.add(Projections.property("preprocessingEnabled"), "preprocessingEnabled");
    @SuppressWarnings("unchecked")
    final List<ProjectDto> dtos = (List<ProjectDto>) projectQuery.listForProjection(ssc, projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.ProjectDao.java

License:Open Source License

public ProjectDto getAsDto(final SharedSessionContract ssc, final long projectId, final Long userId) {
    // Restrict to user
    final Collection<Long> projectIdsForUser = getIdsForUser(ssc, userId);
    if (projectIdsForUser.isEmpty()) {
        return null;
    }//from w  w w  .j a  v a 2s.co  m

    // Query: Project
    final EntityWithIdQuery<Project> projectQuery = new EntityWithIdQuery<>(Project.class);
    projectQuery.addRestriction(Restrictions.idEq(projectId));
    projectQuery.addIdRestriction(projectIdsForUser);
    projectQuery.addOrder(Order.desc("started"));
    projectQuery.setResultTransformer(new AliasToBeanResultTransformer(ProjectDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("name"), "name");
    projectionList.add(Projections.property("crawlingEnabled"), "crawlingEnabled");
    projectionList.add(Projections.property("crawlingInterval"), "crawlingInterval");
    projectionList.add(Projections.property("preprocessingEnabled"), "preprocessingEnabled");
    final ProjectDto dto = (ProjectDto) projectQuery.uniqueForProjection(ssc, projectionList);
    return dto;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.RedirectingRuleDao.java

License:Open Source License

public List<RedirectingRuleDto> getAsDtos(final SharedSessionContract ssc, final long sourceId) {
    // Query: RedirectingRule
    final EntityWithIdQuery<RedirectingRule> redirectingRuleQuery = new EntityWithIdQuery<>(
            RedirectingRule.class);
    redirectingRuleQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    redirectingRuleQuery.addOrder(Order.asc("activeFrom"));
    redirectingRuleQuery.setResultTransformer(new AliasToBeanResultTransformer(RedirectingRuleDto.class));

    // Done/*www .j  a va2  s  .  co m*/
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("regex"), "regex");
    projectionList.add(Projections.property("regexGroup"), "regexGroup");
    projectionList.add(Projections.property("activeFrom"), "activeFrom");
    projectionList.add(Projections.property("activeTo"), "activeTo");
    @SuppressWarnings("unchecked")
    final List<RedirectingRuleDto> dtos = (List<RedirectingRuleDto>) redirectingRuleQuery.listForProjection(ssc,
            projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.SourceTypeDao.java

License:Open Source License

public List<SourceTypeDto> getAsDtos(final SharedSessionContract ssc) {
    // Query: SourceType
    final EntityWithIdQuery<SourceType> sourceQuery = new EntityWithIdQuery<>(SourceType.class);
    sourceQuery.addOrder(Order.asc("name"));
    sourceQuery.setResultTransformer(new AliasToBeanResultTransformer(SourceTypeDto.class));

    // Done//from   w  w w. j  a va 2 s  . c o m
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("name"), "name");
    @SuppressWarnings("unchecked")
    final List<SourceTypeDto> dtos = (List<SourceTypeDto>) sourceQuery.listForProjection(ssc, projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.SourceTypeDao.java

License:Open Source License

public List<SourceTypeDto> getAsDtos(final SharedSessionContract ssc, final long sourceId) {
    // Query: Source2SourceType
    final EntityQuery<Source2SourceType> project2SourceQuery = new EntityQuery<>(Source2SourceType.class);
    project2SourceQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    final List<Long> sourceTypeIds = project2SourceQuery.listIdsForProperty(ssc, "sourceTypeId");
    if (sourceTypeIds.isEmpty()) {
        return Collections.emptyList();
    }//w w  w.  ja v a 2  s.  c o  m

    // Query: SourceType
    final EntityQuery<SourceType> sourceTypeQuery = new EntityQuery<>(SourceType.class);
    sourceTypeQuery.addRestriction(Restrictions.in("id", sourceTypeIds));
    sourceTypeQuery.addOrder(Order.asc("name"));
    sourceTypeQuery.setResultTransformer(new AliasToBeanResultTransformer(SourceTypeDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("name"), "name");
    @SuppressWarnings("unchecked")
    final List<SourceTypeDto> dtos = (List<SourceTypeDto>) sourceTypeQuery.listForProjection(ssc,
            projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.TagSelectingRuleDao.java

License:Open Source License

public List<TagSelectingRuleDto> getAsDtos(final SharedSessionContract ssc, final long sourceId) {
    // Query: TagSelectingRule
    final EntityWithIdQuery<TagSelectingRule> tagSelectingRuleQuery = new EntityWithIdQuery<>(
            TagSelectingRule.class);
    tagSelectingRuleQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    tagSelectingRuleQuery.addOrder(Order.asc("activeFrom"));
    tagSelectingRuleQuery.setResultTransformer(new AliasToBeanResultTransformer(TagSelectingRuleDto.class));

    // Done//  ww  w  .j  a  v  a 2  s  .c om
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("tagSelector"), "tagSelector");
    projectionList.add(Projections.property("activeFrom"), "activeFrom");
    projectionList.add(Projections.property("activeTo"), "activeTo");
    @SuppressWarnings("unchecked")
    final List<TagSelectingRuleDto> dtos = (List<TagSelectingRuleDto>) tagSelectingRuleQuery
            .listForProjection(ssc, projectionList);
    return dtos;
}

From source file:com.romeikat.datamessie.core.base.service.SourceService.java

License:Open Source License

public String getNewName(final SharedSessionContract ssc) {
    // Get all names
    final EntityWithIdQuery<Source> sourceQuery = new EntityWithIdQuery<>(Source.class);
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("name"), "name");
    final List<String> names = (List<String>) sourceQuery.listForProjection(ssc, projectionList);

    // Determine new name
    int counter = 1;
    while (true) {
        final String candidateName = "New source #" + counter;
        if (!stringUtil.containsIgnoreCase(names, candidateName)) {
            return candidateName;
        } else {// w  w  w.  j a  v a  2 s.c  om
            counter++;
        }
    }
}

From source file:com.romeikat.datamessie.core.statistics.dao.DocumentDao.java

License:Open Source License

public List<DocumentStatisticsDto> getAsDocumentStatisticsDtos(final SharedSessionContract ssc,
        final Long sourceId, final LocalDate published) {
    final LocalDateTime minPublished = published == null ? null
            : LocalDateTime.of(published, LocalTime.MIDNIGHT);
    final LocalDateTime maxPublished = published == null ? null
            : LocalDateTime.of(published.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    if (sourceId != null) {
        documentQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    }//from  www.  j a  v a2  s.c  om
    if (minPublished != null) {
        documentQuery.addRestriction(Restrictions.ge("published", minPublished));
    }
    if (maxPublished != null) {
        documentQuery.addRestriction(Restrictions.lt("published", maxPublished));
    }
    documentQuery.setResultTransformer(new AliasToBeanResultTransformer(DocumentStatisticsDto.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "documentId");
    projectionList.add(Projections.property("sourceId"), "sourceId");
    projectionList.add(Projections.property("published"), "published");
    projectionList.add(Projections.property("state"), "state");
    @SuppressWarnings("unchecked")
    final List<DocumentStatisticsDto> dtos = (List<DocumentStatisticsDto>) documentQuery.listForProjection(ssc,
            projectionList);
    return dtos;
}