public List<T> doInSession(Session session) { BeanQuery qry = session.from(sources).offset(from).limit(to - from).orderBy(order); if (condition != null) { qry.where(condition); } return qry.list(projection); } });
private BeanQuery createQuery(@Nullable QueryModifiers modifiers) { BeanQuery beanQuery = session.from($(entity)).orderBy($(entity.getProperty()).asc()); if (modifiers != null) beanQuery.restrict(modifiers); return beanQuery; } }
@Test @Ignore public void ChangeCompany() { newSession(); Employee employee = getEmployee(); Company company = new Company(); company.name = "Competitor"; employee.company = company; session.save(employee); newSession(); Company qCompany = alias(Company.class, "company"); List<Company> companies = session .from($(qCompany)) .orderBy($(qCompany.getName()).asc()) // Competitor, Example .list($(qCompany)); assertEquals(2, companies.size()); assertEquals("Competitor", companies.get(0).name); assertEquals("Example", companies.get(1).name); }
@Test public void order() { session.save(new Note(NoteType.A)); session.save(new Note(NoteType.B)); session.flush(); assertEquals( Arrays.asList(null, NoteType.A, NoteType.B, NoteType.TYPE1), session.from($(n)).orderBy($(n.getType()).asc()).list($(n.getType()))); }
@Test public void order_by_ordinal() throws IOException { session.save(new Note(NoteType.A)); session.save(new Note(NoteType.B)); session.flush(); assertEquals( Arrays.asList(null, NoteType.TYPE1, NoteType.A, NoteType.B), session.from($(n)).orderBy($(n.getType()).ordinal().asc()).list($(n.getType()))); }