use of org.hibernate.query.Query in project OpenClinica by OpenClinica.
the class ItemDataDao method getMaxGroupRepeat.
public int getMaxGroupRepeat(Integer eventCrfId, Integer itemId) {
Query q = getCurrentSession().createQuery(getMaxGroupRepeatQuery);
q.setParameter("eventCrfId", eventCrfId);
q.setParameter("itemId", itemId);
Number result = (Number) q.uniqueResult();
if (result == null)
return 0;
else
return result.intValue();
}
use of org.hibernate.query.Query in project api-core by ca-cwds.
the class SystemCodeDaoTest method findAll_Args__.
@Test
public void findAll_Args__() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
Session session = mock(Session.class);
Transaction tx = mock(Transaction.class);
Query query = mock(Query.class);
when(sessionFactory.getCurrentSession()).thenReturn(session);
when(session.getNamedQuery(any(String.class))).thenReturn(query);
when(session.beginTransaction()).thenReturn(tx);
when(query.list()).thenReturn(new ArrayList<SystemCode>());
when(query.setString(any(String.class), any(String.class))).thenReturn(query);
SystemCodeDao target = new SystemCodeDao(sessionFactory);
SystemCode[] actual = target.findByForeignKeyMetaTable("asdf");
SystemCode[] expected = new SystemCode[0];
assertThat(actual, is(equalTo(expected)));
}
use of org.hibernate.query.Query in project api-core by ca-cwds.
the class SystemMetaDaoTest method findAll_Args__.
@Test
public void findAll_Args__() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
Session session = mock(Session.class);
Transaction tx = mock(Transaction.class);
Query query = mock(Query.class);
when(sessionFactory.getCurrentSession()).thenReturn(session);
when(session.getNamedQuery(any(String.class))).thenReturn(query);
when(session.beginTransaction()).thenReturn(tx);
SystemMetaDao target = new SystemMetaDao(sessionFactory);
SystemMeta[] actual = target.findAll();
SystemMeta[] expected = new SystemMeta[0];
assertThat(actual, is(equalTo(expected)));
}
use of org.hibernate.query.Query in project stdlib by petergeneric.
the class JPAQueryBuilder method selectIDs.
public <ID> List<ID> selectIDs() {
Query query = createSelectIDs();
List<?> results = query.getResultList();
if (results.isEmpty())
return Collections.emptyList();
else if (results.get(0).getClass().isArray())
// N.B. we explicitly do not remove duplicates because the only case of duplicates appearing should be if ordering by a collection
return results.stream().map(r -> Array.get(r, 0)).map(id -> (ID) id).collect(Collectors.toList());
else
return (List<ID>) results;
}
use of org.hibernate.query.Query in project KeDou by XiaoBai518.
the class UserDaoImpl method findByUsername.
/**
* @desc 通过电话或者邮箱查询用户
* @author zhangtianrun
* @createDate 2018年3月29日
* @return User
* @throws Exception
*/
public User findByUsername(String teloremail) throws Exception {
SessionFactory sessionFactory = super.getSessionFactory();
String hql = "from User where userTel=:tel or userEmail=:mail";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setParameter("tel", teloremail);
query.setParameter("mail", teloremail);
return (User) query.uniqueResult();
}
Aggregations