List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:dao.hibernate.HibernateEmployeeSubjectDAO.java
@Override public List<EmployeeSubject> getSubjectsByEmployee(Employee employee) throws EngineDAOException { getSession().beginTransaction();// w w w . j a v a 2 s . c o m Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(EMPLOYEE, employee)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<EmployeeSubject> employeesSubject = null; try { employeesSubject = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (employeesSubject == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return employeesSubject; }
From source file:dao.hibernate.HibernateKeywordsDAO.java
@Override public List<Keywords> getKeywordsByKeywords(List<Keywords> keywords) throws EngineDAOException { List<Keywords> keys = new ArrayList<>(); for (Keywords k : keywords) { getSession().beginTransaction(); Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.like(KEYWORD, "%" + k.getKeyword() + "%")); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Keywords keyword;/*from ww w . j a v a 2s . co m*/ try { keyword = (Keywords) criteria.uniqueResult(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (keyword == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); keys.add(keyword); } return keys; }
From source file:dao.hibernate.HibernateMessageDAO.java
@Override public List<Message> getMessagesByCommunication(Communication com) throws EngineDAOException { getSession().beginTransaction();// w w w.j av a2 s.c om Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(COMMUNICATION, com)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Message> messages = null; try { messages = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (messages == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return messages; }
From source file:dao.hibernate.HibernateMessageDAO.java
@Override public List<Message> getUnreadMessages(Person person) throws EngineDAOException { getSession().beginTransaction();/* w w w .j av a 2s .c o m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(RECIEVER, person)); criteria.add(Restrictions.eq(READ, false)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Message> messages = null; try { messages = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (messages == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return messages; }
From source file:dao.hibernate.HibernatePersonDAO.java
@Override public Person getPersonByUsernameAndPassword(String username, String password) throws EngineDAOException { getSession().beginTransaction();//from w w w .j a v a 2s . c om Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(USERNAME, username)); criteria.add(Restrictions.eq(PASSWORD, password)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Person person = null; try { person = (Person) criteria.uniqueResult(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (person == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return person; }
From source file:dao.hibernate.HibernatePersonDAO.java
@Override public Person getPersonByUsername(String username) throws EngineDAOException { getSession().beginTransaction();/*from w ww . j av a2 s.co m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(USERNAME, username)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Person person = null; try { person = (Person) criteria.uniqueResult(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (person == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return person; }
From source file:dao.hibernate.HibernatePersonDAO.java
@Override public List<Person> getPersonsByName(String name) throws EngineDAOException { getSession().beginTransaction();/*ww w. j a v a2 s. c om*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(NAME, name)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Person> persons = null; try { persons = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (persons == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return persons; }
From source file:dao.hibernate.HibernatePersonDAO.java
@Override public List<Person> getPersonsByLastname(String lastname) throws EngineDAOException { getSession().beginTransaction();//from ww w . ja v a2s . c o m Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(SURNAME, lastname)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Person> persons = null; try { persons = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (persons == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return persons; }
From source file:dao.hibernate.HibernatePersonDAO.java
@Override public List<Person> getPersonsByNameAndLastname(String name, String lastname) throws EngineDAOException { getSession().beginTransaction();/* w ww . j a v a2 s . c om*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(NAME, name)); criteria.add(Restrictions.eq(SURNAME, lastname)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Person> persons = null; try { persons = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (persons == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return persons; }
From source file:dao.hibernate.HibernatePersonDAO.java
@Override public Person getPersonByEmail(String email) throws EngineDAOException { getSession().beginTransaction();/*www . j a va 2 s . c o m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(EMAIL, email)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Person person = null; try { person = (Person) criteria.uniqueResult(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (person == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return person; }