Example usage for org.hibernate FetchMode JOIN

List of usage examples for org.hibernate FetchMode JOIN

Introduction

In this page you can find the example usage for org.hibernate FetchMode JOIN.

Prototype

FetchMode JOIN

To view the source code for org.hibernate FetchMode JOIN.

Click Source Link

Document

Fetch using an outer join.

Usage

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

License:Open Source License

/**
 * Loads all GLA Entity Objects 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 Objects present in Database and matching the specified Category ID.
 **//*from   ww  w  . j  a  va 2s.  co m*/
@Override
@Transactional(readOnly = true)
public List<String> loadEntitiesByCategoryIDName(Long categoryID, String name) {
    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", name));
    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./* ww  w  .j a va2s.c  o  m*/
 * @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.
 **//*from w  w  w.  ja  va 2s.  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.
 **/// w  w  w.j a  v  a2s . co  m
@Override
@Transactional(readOnly = true)
public List<String> loadEventByCategoryID(Long categoryID) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEvent.class);
    criteria.createAlias("glaCategory", "category");
    criteria.setFetchMode("entities", FetchMode.JOIN);
    criteria.setFetchMode("glaUser", FetchMode.JOIN);
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.add(Restrictions.eq("category.id", categoryID));
    log.info("Dumping criteria" + criteria.list());
    List<GLAEvent> list = criteria.list();
    log.info("Dumping List<GLAEvent> list" + list);
    List<String> selectedEvents = new ArrayList<>();
    for (GLAEvent data : list) {
        selectedEvents.add(data.getAction());
        log.info("Dumping List<GLAEvent>.Actions list" + data.getAction());
    }
    log.info("Dumping Events By Category ID" + selectedEvents);
    return selectedEvents;
}

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.
 **//*w w  w.  j av a  2s .  c  om*/
@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.//  ww  w .j a  v a2s .co 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.
 *///from   w ww  . ja  va  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 w w.j a  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 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.j  a  va 2s . com
 *            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  . java 2  s . c o m
 * @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();

}