use of org.hibernate.userguide.model.Call in project hibernate-orm by hibernate.
the class HQLTest method test_hql_collection_expressions_example_4.
@Test
public void test_hql_collection_expressions_example_4() {
doInJPA(this::entityManagerFactory, entityManager -> {
Call call = entityManager.createQuery("select c from Call c", Call.class).getResultList().get(0);
Phone phone = call.getPhone();
List<Person> persons = entityManager.createQuery("select p " + "from Person p " + "where :phone member of p.phones", Person.class).setParameter("phone", phone).getResultList();
assertEquals(1, persons.size());
});
}
use of org.hibernate.userguide.model.Call in project hibernate-orm by hibernate.
the class HQLTest method test_hql_collection_expressions_example_2.
@Test
public void test_hql_collection_expressions_example_2() {
doInJPA(this::entityManagerFactory, entityManager -> {
Call call = entityManager.createQuery("select c from Call c", Call.class).getResultList().get(0);
List<Phone> phones = entityManager.createQuery("select p " + "from Phone p " + "where minelement( p.calls ) = :call", Phone.class).setParameter("call", call).getResultList();
assertEquals(1, phones.size());
});
}
use of org.hibernate.userguide.model.Call in project hibernate-orm by hibernate.
the class CriteriaTest method init.
@Before
public void init() {
doInJPA(this::entityManagerFactory, entityManager -> {
Person person1 = new Person("John Doe");
person1.setNickName("JD");
person1.setAddress("Earth");
person1.setCreatedOn(Timestamp.from(LocalDateTime.of(2000, 1, 1, 0, 0, 0).toInstant(ZoneOffset.UTC)));
person1.getAddresses().put(AddressType.HOME, "Home address");
person1.getAddresses().put(AddressType.OFFICE, "Office address");
entityManager.persist(person1);
Person person2 = new Person("Mrs. John Doe");
person2.setAddress("Earth");
person2.setCreatedOn(Timestamp.from(LocalDateTime.of(2000, 1, 2, 12, 0, 0).toInstant(ZoneOffset.UTC)));
entityManager.persist(person2);
Person person3 = new Person("Dr_ John Doe");
entityManager.persist(person3);
Phone phone1 = new Phone("123-456-7890");
phone1.setId(1L);
phone1.setType(PhoneType.MOBILE);
person1.addPhone(phone1);
phone1.getRepairTimestamps().add(Timestamp.from(LocalDateTime.of(2005, 1, 1, 12, 0, 0).toInstant(ZoneOffset.UTC)));
phone1.getRepairTimestamps().add(Timestamp.from(LocalDateTime.of(2006, 1, 1, 12, 0, 0).toInstant(ZoneOffset.UTC)));
Call call11 = new Call();
call11.setDuration(12);
call11.setTimestamp(Timestamp.from(LocalDateTime.of(2000, 1, 1, 0, 0, 0).toInstant(ZoneOffset.UTC)));
Call call12 = new Call();
call12.setDuration(33);
call12.setTimestamp(Timestamp.from(LocalDateTime.of(2000, 1, 1, 1, 0, 0).toInstant(ZoneOffset.UTC)));
phone1.addCall(call11);
phone1.addCall(call12);
Phone phone2 = new Phone("098_765-4321");
phone2.setId(2L);
phone2.setType(PhoneType.LAND_LINE);
Phone phone3 = new Phone("098-765-4320");
phone3.setId(3L);
phone3.setType(PhoneType.LAND_LINE);
person2.addPhone(phone2);
person2.addPhone(phone3);
CreditCardPayment creditCardPayment = new CreditCardPayment();
creditCardPayment.setCompleted(true);
creditCardPayment.setAmount(BigDecimal.ZERO);
creditCardPayment.setPerson(person1);
WireTransferPayment wireTransferPayment = new WireTransferPayment();
wireTransferPayment.setCompleted(true);
wireTransferPayment.setAmount(BigDecimal.valueOf(100));
wireTransferPayment.setPerson(person2);
entityManager.persist(creditCardPayment);
entityManager.persist(wireTransferPayment);
Partner partner = new Partner("John Doe");
entityManager.persist(partner);
});
}
use of org.hibernate.userguide.model.Call in project hibernate-orm by hibernate.
the class HQLTest method test_hql_api_stream_example.
@Test
public void test_hql_api_stream_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap(Session.class);
try (Stream<Person> persons = session.createQuery("select p " + "from Person p " + "where p.name like :name").setParameter("name", "J%").stream()) {
Map<Phone, List<Call>> callRegistry = persons.flatMap(person -> person.getPhones().stream()).flatMap(phone -> phone.getCalls().stream()).collect(Collectors.groupingBy(Call::getPhone));
process(callRegistry);
}
});
}
use of org.hibernate.userguide.model.Call in project hibernate-orm by hibernate.
the class HQLTest method test_hql_group_by_example_4.
@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(PostgreSQL81Dialect.class)
@RequiresDialect(MySQL5Dialect.class)
public void test_hql_group_by_example_4() {
doInJPA(this::entityManagerFactory, entityManager -> {
Call call11 = new Call();
call11.setDuration(10);
call11.setTimestamp(Timestamp.from(LocalDateTime.of(2000, 1, 1, 0, 0, 0).toInstant(ZoneOffset.UTC)));
Phone phone = entityManager.createQuery("select p from Phone p where p.calls is empty ", Phone.class).getResultList().get(0);
phone.addCall(call11);
entityManager.flush();
entityManager.clear();
List<Object[]> personTotalCallDurations = entityManager.createQuery("select p, sum( c.duration ) " + "from Call c " + "join c.phone p " + "group by p", Object[].class).getResultList();
assertEquals(2, personTotalCallDurations.size());
});
}
Aggregations