@Test @RunOrder(2.31) public void toListBySelectStringTest() { EntityManager em = emf.createEntityManager(); try { Date date = getDateValue(); // ============= Query construction ============== // JpaQueryStream<Object[]> stream = JpaQueryProvider.select(em, Person.class) .where() .equal(Person::getPersonalNo, PERSONAL_NO1) .and() .like(Person::getLastName, "lname%") .and() .brackets( s -> s.startsWith(Person::getFirstName, "fname") .or() .ge(Person::getBirthDate, date)) .and() .in(Person::getPersonId, Arrays.asList(IDENTIFIERS)) .select("select c.personalNo, c.firstName, c.lastName"); System.out.println(stream.sql()); List<Object[]> persons = stream.toList(); // =============================================// System.out.println(); System.out.println("-------Entity----"); System.out.println(); persons.forEach(c -> System.out.println(Arrays.toString(c))); } finally { em.close(); } }
@Test @RunOrder(2.36) public void toListBySelectConsumerTypedTest() { EntityManager em = emf.createEntityManager(); try { Date date = getDateValue(); // ============= Query construction ============== // JpaQueryStream<PersonWrapper> stream = JpaQueryProvider.select(em, Person.class) .where() .equal(Person::getPersonalNo, PERSONAL_NO1) .and() .like(Person::getLastName, "lname%") .and() .brackets( s -> s.startsWith(Person::getFirstName, "fname") .or() .ge(Person::getBirthDate, date)) .and() .in(Person::getPersonId, Arrays.asList(IDENTIFIERS)) .selectType( PersonWrapper.class, s -> s.column(Person::getPersonalNo) .column(Person::getLastName) .column(Person::getFirstName)); System.out.println(stream.sql()); List<PersonWrapper> persons = stream.toList(); // =============================================// System.out.println(); System.out.println("-------Entity----"); System.out.println(); persons.forEach(System.out::println); } finally { em.close(); } }
@Test @RunOrder(2.32) public void toListBySelectWrapperTest() { EntityManager em = emf.createEntityManager(); try { Date date = getDateValue(); // ============= Query construction ============== // JpaQueryStream<PersonWrapper> stream = JpaQueryProvider.select(em, Person.class) .where() .equal(Person::getPersonalNo, PERSONAL_NO1) .and() .like(Person::getLastName, "lname%") .and() .brackets( s -> s.startsWith(Person::getFirstName, "fname") .or() .ge(Person::getBirthDate, date)) .and() .in(Person::getPersonId, Arrays.asList(IDENTIFIERS)) .select( "select new org.lightmare.criteria.entities.PersonWrapper(c.personalNo, c.lastName, c.firstName)", PersonWrapper.class); System.out.println(stream.sql()); List<PersonWrapper> persons = stream.toList(); // =============================================// System.out.println(); System.out.println("-------Entity----"); System.out.println(); persons.forEach(System.out::println); } catch (Throwable ex) { ex.printStackTrace(); } finally { em.close(); } }