Example usage for org.hibernate.criterion Projections property

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

Introduction

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

Prototype

public static PropertyProjection property(String propertyName) 

Source Link

Document

A property value projection

Usage

From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java

License:Open Source License

/**
 * Loads all GLA Entity Keys present in the Database based on a specific Category ID.
 * @param categoryID Category ID used for selecting relevant GLA Entity Objects.
 * @return Returns all GLA Entity Keys present in Database and matching the specified Category ID.
 **///from ww  w  .  j  av  a2  s.  c o m
@Override
@Transactional(readOnly = true)
public List<String> loadEntityKeyValuesByCategoryID(Long categoryID, String key) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEntity.class);
    criteria.createAlias("glaEvent", "events");
    criteria.setFetchMode("events", FetchMode.JOIN);
    criteria.createAlias("events.glaCategory", "category");
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.add(Restrictions.eq("category.id", categoryID));
    criteria.add(Restrictions.eq("key", key));
    criteria.setProjection(Projections.property("value"));
    return criteria.list();

}

From source file:com.indicator_engine.dao.GLAEventDaoImpl.java

License:Open Source License

/**
 * Adds a new GLA Entity Object to the Database.
 * @param glaEntity New GLA Entity Object to be saved.
 * @return ID of the Newly Created GLA Entity object in DB.
 **/// www  .  ja v  a 2  s .  c  o  m
@Override
@Transactional(readOnly = true)
public List<String> selectAllEvents() {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEvent.class).setProjection(Projections.property("id"));
    return criteria.list();

}

From source file:com.indicator_engine.dao.GLAIndicatorDaoImpl.java

License:Open Source License

/**
 * Finds an existing Indicator using its name. It does an exact lookup.
 * @param indicatorName Name of Indicator to be searched in the Database.
 * @return//  w  ww  . j a  v a  2  s. c  om
 *      Returns the Indicator ID if a match is found.
 */
@Override
@Transactional
public long findIndicatorID(String indicatorName) {
    Session session = factory.getCurrentSession();
    long indicatorID = 0;
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.setFetchMode("queries", FetchMode.JOIN);
    criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN);
    criteria.setProjection(Projections.property("id"));
    criteria.add(Restrictions.eq("indicator_name", indicatorName));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    Object result = criteria.uniqueResult();
    if (result != null) {
        indicatorID = (long) result;
    }
    return indicatorID;
}

From source file:com.indicator_engine.dao.GLAIndicatorDaoImpl.java

License:Open Source License

@Override
@Transactional//from w  w  w.  j a va2  s .c  o  m
public long findQuestionID(long indicatorID) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN);
    criteria.createAlias("glaQuestions", "questions");
    criteria.setFetchMode("questions", FetchMode.JOIN);
    criteria.add(Restrictions.eq("id", indicatorID));
    criteria.setProjection(Projections.property("questions.id"));

    return ((Long) criteria.uniqueResult()).longValue();

}

From source file:com.indicator_engine.dao.GLAOperationsDaoImpl.java

License:Open Source License

@Override
@Transactional//from w w  w  . jav a 2s  .  c om
public List<String> selectAllOperations() {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAOperations.class)
            .setProjection(Projections.property("operations"));
    return criteria.list();
}

From source file:com.indicator_engine.dao.GLAQuestionDaoImpl.java

License:Open Source License

/**
 * Finds an existing Question using its name. It does an exact lookup.
 * @param questionName Name of Question to be searched in the Database.
 * @return//from   w w w  .  jav a2 s  .  c o  m
 *      Returns the Question ID if a match is found.
 */
@Override
@Transactional
public long findQuestionID(String questionName) {
    Session session = factory.getCurrentSession();
    long indicatorID = 0;
    Criteria criteria = session.createCriteria(GLAQuestion.class);
    criteria.setFetchMode("glaIndicators", FetchMode.JOIN);
    criteria.setFetchMode("glaQuestionProps", FetchMode.JOIN);
    criteria.setProjection(Projections.property("id"));
    criteria.add(Restrictions.eq("question_name", questionName));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    Object result = criteria.uniqueResult();
    if (result != null) {
        indicatorID = (long) result;
    }
    return indicatorID;
}

From source file:com.indicator_engine.dao.GLAUserDaoImpl.java

License:Open Source License

@Override
@Transactional(readOnly = true)//  ww w  . j a  v a2 s. c  om
public List<String> selectAllUsers() {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAUser.class).setProjection(Projections.property("username"));
    return criteria.list();

}

From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java

@Override
public List<EmpData> getAllDataNotExistInUserByParam(String param, int firstResult, int maxResults,
        Order order) {// ww  w .j av  a 2  s.c o m
    DetachedCriteria subQuery = DetachedCriteria.forClass(HrmUser.class, "user")
            .setProjection(Projections.property("user.id"));
    subQuery.add(Property.forName("employee.id").eqProperty("user.empData.id"));

    Criteria criteria = getCurrentSession().createCriteria(getEntityClass(), "employee");
    criteria.add(Subqueries.notExists(subQuery));
    criteria = this.doSearchNotExistInUserByParam(param, criteria);

    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    criteria.addOrder(order);

    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java

@Override
public Long getTotalNotExistInUserByParam(String param) {
    DetachedCriteria subQuery = DetachedCriteria.forClass(HrmUser.class, "user")
            .setProjection(Projections.property("user.id"));
    subQuery.add(Property.forName("employee.id").eqProperty("user.empData.id"));

    Criteria criteria = getCurrentSession().createCriteria(getEntityClass(), "employee");
    criteria.add(Subqueries.notExists(subQuery));
    criteria = this.doSearchNotExistInUserByParam(param, criteria);

    return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java

@Override
public List<String> getAllNikBetween(String from, String until) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    /**//from w  ww .  j  av  a 2s . com
     * automatically get relations of jabatanByJabatanId, department,
     * company don't create alias for that entity, or will get error :
     * duplicate association path
     */
    criteria = this.addJoinRelationsOfCompanyId(criteria, HrmUserInfoUtil.getCompanyId());
    criteria.add(Restrictions.not(Restrictions.eq("status", HRMConstant.EMP_TERMINATION)));

    criteria.add(Restrictions.ge("nik", from));
    criteria.add(Restrictions.le("nik", until));
    criteria.setProjection(Projections.property("nik"));
    return criteria.list();
}