Example #1
0
  @Test
  public void AliasVariations2() {
    // 1st
    QCat cat = new QCat("cat");
    assertEquals(
        Arrays.asList(), from(cat, cats).where(cat.name.matches("fri.*")).select(cat.name).fetch());

    // 2nd
    Cat c = alias(Cat.class, "cat");
    assertEquals(
        Arrays.asList(),
        from(c, cats).where($(c.getName()).matches("fri.*")).select($(c.getName())).fetch());
  }
Example #2
0
  @Test
  public void AliasVariations1() {
    // 1st
    QCat cat = new QCat("cat");
    assertEquals(
        Arrays.asList("Kitty", "Bob", "Alex", "Francis"),
        from(cat, cats).where(cat.kittens.size().gt(0)).select(cat.name).fetch());

    // 2nd
    Cat c = alias(Cat.class, "cat");
    assertEquals(
        Arrays.asList("Kitty", "Bob", "Alex", "Francis"),
        from(c, cats).where($(c.getKittens()).size().gt(0)).select($(c.getName())).fetch());
  }
Example #3
0
  @Test
  public void Alias3() {
    QCat cat = new QCat("cat");
    Cat other = new Cat();
    Cat c = alias(Cat.class, "cat");

    // 1
    from(c, cats).where($(c.getBirthdate()).gt(new Date())).select($(c)).iterate();

    // 2
    try {
      from(c, cats).where($(c.getMate().getName().toUpperCase()).eq("MOE"));
      fail("expected NPE");
    } catch (NullPointerException ne) {
      // expected
    }

    // 3
    assertEquals(cat.name, $(c.getName()));

    // 4
    from(c, cats)
        .where($(c.getKittens().get(0).getBodyWeight()).gt(12))
        .select($(c.getName()))
        .iterate();

    // 5
    from(c, cats).where($(c).eq(other)).select($(c)).iterate();

    // 6
    from(c, cats).where($(c.getKittens()).contains(other)).select($(c)).iterate();

    // 7
    from(c, cats).where($(c.getKittens().isEmpty())).select($(c)).iterate();

    // 8
    from(c, cats).where($(c.getName()).startsWith("B")).select($(c)).iterate();

    // 9
    from(c, cats).where($(c.getName()).upper().eq("MOE")).select($(c)).iterate();

    // 10
    assertNotNull($(c.getKittensByName()));
    assertNotNull($(c.getKittensByName().get("Kitty")));
    from(c, cats).where($(c.getKittensByName().get("Kitty")).isNotNull()).select(cat).iterate();

    // 11
    //        try {
    //            from(cat, cats).where(cat.mate.alive).fetch(cat);
    //            fail("expected RuntimeException");
    //        } catch (RuntimeException e) {
    //            System.out.println(e.getMessage());
    //            assertEquals("null in cat.mate.alive", e.getMessage());
    //        }

    // 12
    // TestQuery query = query().from(cat, c1, c2).from(cat, c1, c2);
    // assertEquals(1, query.getMetadata().getJoins().size());

  }