Example usage for org.hibernate Criteria setResultTransformer

List of usage examples for org.hibernate Criteria setResultTransformer

Introduction

In this page you can find the example usage for org.hibernate Criteria setResultTransformer.

Prototype

public Criteria setResultTransformer(ResultTransformer resultTransformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

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

License:Open Source License

/**
 * Searches Category Items based on a Minor Value.
 * @param searchParameter Minor Value used for Searching.
 * @param exactSearch Search Type : Exact or Likewise.
 * @param colName Column Name used for Sorting the Results.
 * @param sortDirection Sorting Direction : Ascending/Descending.
 * @param sort Turn Sorting ON/OFF./*from   w w w.j  a v a2 s  . c  o m*/
 * @return Returns list of Matching GLACategory Items.
 */
@Override
@Transactional(readOnly = true)
public List<GLACategory> searchCategoryByMinor(String searchParameter, boolean exactSearch, String colName,
        String sortDirection, boolean sort) {
    if (!exactSearch)
        searchParameter = "%" + searchParameter + "%";
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLACategory.class);
    criteria.setFetchMode("events", FetchMode.JOIN);
    if (!exactSearch)
        criteria.add(Restrictions.ilike("minor", searchParameter));
    else
        criteria.add(Restrictions.eq("minor", searchParameter));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();
}

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

License:Open Source License

/**
 * Loads all GLA Entity Objects present in the Database.
 * @param colName Sort the Results using this Column Name.
 * @param sortDirection Specify Sort Direction : asc/desc.
 * @param sort Turn Sorting ON/OFF//  w w  w.  j a v  a 2  s.  c  om
 * @return Returns all GLA Entity Objects present in Database and sorted if specified.
 **/
@Override
@Transactional(readOnly = true)
public List<GLAEntity> loadAll(String colName, String sortDirection, boolean sort) {
    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.createAlias("events.glaUser", "users");
    criteria.setFetchMode("users", FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();

}

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

License:Open Source License

/**
 * Search GLA Entity Objects based on Entity Key
 * @param searchParameter Entity Key used for searching
 * @param exactSearch Search Pattern : Exact or Likewise
 * @param colName Sort Results based on this Column Name
 * @param sortDirection Specify Sort Direction ASC/DESC
 * @param sort Turn Sorting ON/OFF.//from   www. ja  v a2  s .  c om
 * @return Returns all GLA Entity Objects present in Database and matching the Search Criteria.
 **/
@Override
@Transactional(readOnly = true)
public List<GLAEntity> searchEntitiesByKey(String searchParameter, boolean exactSearch, String colName,
        String sortDirection, boolean sort) {
    if (!exactSearch)
        searchParameter = "%" + searchParameter + "%";
    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.createAlias("events.glaUser", "users");
    criteria.setFetchMode("users", FetchMode.JOIN);
    if (!exactSearch)
        criteria.add(Restrictions.ilike("key", searchParameter));
    else
        criteria.add(Restrictions.eq("key", searchParameter));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    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.
 **///  ww w .j ava2 s  . c o  m
@Override
@Transactional(readOnly = true)
public List<GLAEvent> loadAllEvents(String colName, String sortDirection, boolean sort) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEvent.class);
    criteria.setFetchMode("entities", FetchMode.JOIN);
    criteria.setFetchMode("glaUser", FetchMode.JOIN);
    criteria.setFetchMode("glaCategory", FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    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.
 **///from w  w  w .j  a va  2  s  .c o m
@Override
@Transactional(readOnly = true)
public List<GLAEvent> searchEventsByAction(String searchParameter, boolean exactSearch, String colName,
        String sortDirection, boolean sort) {
    if (!exactSearch)
        searchParameter = "%" + searchParameter + "%";
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEvent.class);
    criteria.setFetchMode("entities", FetchMode.JOIN);
    criteria.setFetchMode("glaUser", FetchMode.JOIN);
    criteria.setFetchMode("glaCategory", FetchMode.JOIN);
    if (!exactSearch)
        criteria.add(Restrictions.ilike("action", searchParameter));
    else
        criteria.add(Restrictions.eq("action", searchParameter));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();
}

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

License:Open Source License

/**
 * Loads an Indicator from Database.//from   www . j  av a  2s  .c  o  m
 * @param ID Indicator ID to be searched and loaded.
 * @return The loaded Indicator.
 */

@Override
@Transactional
public GLAIndicator loadByIndicatorID(long ID) {
    Session session = factory.getCurrentSession();
    GLAIndicator glaIndicator = null;
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.setFetchMode("glaQuestions", FetchMode.JOIN);
    criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN);
    criteria.add(Restrictions.eq("id", ID));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    Object result = criteria.uniqueResult();
    if (result != null) {
        glaIndicator = (GLAIndicator) result;
    }
    return glaIndicator;

}

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

License:Open Source License

/**
 * Loads an existing Indicator from the Database. Looks up using name in the Database. It does a similarity search in the database.
 * @param indicatorName Name of the Indicator used for lookup.
 * @return A List of similarly named Indicators present in the Database.
 *//* w w  w  . java 2s.  c  o  m*/
@Override
@Transactional
public List<GLAIndicator> loadByIndicatorByName(String indicatorName, boolean exact) {
    Session session = factory.getCurrentSession();
    indicatorName = "%" + indicatorName + "%";
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.setFetchMode("queries", FetchMode.JOIN);
    criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN);
    if (exact)
        criteria.add(Restrictions.eq("indicator_name", indicatorName));
    else
        criteria.add(Restrictions.ilike("indicator_name", indicatorName));

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();

}

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

License:Open Source License

/**
 * Lists all the Indicators present in the Database.
 * @param colName//  w ww. j ava  2  s . co  m
 *            Column Name to be used for Sorting the results
 * @param sortDirection
 *            Sort Direction : Ascending/Descending
 * @param sort
 *            True for sorting Required and False to set sorting of results off.
 * @return
 *           Listing of all the Indicators.
 *
 */
@Override
@Transactional
public List<GLAIndicator> displayall(String colName, String sortDirection, boolean sort) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.setFetchMode("queries", FetchMode.JOIN);
    criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN);
    criteria.setFetchMode("glaQuestions", FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();
}

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

License:Open Source License

/**
 * Lists all the Non-Composite Indicators present in the Database.
 * @param colName//from ww w  .ja  v a  2  s.c  o  m
 *            Column Name to be used for Sorting the results
 * @param sortDirection
 *            Sort Direction : Ascending/Descending
 * @param sort
 *            True for sorting Required and False to set sorting of results off.
 * @return
 *           Listing of all the Non-Composite Indicators.
 *
 */
@Override
@Transactional
public List<GLAIndicator> displayAllNonComposite(String colName, String sortDirection, boolean sort) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.createAlias("glaIndicatorProps", "indProps");
    criteria.setFetchMode("indProps", FetchMode.JOIN);
    criteria.setFetchMode("glaQuestions", FetchMode.JOIN);
    criteria.add(Restrictions.eq("indProps.isComposite", false));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();
}

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

License:Open Source License

/**
 * Loads Indicators based on a given ID Range.
 * @param startRange Starting ID//  w w  w.  j av a  2  s. com
 * @param endRange Ending ID
 * @return List of Indicators loaded from the Database.
 */
@Override
@Transactional
public List<GLAIndicator> loadIndicatorsRange(long startRange, long endRange) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.setFetchMode("queries", FetchMode.JOIN);
    criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN);
    criteria.add(Restrictions.ge("id", startRange));
    criteria.add(Restrictions.le("id", endRange));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();

}