Example usage for org.hibernate.criterion DetachedCriteria getExecutableCriteria

List of usage examples for org.hibernate.criterion DetachedCriteria getExecutableCriteria

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria getExecutableCriteria.

Prototype

public Criteria getExecutableCriteria(Session session) 

Source Link

Document

Get an executable instance of Criteria to actually run the query.

Usage

From source file:org.conventionsframework.dao.impl.BaseHibernateDaoImpl.java

License:Apache License

@Override
public Long getRowCount(final DetachedCriteria dc) {
    Criteria criteria = dc.getExecutableCriteria(getSession());
    criteria.setProjection(Projections.rowCount());
    criteria.setFirstResult(0);//w  w w.j av a 2 s .  c  o  m
    criteria.setMaxResults(1);
    Long result = (Long) criteria.uniqueResult();
    dc.setProjection(null).setResultTransformer(Criteria.ROOT_ENTITY);
    return result;
}

From source file:org.conventionsframework.dao.impl.BaseHibernateDaoImpl.java

License:Apache License

@Override
public List<T> findByCriteria(DetachedCriteria dc, int first, int maxResult) {
    Criteria criteria = dc.getExecutableCriteria(getSession());
    criteria.setFirstResult(first);// w  w w .j ava  2  s  . c  o m
    criteria.setMaxResults(maxResult);
    return criteria.list();
}

From source file:org.conventionsframework.dao.impl.BaseHibernateDaoImpl.java

License:Apache License

@Override
public List<T> findByCriteria(DetachedCriteria dc) {
    return dc.getExecutableCriteria(getSession()).list();
}

From source file:org.conventionsframework.dao.impl.BaseHibernateDaoImpl.java

License:Apache License

@Override
public T findOneByCriteria(DetachedCriteria dc) {
    Criteria criteria = dc.getExecutableCriteria(getSession());
    criteria.setMaxResults(1);//  w ww  .  j a v a 2s.c  o m
    criteria.setFirstResult(0);
    return (T) criteria.uniqueResult();
}

From source file:org.cropinformatics.sql.HibernateDAO.java

License:Apache License

public Criteria createCriteria(DetachedCriteria query) {
    return query.getExecutableCriteria(getCurrentSession());
}

From source file:org.egov.pims.service.PersonalInformationService.java

License:Open Source License

private Criteria getCriteriaForEmpSearchByStatus(Integer statusid, Date fromDate, Date toDate) {
    EgwStatus egwStatus = egwStatusHibernateDAO.findById(statusid, false);
    DetachedCriteria detachCriteriaPersonalInfo = DetachedCriteria.forClass(PersonalInformation.class, "emp");
    if (egwStatus.getModuletype().equals("Employee")
            && egwStatus.getDescription().equalsIgnoreCase("Employed")) {
        detachCriteriaPersonalInfo.createAlias("emp.egpimsAssignment", "assPrd")
                .add(Restrictions.and(Restrictions.le("assPrd.fromDate", toDate), Restrictions
                        .or(Restrictions.ge("assPrd.toDate", toDate), Restrictions.isNull("assPrd.toDate"))));

    } else if (egwStatus.getModuletype().equals("Employee")
            && egwStatus.getDescription().equalsIgnoreCase("Retired")) {
        detachCriteriaPersonalInfo.add(Restrictions.between("emp.retirementDate", fromDate, toDate));

    } else if (egwStatus.getModuletype().equals("Employee")
            && egwStatus.getDescription().equalsIgnoreCase("Deceased")) {
        detachCriteriaPersonalInfo.add(Restrictions.between("emp.deathDate", fromDate, toDate));
    }/*from w w w.j  a v  a  2s .co  m*/
    return detachCriteriaPersonalInfo.getExecutableCriteria(getCurrentSession());
}

From source file:org.egov.ptis.domain.dao.property.PropertyHibernateDAO.java

License:Open Source License

/**
 * To get the list of required values/*from   ww  w  . j  a  v  a  2  s .  c  o m*/
 *
 * @param org .hibernate.criterion.DetachedCriteria detachedCriteria
 * @return Projection list(i.e mentioned in DetachedCriteria).
 */
@Override
public List getResultsList(final DetachedCriteria detachedCriteria) {
    Criteria criteria = null;
    if (detachedCriteria != null)
        criteria = detachedCriteria.getExecutableCriteria(getCurrentSession());
    return criteria.list();
}

From source file:org.eulerframework.web.core.base.dao.impl.hibernate5.BaseDao.java

License:Apache License

@SuppressWarnings("unchecked")
protected List<T> query(DetachedCriteria detachedCriteria) {
    List<T> result = detachedCriteria.getExecutableCriteria(this.getSessionFactory().getCurrentSession())
            .list();/*from   w w w.  j a va  2s.c o m*/
    evict(result);
    return result;
}

From source file:org.eulerframework.web.core.base.dao.impl.hibernate5.BaseDao.java

License:Apache License

@SuppressWarnings("unchecked")
protected List<T> limitQuery(DetachedCriteria detachedCriteria, int maxResults) {
    Criteria criteria = detachedCriteria.getExecutableCriteria(this.getSessionFactory().getCurrentSession());

    criteria.setMaxResults(maxResults);//from   w w  w  . j av  a2s  .  com

    List<T> result = criteria.list();
    evict(result);
    return result;
}

From source file:org.eulerframework.web.core.base.dao.impl.hibernate5.BaseDao.java

License:Apache License

@SuppressWarnings("unchecked")
protected PageResponse<T> pageQuery(DetachedCriteria detachedCriteria, int pageIndex, int pageSize,
        Projection projection) {/*from   w  w w  .j  a va 2  s. c o m*/

    detachedCriteria.setProjection(Projections.rowCount());
    long total = ((Long) detachedCriteria.getExecutableCriteria(this.getSessionFactory().getCurrentSession())
            .list().get(0)).longValue();

    detachedCriteria.setProjection(projection);

    if (projection != null)
        detachedCriteria.setResultTransformer(Transformers.aliasToBean(this.entityClass));

    Criteria criteria = detachedCriteria.getExecutableCriteria(this.getSessionFactory().getCurrentSession());
    criteria.setFirstResult((pageIndex - 1) * pageSize);
    criteria.setMaxResults(pageSize);
    List<T> result = criteria.list();
    evict(result);
    return new PageResponse<>(result, total, pageIndex, pageSize);
}