use of org.hibernate.test.cache.infinispan.functional.entities.Customer in project hibernate-orm by hibernate.
the class EntityCollectionInvalidationTest method doGetCustomer.
private Customer doGetCustomer(Integer id, Session session) throws Exception {
Customer customer = session.get(Customer.class, id);
if (customer == null) {
return null;
}
// Access all the contacts
Set<Contact> contacts = customer.getContacts();
if (contacts != null) {
for (Iterator it = contacts.iterator(); it.hasNext(); ) {
((Contact) it.next()).getName();
}
}
return customer;
}
use of org.hibernate.test.cache.infinispan.functional.entities.Customer in project hibernate-orm by hibernate.
the class EntityCollectionInvalidationTest method cleanup.
private void cleanup(SessionFactory sessionFactory) throws Exception {
withTxSession(sessionFactory, session -> {
Customer c = (Customer) session.get(Customer.class, CUSTOMER_ID);
if (c != null) {
Set contacts = c.getContacts();
for (Iterator it = contacts.iterator(); it.hasNext(); ) {
session.delete(it.next());
}
c.setContacts(null);
session.delete(c);
}
for (Object contact : session.createCriteria(Contact.class).list()) {
session.delete(contact);
}
});
}
use of org.hibernate.test.cache.infinispan.functional.entities.Customer in project hibernate-orm by hibernate.
the class EntityCollectionInvalidationTest method createCustomer.
private IdContainer createCustomer(SessionFactory sessionFactory) throws Exception {
log.debug("CREATE CUSTOMER");
Customer customer = new Customer();
customer.setName("JBoss");
Set<Contact> contacts = new HashSet<Contact>();
Contact kabir = new Contact();
kabir.setCustomer(customer);
kabir.setName("Kabir");
kabir.setTlf("1111");
contacts.add(kabir);
Contact bill = new Contact();
bill.setCustomer(customer);
bill.setName("Bill");
bill.setTlf("2222");
contacts.add(bill);
customer.setContacts(contacts);
ArrayList<Runnable> cleanup = new ArrayList<>();
CountDownLatch customerLatch = new CountDownLatch(1);
CountDownLatch collectionLatch = new CountDownLatch(1);
CountDownLatch contactsLatch = new CountDownLatch(2);
if (cacheMode.isInvalidation()) {
cleanup.add(mockValidator(remoteCustomerCache, customerLatch));
cleanup.add(mockValidator(remoteCollectionCache, collectionLatch));
cleanup.add(mockValidator(remoteContactCache, contactsLatch));
} else if (accessType == AccessType.NONSTRICT_READ_WRITE) {
// ATM nonstrict mode has sync after-invalidation update
Stream.of(customerLatch, collectionLatch, contactsLatch, contactsLatch).forEach(l -> l.countDown());
} else {
ExpectingInterceptor.get(remoteCustomerCache).when(this::isFutureUpdate).countDown(collectionLatch);
ExpectingInterceptor.get(remoteCollectionCache).when(this::isFutureUpdate).countDown(customerLatch);
ExpectingInterceptor.get(remoteContactCache).when(this::isFutureUpdate).countDown(contactsLatch);
cleanup.add(() -> ExpectingInterceptor.cleanup(remoteCustomerCache, remoteCollectionCache, remoteContactCache));
}
withTxSession(sessionFactory, session -> session.save(customer));
assertTrue(customerLatch.await(2, TimeUnit.SECONDS));
assertTrue(collectionLatch.await(2, TimeUnit.SECONDS));
assertTrue(contactsLatch.await(2, TimeUnit.SECONDS));
cleanup.forEach(Runnable::run);
IdContainer ids = new IdContainer();
ids.customerId = customer.getId();
Set contactIds = new HashSet();
contactIds.add(kabir.getId());
contactIds.add(bill.getId());
ids.contactIds = contactIds;
log.debug("CREATE CUSTOMER - END");
return ids;
}
use of org.hibernate.test.cache.infinispan.functional.entities.Customer in project hibernate-orm by hibernate.
the class BulkOperationsTest method createContacts.
public void createContacts() throws Exception {
withTxSession(s -> {
for (int i = 0; i < 10; i++) {
Customer c = createCustomer(i);
s.persist(c);
}
});
}
use of org.hibernate.test.cache.infinispan.functional.entities.Customer in project hibernate-orm by hibernate.
the class ConcurrentWriteTest method readEveryonesFirstContact.
/**
* read first contact of every Customer participating in this test. this forces concurrent cache
* writes of Customer.contacts Collection cache node
*
* @return who cares
* @throws java.lang.Exception
*/
private void readEveryonesFirstContact() throws Exception {
withTxSession(s -> {
for (Integer customerId : getCustomerIDs()) {
if (TERMINATE_ALL_USERS) {
markRollbackOnly(s);
return;
}
Customer customer = s.load(Customer.class, customerId);
Set<Contact> contacts = customer.getContacts();
if (!contacts.isEmpty()) {
contacts.iterator().next();
}
}
});
}
Aggregations