Exemplo n.º 1
0
  @Test
  @RunOrder(10)
  public void queryMaxTest() {

    EntityManager em = emf.createEntityManager();
    try {
      // ============= Query construction ============== //
      JpaQueryStream<Long> stream =
          JpaQueryProvider.select(em, Person.class)
              .where()
              .equal(Person::getPersonalNo, Person::getAddrress)
              .and()
              .like(Person::getLastName, "lname%", 'e')
              .and()
              .startsWith(Person::getLastName, "lname")
              .max(Person::getPersonId);
      String sql = stream.sql();
      System.out.println(sql);
      Long max = stream.firstOrDefault(Long.valueOf(0));
      // =============================================//
      System.out.println();
      System.out.println("-------Entity----");
      System.out.println(max);
    } finally {
      em.close();
    }
  }
Exemplo n.º 2
0
  @Test
  @RunOrder(9)
  public void queryLikeFieldTest() {

    EntityManager em = emf.createEntityManager();
    try {
      // ============= Query construction ============== //
      JpaQueryStream<Person> stream =
          JpaQueryProvider.select(em, Person.class)
              .where()
              .equal(Person::getPersonalNo, Person::getAddrress)
              .and()
              .like(Person::getLastName, GeneralInfo::getFullName, Person::getEscape)
              .and()
              .startsWith(Person::getLastName, "lname");
      String sql = stream.sql();
      System.out.println(sql);
      Person person = stream.firstOrDefault(new Person());
      // =============================================//
      System.out.println();
      System.out.println("-------Entity----");
      System.out.println(person);
    } finally {
      em.close();
    }
  }