List of usage examples for org.hibernate Criteria setFetchMode
public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;
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/*from w w w . j av a2 s . c o m*/ * @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
/** * 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 www . j ava 2s . c o m @Override @Transactional(readOnly = true) public List<String> loadEntitiesByCategoryID(Long categoryID) { Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAEntity.class); criteria.setProjection(Projections.distinct(Projections.property("key"))); 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)); return criteria.list(); }
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. **//*w w w. j av a2 s . c om*/ @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.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. **/// ww w .j a v a 2 s . 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.//from w w w. j a v a 2 s . 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. **//* www. ja v a2 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. **///www.j ava 2s . c o 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.jav a 2 s.com*/ @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./*w ww .j av a 2 s . 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. j a v a2s . c om @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(); }