List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:org.opencustomer.db.dao.system.ListConfigurationDAO.java
License:Mozilla Public License
public ListConfigurationVO getForUserByTypeAndName(ListConfigurationVO.Type type, String name, UserVO user) { ListConfigurationVO vo = null;/*from ww w . ja va2 s . c o m*/ StringBuilder hql = new StringBuilder(); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE e.type = :type "); hql.append(" AND e.name = :name "); hql.append(" AND e.user = :user "); Query query = HibernateContext.getSession().createQuery(hql.toString()); query.setString("type", type.toString()); query.setString("name", name); query.setEntity("user", user); vo = (ListConfigurationVO) query.uniqueResult(); if (log.isDebugEnabled()) log.debug("found list configuration: " + vo); return vo; }
From source file:org.opencustomer.db.dao.system.ListConfigurationDAO.java
License:Mozilla Public License
public ListConfigurationVO getDefaultListConfiguration(ListConfigurationVO.Type type, UserVO user) { ListConfigurationVO vo = null;/*from w w w . j a v a2 s . c o m*/ StringBuilder hql = new StringBuilder(); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE e.type = :type "); hql.append(" AND (e.user = :user OR e.user is null)"); hql.append(" ORDER BY default desc, user desc, name asc "); Query query = HibernateContext.getSession().createQuery(hql.toString()); query.setString("type", type.toString()); query.setEntity("user", user); query.setMaxResults(1); vo = (ListConfigurationVO) query.uniqueResult(); if (log.isDebugEnabled()) log.debug("found default list configuration: " + vo); return vo; }
From source file:org.opencustomer.db.dao.system.RoleDAO.java
License:Mozilla Public License
public List<RoleVO> getForDefaultUsergroup(UsergroupVO usergroup) { List<RoleVO> roles = new ArrayList<RoleVO>(); try {//from w w w. j a v a 2 s .co m StringBuilder hql = new StringBuilder(); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE e.defaultUsergroup = :usergroup "); hql.append(" order by e.name "); Query query = HibernateContext.getSession().createQuery(hql.toString()); query.setEntity("usergroup", usergroup); roles = toTypeSafeList(query.list()); if (log.isDebugEnabled()) log.debug("found " + roles.size() + " roles"); } catch (HibernateException e) { log.error("Could not find roles", e); throw e; } return roles; }
From source file:org.opencustomer.db.dao.system.UserDAO.java
License:Mozilla Public License
public List<UserVO> getForRole(RoleVO role) { List<UserVO> list = new ArrayList<UserVO>(); try {/* ww w . j av a 2 s. c o m*/ StringBuilder hql = new StringBuilder(); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE e.profile.role = :role "); Query query = HibernateContext.getSession().createQuery(hql.toString()); query.setEntity("role", role); list = toTypeSafeList(query.list()); if (log.isDebugEnabled()) log.debug("found role: " + role); } catch (HibernateException e) { log.error("Could not find role for " + role, e); throw e; } return list; }
From source file:org.opencustomer.db.dao.system.UserLoginLogDAO.java
License:Mozilla Public License
private UserLoginLogVO getLastLoginForUser(UserVO user, Result result) { UserLoginLogVO userLoginLog = null;/*from w w w . ja va2 s. c om*/ try { StringBuilder hql = new StringBuilder(); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE e.user = :user "); hql.append(" AND result = :result "); hql.append(" ORDER by e.loginDate DESC "); Query query = HibernateContext.getSession().createQuery(hql.toString()); query.setEntity("user", user); query.setString("result", result.toString()); query.setMaxResults(1); userLoginLog = (UserLoginLogVO) query.uniqueResult(); if (log.isDebugEnabled()) log.debug("found user: " + user); } catch (HibernateException e) { log.error("Could not find user login log for user with id " + user.getId(), e); throw e; } return userLoginLog; }
From source file:org.opencustomer.db.dao.system.UserLoginLogDAO.java
License:Mozilla Public License
public long countInvalidLoginsForUser(UserVO user) { long count = 0; try {/*ww w .j ava 2 s. com*/ StringBuilder hql = new StringBuilder(); hql.append(" SELECT count(*) "); hql.append(" FROM ").append(getEntityClass().getName()).append(" e "); hql.append(" WHERE e.user = :user "); hql.append(" AND result = '").append(Result.INVALID).append("'"); hql.append(" AND loginDate >= ( "); hql.append(" select max(s.loginDate) "); hql.append(" FROM ").append(getEntityClass().getName()).append(" s "); hql.append(" WHERE s.user = e.user "); hql.append(" AND result = '").append(Result.VALID).append("'"); hql.append(" ) "); hql.append(" ORDER by e.loginDate DESC "); Query query = HibernateContext.getSession().createQuery(hql.toString()); query.setEntity("user", user); query.setMaxResults(1); count = (Long) query.uniqueResult(); if (log.isDebugEnabled()) log.debug("found user: " + user); } catch (HibernateException e) { log.error("Could not find user login log for user with id " + user.getId(), e); throw e; } return count; }
From source file:org.openmrs.api.db.hibernate.HibernateFormDAO.java
License:Mozilla Public License
/** * @see org.openmrs.api.db.FormDAO#getFormsContainingConcept(org.openmrs.Concept) *//* w w w. j a va2 s . c o m*/ @SuppressWarnings("unchecked") public List<Form> getFormsContainingConcept(Concept c) throws DAOException { String q = "select distinct ff.form from FormField ff where ff.field.concept = :concept"; Query query = sessionFactory.getCurrentSession().createQuery(q); query.setEntity("concept", c); return query.list(); }
From source file:org.openmrs.api.db.hibernate.HibernateProgramWorkflowDAO.java
License:Mozilla Public License
/** * @see org.openmrs.api.db.ProgramWorkflowDAO#getProgramsByConcept(org.openmrs.Concept) *//*ww w . jav a 2s . co m*/ @Override public List<Program> getProgramsByConcept(Concept concept) { String pq = "select distinct p from Program p where p.concept = :concept"; Query pquery = sessionFactory.getCurrentSession().createQuery(pq); pquery.setEntity("concept", concept); return pquery.list(); }
From source file:org.openmrs.api.db.hibernate.HibernateProgramWorkflowDAO.java
License:Mozilla Public License
/** * @see org.openmrs.api.db.ProgramWorkflowDAO#getProgramWorkflowsByConcept(org.openmrs.Concept) *//*from www. j a va2 s. c o m*/ @Override public List<ProgramWorkflow> getProgramWorkflowsByConcept(Concept concept) { String wq = "select distinct w from ProgramWorkflow w where w.concept = :concept"; Query wquery = sessionFactory.getCurrentSession().createQuery(wq); wquery.setEntity("concept", concept); return wquery.list(); }
From source file:org.openmrs.api.db.hibernate.HibernateProgramWorkflowDAO.java
License:Mozilla Public License
/** * @see org.openmrs.api.db.ProgramWorkflowDAO#getProgramWorkflowStatesByConcept(org.openmrs.Concept) *//* w w w .j a va2s.c o m*/ @Override public List<ProgramWorkflowState> getProgramWorkflowStatesByConcept(Concept concept) { String sq = "select distinct s from ProgramWorkflowState s where s.concept = :concept"; Query squery = sessionFactory.getCurrentSession().createQuery(sq); squery.setEntity("concept", concept); return squery.list(); }