Search in sources :

Example 11 with Tuple

use of io.requery.query.Tuple in project requery by requery.

the class FunctionalTest method testQueryUnion.

@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!"));
}
Also used : Group(io.requery.test.model.Group) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Tuple(io.requery.query.Tuple) Test(org.junit.Test)

Example 12 with Tuple

use of io.requery.query.Tuple in project requery by requery.

the class FunctionalTest method testQueryOrderByFunction.

@Test
public void testQueryOrderByFunction() {
    Person person = randomPerson();
    person.setName("BOBB");
    data.insert(person);
    person = randomPerson();
    person.setName("BobA");
    data.insert(person);
    person = randomPerson();
    person.setName("bobC");
    data.insert(person);
    List<Tuple> list = data.select(Person.NAME).orderBy(Upper.upper(Person.NAME).desc()).get().toList();
    assertTrue(list.get(0).get(0).equals("bobC"));
    assertTrue(list.get(1).get(0).equals("BOBB"));
    assertTrue(list.get(2).get(0).equals("BobA"));
}
Also used : Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Tuple(io.requery.query.Tuple) Test(org.junit.Test)

Example 13 with Tuple

use of io.requery.query.Tuple in project requery by requery.

the class FunctionalTest method testQueryOrderBy.

@Test
public void testQueryOrderBy() {
    for (int i = 0; i < 5; i++) {
        Person person = randomPerson();
        person.setAge(i);
        data.insert(person);
    }
    try (Result<Tuple> query = data.select(Person.AGE).orderBy(Person.AGE.desc()).get()) {
        Integer i = query.first().get(0);
        assertTrue(i.equals(4));
    }
}
Also used : Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Tuple(io.requery.query.Tuple) Test(org.junit.Test)

Example 14 with Tuple

use of io.requery.query.Tuple in project requery by requery.

the class FunctionalTest method testQuerySelectWhereIn.

@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<? extends 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());
}
Also used : Group(io.requery.test.model.Group) Person(io.requery.test.model.Person) Group_Person(io.requery.test.model.Group_Person) Tuple(io.requery.query.Tuple) Test(org.junit.Test)

Aggregations

Tuple (io.requery.query.Tuple)14 Test (org.junit.Test)13 Group_Person (io.requery.test.model.Group_Person)12 Person (io.requery.test.model.Person)12 Group (io.requery.test.model.Group)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Attribute (io.requery.meta.Attribute)1 QueryAttribute (io.requery.meta.QueryAttribute)1 EntityProxy (io.requery.proxy.EntityProxy)1 AliasedExpression (io.requery.query.AliasedExpression)1 Expression (io.requery.query.Expression)1 QueryElement (io.requery.query.element.QueryElement)1 WHERE (io.requery.sql.Keyword.WHERE)1 Person (io.requery.test.autovalue.Person)1 Consumer (io.requery.util.function.Consumer)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1