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.GLAIndicatorDaoImpl.java
License:Open Source License
/** * Lists all the Indicators present in the Database. * @param colName/*from ww w . ja v a 2s.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// w w w . j a v a 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 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// www .j a v a 2s . 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(); }
From source file:com.indicator_engine.dao.GLAIndicatorDaoImpl.java
License:Open Source License
/** * Searches for Indicators based on their Name * * @param searchParameter/* w w w . ja v a 2 s .co m*/ * Name to be searched for * @param exactSearch * True for exact Search, False for Similarity Search * @param colName * 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 Returns the Result of Similar or Exact search as a List<GLAIndicator> */ @Override @Transactional public List<GLAIndicator> searchIndicatorsName(String searchParameter, boolean exactSearch, String colName, String sortDirection, boolean sort) { if (!exactSearch) searchParameter = "%" + searchParameter + "%"; Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAIndicator.class); criteria.setFetchMode("queries", FetchMode.JOIN); criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN); if (!exactSearch) criteria.add(Restrictions.ilike("indicator_name", searchParameter)); else criteria.add(Restrictions.eq("indicator_name", 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
/** * Deletes an existing Indicator using its ID. Deletes the Indicator if found else ignores. * @param indicator_id//from w w w . ja v a2 s . co m * Specific Indicator with this ID to be deleted. */ @Override @Transactional public void deleteIndicator(long indicator_id) { GLAIndicator glaIndicator = null; Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAIndicator.class); criteria.setFetchMode("queries", FetchMode.JOIN); criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN); criteria.add(Restrictions.eq("id", indicator_id)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); Object result = criteria.uniqueResult(); if (result != null) { glaIndicator = (GLAIndicator) result; } session.delete(glaIndicator); }
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//from w w w . ja va2 s . co m * 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
/** * Updates the Execution Statistics Counter of a Specific Indicator. * @param ID Indicator ID to be searched and updated. * */// w w w . jav a 2s . c o m @Override @Transactional public void updateStatistics(long ID) { Session session = factory.getCurrentSession(); GLAIndicator glaIndicator = null; Calendar calendar = Calendar.getInstance(); java.util.Date now = calendar.getTime(); 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; } glaIndicator.getGlaIndicatorProps().setLast_executionTime(new java.sql.Timestamp(now.getTime())); glaIndicator.getGlaIndicatorProps() .setTotalExecutions(glaIndicator.getGlaIndicatorProps().getTotalExecutions() + 1); factory.getCurrentSession().saveOrUpdate(glaIndicator); }
From source file:com.indicator_engine.dao.GLAIndicatorDaoImpl.java
License:Open Source License
@Override @Transactional// www. j a v a 2 s . c om 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.GLAQuestionDaoImpl.java
License:Open Source License
/** * Lists all the Questions present in the Database. * @param colName//from w w w. j ava 2s . 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 Questions. * */ @Override @Transactional public List<GLAQuestion> displayAll(String colName, String sortDirection, boolean sort) { Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAQuestion.class); criteria.setFetchMode("glaIndicators", FetchMode.JOIN); criteria.setFetchMode("glaQuestionProps", 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.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 a 2 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; }