use of org.hibernate.test.cache.infinispan.functional.entities.Contact in project hibernate-orm by hibernate.
the class ConcurrentWriteTest method addContact.
/**
* -load existing Customer -create a new Contact and add to customer's contacts
*
* @param customerId
* @return added Contact
*/
private Contact addContact(Integer customerId) throws Exception {
assert customerId != null;
return withTxSessionApply(s -> {
final Customer customer = s.load(Customer.class, customerId);
Contact contact = new Contact();
contact.setName("contact name");
contact.setTlf("wtf is tlf?");
contact.setCustomer(customer);
customer.getContacts().add(contact);
if (TERMINATE_ALL_USERS) {
markRollbackOnly(s);
}
return contact;
});
}
use of org.hibernate.test.cache.infinispan.functional.entities.Contact in project hibernate-orm by hibernate.
the class ConcurrentWriteTest method removeContact.
/**
* remove existing 'contact' from customer's list of contacts
*
* @param customerId
* @throws IllegalStateException
* if customer does not own a contact
*/
private void removeContact(Integer customerId) throws Exception {
assert customerId != null;
withTxSession(s -> {
Customer customer = s.load(Customer.class, customerId);
Set<Contact> contacts = customer.getContacts();
if (contacts.size() != 1) {
throw new IllegalStateException("can't remove contact: customer id=" + customerId + " expected exactly 1 contact, " + "actual count=" + contacts.size());
}
Contact contact = contacts.iterator().next();
s.lock(contact, LockMode.PESSIMISTIC_WRITE);
contacts.remove(contact);
contact.setCustomer(null);
if (TERMINATE_ALL_USERS) {
markRollbackOnly(s);
}
});
}
Aggregations