Пример #1
0
 @Test
 public void testQuerySelectWhereIn() {
   final String name = "Hello!";
   Person person = randomPerson();
   person.setName(name);
   data.insert(person);
   Group group = new Group();
   group.setName("Hello!");
   data.insert(group);
   person.getGroups().add(group);
   data.update(person);
   Return<Result<Tuple>> groupNames = data.select(Group.NAME).where(Group.NAME.equal(name));
   Person p = data.select(Person.class).where(Person.NAME.in(groupNames)).get().first();
   assertEquals(p.getName(), name);
   p = data.select(Person.class).where(Person.NAME.notIn(groupNames)).get().firstOrNull();
   assertNull(p);
   p =
       data.select(Person.class)
           .where(Person.NAME.in(Arrays.asList("Hello!", "Other")))
           .get()
           .first();
   assertEquals(p.getName(), name);
   p =
       data.select(Person.class)
           .where(Person.NAME.in(Collections.singleton("Hello!")))
           .get()
           .first();
   assertEquals(p.getName(), name);
   assertTrue(
       data.select(Person.class)
           .where(Person.NAME.notIn(Collections.singleton("Hello!")))
           .get()
           .toList()
           .isEmpty());
 }
Пример #2
0
 @Test
 public void testQueryUnion() {
   Person person = randomPerson();
   person.setName("Carol");
   data.insert(person);
   Group group = new Group();
   group.setName("Hello!");
   data.insert(group);
   List<Tuple> result =
       data.select(Person.NAME.as("name"))
           .union()
           .select(Group.NAME.as("name"))
           .orderBy(Group.NAME.as("name"))
           .get()
           .toList();
   assertTrue(result.size() == 2);
   assertTrue(result.get(0).get(0).equals("Carol"));
   assertTrue(result.get(1).get(0).equals("Hello!"));
 }