@Test public void List_Deep_Keys() { User u = where(user.firstName.eq("Jaakko")).singleResult(user.addresses.any().street); for (Address a : u.getAddresses()) { assertNotNull(a.street); assertNull(a.city); } }
@Test public void List_Keys() { User u = where(user.firstName.eq("Jaakko")).list(user.firstName, user.mainAddress().street).get(0); assertEquals("Jaakko", u.getFirstName()); assertNull(u.getLastName()); assertEquals("Aakatu", u.getMainAddress().street); assertNull(u.getMainAddress().postCode); }
@Test public void References() { for (User u : users) { if (u.getFriend() != null) { assertQuery(user.friend().eq(u.getFriend()), u); where(user.friend().ne(u.getFriend())).list(); } } }
private User addUser( String first, String last, int age, Address mainAddress, Address... addresses) { User user = new User(first, last, age, new Date()); user.setGender(Gender.MALE); user.setMainAddress(mainAddress); for (Address address : addresses) { user.addAddress(address); } for (User u : users) { user.addFriend(u); } if (!users.isEmpty()) { user.setFriend(users.get(users.size() - 1)); } ds.save(user); users.add(user); return user; }
@Test public void SingleResult_Keys() { User u = where(user.firstName.eq("Jaakko")).singleResult(user.firstName); assertEquals("Jaakko", u.getFirstName()); assertNull(u.getLastName()); }
@Test public void Find_By_Id() { assertNotNull(where(user.id.eq(u1.getId())).singleResult() != null); }
@Test public void Exists() { assertTrue(where(user.firstName.eq("Jaakko")).exists()); assertFalse(where(user.firstName.eq("JaakkoX")).exists()); assertTrue(where(user.id.eq(u1.getId())).exists()); }