Search in sources :

Example 11 with Customer

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");
    }
}
Also used : Customer(org.hibernate.test.cache.infinispan.functional.entities.Customer) HashSet(java.util.HashSet) Contact(org.hibernate.test.cache.infinispan.functional.entities.Contact)

Example 12 with Customer

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;
    });
}
Also used : Customer(org.hibernate.test.cache.infinispan.functional.entities.Customer) Contact(org.hibernate.test.cache.infinispan.functional.entities.Contact)

Example 13 with 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;
    });
}
Also used : Customer(org.hibernate.test.cache.infinispan.functional.entities.Customer) Contact(org.hibernate.test.cache.infinispan.functional.entities.Contact)

Example 14 with Customer

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);
        }
    });
}
Also used : Customer(org.hibernate.test.cache.infinispan.functional.entities.Customer) Contact(org.hibernate.test.cache.infinispan.functional.entities.Contact)

Aggregations

Customer (org.hibernate.test.cache.infinispan.functional.entities.Customer)14 Contact (org.hibernate.test.cache.infinispan.functional.entities.Contact)11 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 Iterator (java.util.Iterator)3 Set (java.util.Set)3 ConcurrentSet (org.jboss.util.collection.ConcurrentSet)3 ArrayList (java.util.ArrayList)2 Phaser (java.util.concurrent.Phaser)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 TestForIssue (org.hibernate.testing.TestForIssue)2 AdvancedCache (org.infinispan.AdvancedCache)2 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1