use of org.hibernate.test.cache.infinispan.functional.entities.Customer in project hibernate-orm by hibernate.
the class BulkOperationsTest method createCustomer.
private Customer createCustomer(int id) throws Exception {
System.out.println("CREATE CUSTOMER " + id);
try {
Customer customer = new Customer();
customer.setName((id % 2 == 0) ? "JBoss" : "Red Hat");
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);
return customer;
} finally {
System.out.println("CREATE CUSTOMER " + id + " - END");
}
}
use of org.hibernate.test.cache.infinispan.functional.entities.Customer in project hibernate-orm by hibernate.
the class ConcurrentWriteTest method createCustomer.
private Customer createCustomer(int nameSuffix) throws Exception {
return withTxSessionApply(s -> {
Customer customer = new Customer();
customer.setName("customer_" + nameSuffix);
customer.setContacts(new HashSet<Contact>());
s.persist(customer);
return customer;
});
}
use of org.hibernate.test.cache.infinispan.functional.entities.Customer 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.Customer 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