Example usage for org.hibernate.criterion Restrictions ge

List of usage examples for org.hibernate.criterion Restrictions ge

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ge.

Prototype

public static SimpleExpression ge(String propertyName, Object value) 

Source Link

Document

Apply a "greater than or equal" constraint to the named property

Usage

From source file:com.registryKit.survey.surveyDAO.java

/**
 * The 'getSurveyQuestions' function will return the questions associated with the survey
 * /*  w  w  w . jav  a 2  s.  c o  m*/
 * @param surveyPageId  The id for the current page
 * @return
 * @throws Exception 
 */
@SuppressWarnings("unchecked")
public List<SurveyQuestions> getSurveyQuestions(Integer surveyPageId, Integer goToQuestion,
        Integer completedSurveyId) throws Exception {

    List<SurveyQuestions> surveyQuestions = null;

    if (completedSurveyId > 0) {
        Query query = sessionFactory.getCurrentSession().createSQLQuery(
                "SELECT * from survey_questions where surveyPageId = :surveyPageId and survey_questions.id in (select questionId from patient_completedSurveyAnswers where completedSurveyid = :completedSurveyId) order by questionNum")
                .setParameter("surveyPageId", surveyPageId)
                .setParameter("completedSurveyId", completedSurveyId);

        query.setResultTransformer(Transformers.aliasToBean(SurveyQuestions.class));

        surveyQuestions = query.list();

    } else {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SurveyQuestions.class);
        criteria.add(Restrictions.eq("surveyPageId", surveyPageId));
        criteria.add(Restrictions.eq("deleted", false));
        criteria.add(Restrictions.eq("hide", false));

        if (goToQuestion > 0) {
            Criteria goToQuestioncriteria = sessionFactory.getCurrentSession()
                    .createCriteria(SurveyQuestions.class);
            goToQuestioncriteria.add(Restrictions.eq("id", goToQuestion));

            SurveyQuestions goToQuestionDetails = (SurveyQuestions) goToQuestioncriteria.uniqueResult();

            criteria.add(Restrictions.ge("questionNum", goToQuestionDetails.getQuestionNum()));
        }

        criteria.addOrder(Order.asc("questionNum"));
        surveyQuestions = criteria.list();
    }

    for (SurveyQuestions question : surveyQuestions) {
        if (question.getValidationId() > 0) {
            question.setValidation(clientDAO.getValidationType(question.getValidationId()));
        }
    }

    return surveyQuestions;
}

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

License:Open Source License

@Override
public TreeMap<Long, Long> getIdsWithVersion(final SharedSessionContract ssc, final Long firstId,
        final Integer maxResults) {
    // Query//from w w  w .ja  v a  2 s.  c om
    final EntityWithIdQuery<E> query = new EntityWithIdQuery<>(getEntityClass());
    if (firstId != null) {
        query.addRestriction(Restrictions.ge("id", firstId));
    }
    query.setMaxResults(maxResults);
    query.addOrder(Order.asc("id"));
    query.setResultTransformer(new AliasToBeanResultTransformer(IdAndVersion.class));

    // Done
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.property("id"), "id");
    projectionList.add(Projections.property("version"), "version");
    @SuppressWarnings("unchecked")
    final List<IdAndVersion> idsAndVersions = (List<IdAndVersion>) query.listForProjection(ssc, projectionList);

    // Transform into map
    final TreeMap<Long, Long> result = transformIntoMap(idsAndVersions);
    return result;
}

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

License:Open Source License

@Override
public List<Long> getIds(final SharedSessionContract ssc, final Long firstId, final Integer maxResults) {
    // Query//from  ww w.  j a  v a  2  s .  co m
    final EntityWithIdQuery<E> query = new EntityWithIdQuery<>(getEntityClass());
    if (firstId != null) {
        query.addRestriction(Restrictions.ge("id", firstId));
    }
    query.setMaxResults(maxResults);
    query.addOrder(Order.asc("id"));
    // Done
    final List<Long> result = query.listIds(ssc);
    return result;
}

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

License:Open Source License

@Override
public List<Long> getIds(final SharedSessionContract ssc, final Collection<Long> ids, final Long firstId,
        final Integer maxResults) {
    if (ids.isEmpty()) {
        return Collections.emptyList();
    }//ww w. j  a v a  2  s.  c  o m

    // Query
    final EntityWithIdQuery<E> query = new EntityWithIdQuery<>(getEntityClass());
    query.addRestriction(Restrictions.in("id", ids));
    if (firstId != null) {
        query.addRestriction(Restrictions.ge("id", firstId));
    }
    query.setMaxResults(maxResults);
    query.addOrder(Order.asc("id"));
    // Done
    final List<Long> result = query.listIds(ssc);
    return result;
}

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

License:Open Source License

public List<Document> getForSourceAndDownloaded(final SharedSessionContract ssc, final long sourceId,
        final LocalDate downloaded) {
    final LocalDateTime minDownloaded = LocalDateTime.of(downloaded, LocalTime.MIDNIGHT);
    final LocalDateTime maxDownloaded = LocalDateTime.of(downloaded.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    documentQuery.addRestriction(Restrictions.eq("sourceId", sourceId));
    documentQuery.addRestriction(Restrictions.ge("downloaded", minDownloaded));
    documentQuery.addRestriction(Restrictions.lt("downloaded", maxDownloaded));

    // Done//from  ww  w.  j a v a 2s .com
    final List<Document> entities = documentQuery.listObjects(ssc);
    return entities;
}

From source file:com.romeikat.datamessie.core.base.query.entity.entities.DocumentQuery.java

License:Open Source License

private void addRestrictions() {
    // Published//w  w  w . j  av  a  2 s  .com
    if (dfs.getFromDate() != null) {
        addRestriction(Restrictions.ge("published", LocalDateTime.of(dfs.getFromDate(), LocalTime.MIDNIGHT)));
    }
    if (dfs.getToDate() != null) {
        addRestriction(Restrictions.lt("published",
                LocalDateTime.of(dfs.getToDate(), LocalTime.MIDNIGHT).plusDays(1)));
    }

    // States
    if (!CollectionUtils.isEmpty(dfs.getStates())) {
        addRestriction(Restrictions.in("state", dfs.getStates()));
    }

    // Document IDs from DFS
    final Collection<Long> documentIds = dfs.getDocumentIds();
    final boolean documentIdsApply = documentIds != null;
    if (documentIdsApply) {
        addIdRestriction(documentIds);
    }

    // Additional document IDs
    for (final Collection<Long> idRestriction : idRestrictions) {
        addIdRestriction(idRestriction);
    }
}

From source file:com.romeikat.datamessie.core.base.query.entity.EntityQueryTest.java

License:Open Source License

@Test
public void addRestrictions() {
    final EntityQuery<BarEntity> query = new EntityQuery<>(BarEntity.class);
    query.addRestriction(Restrictions.ge("fooId", 2l));
    query.addRestriction(Restrictions.eq("active", false));

    final List<BarEntity> objects = query.listObjects(sessionProvider.getStatelessSession());
    final List<String> names = getNames(objects);
    final List<String> expected = Arrays.asList("BarEntity3", "BarEntity4");
    assertTrue(ListUtils.isEqualList(expected, names));

    dbSetupTracker.skipNextLaunch();/*from  w w w .j  a  va2  s  . c o  m*/
}

From source file:com.romeikat.datamessie.core.base.query.entity.EntityWithIdQueryTest.java

License:Open Source License

@Test
public void addRestrictions() {
    final EntityWithIdQuery<BarEntityWithId> query = new EntityWithIdQuery<>(BarEntityWithId.class);
    query.addRestriction(Restrictions.ge("fooId", 2l));
    query.addRestriction(Restrictions.eq("active", false));
    query.addOrder(Order.asc("name"));

    final List<BarEntityWithId> objects = query.listObjects(sessionProvider.getStatelessSession());
    final List<String> names = getNames(objects);
    final List<String> expected = Arrays.asList("BarEntityWithId3", "BarEntityWithId4");
    assertTrue(ListUtils.isEqualList(expected, names));

    dbSetupTracker.skipNextLaunch();/*from  w ww . j  a  v  a 2  s.c o  m*/
}

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

License:Open Source License

public List<Document> getToProcess(final SharedSessionContract ssc, final LocalDate downloaded,
        final int maxResults) {
    final LocalDateTime minDownloaded = LocalDateTime.of(downloaded, LocalTime.MIDNIGHT);
    final LocalDateTime maxDownloaded = LocalDateTime.of(downloaded.plusDays(1), LocalTime.MIDNIGHT);

    // Query: Project
    final EntityWithIdQuery<Project> projectQuery = new EntityWithIdQuery<>(Project.class);
    projectQuery.addRestriction(Restrictions.eq("preprocessingEnabled", true));
    final Collection<Long> projectIds = projectQuery.listIds(ssc);
    if (projectIds.isEmpty()) {
        return Collections.emptyList();
    }/*from  ww w.j  a va2  s  .  co  m*/
    // Query: Project2Source
    final Project2SourceQuery project2SourceQuery = new Project2SourceQuery();
    project2SourceQuery.addRestriction(Restrictions.in("projectId", projectIds));
    final Collection<Long> sourceIds = project2SourceQuery.listIdsForProperty(ssc, "sourceId");
    if (sourceIds.isEmpty()) {
        return Collections.emptyList();
    }

    // Query: Document
    final EntityWithIdQuery<Document> documentQuery = new EntityWithIdQuery<>(Document.class);
    documentQuery.addRestriction(Restrictions.in("sourceId", sourceIds));
    documentQuery.addRestriction(Restrictions.ge("downloaded", minDownloaded));
    documentQuery.addRestriction(Restrictions.lt("downloaded", maxDownloaded));
    final Object[] statesForProcessing = new DocumentProcessingState[] { DocumentProcessingState.DOWNLOADED,
            DocumentProcessingState.REDIRECTED, DocumentProcessingState.CLEANED };
    documentQuery.addRestriction(Restrictions.in("state", statesForProcessing));
    documentQuery.setMaxResults(maxResults);

    // Done
    final List<Document> entities = documentQuery.listObjects(ssc);
    return entities;
}

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));
    }//w  w w . j  a v  a 2 s  .  c  o m
    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;
}