use of org.eclipse.persistence.testing.models.jpa.fieldaccess.relationships.Order in project eclipselink by eclipse-ee4j.
the class RelationshipModelJUnitTestSuite method testUpdateCustomer.
// Test that updating a customer works correctly.
public void testUpdateCustomer() {
Customer customer = RelationshipsExamples.customerExample4();
EntityManager em = createEntityManager("fieldaccess");
try {
beginTransaction(em);
em.persist(customer);
commitTransaction(em);
closeEntityManager(em);
clearCache("fieldaccess");
em = createEntityManager("fieldaccess");
beginTransaction(em);
customer = em.find(Customer.class, customer.getCustomerId());
Item item1 = RelationshipsExamples.itemExample1();
Order order1 = RelationshipsExamples.orderExample1();
customer.addOrder(order1);
order1.setItem(item1);
em.flush();
Item item2 = RelationshipsExamples.itemExample2();
Order order2 = RelationshipsExamples.orderExample2();
customer.addOrder(order2);
order2.setItem(item2);
Item item3 = RelationshipsExamples.itemExample3();
Order order3 = RelationshipsExamples.orderExample3();
customer.addOrder(order3);
order3.setItem(item3);
// Force LAZY otherwise compare will fail on was.
getServerSession("fieldaccess").copy(customer);
commitTransaction(em);
beginTransaction(em);
verifyObjectInEntityManager(customer, "fieldaccess");
verifyObjectInEntityManager(order1, "fieldaccess");
verifyObjectInEntityManager(item1, "fieldaccess");
verifyObjectInEntityManager(order2, "fieldaccess");
verifyObjectInEntityManager(item2, "fieldaccess");
verifyObjectInEntityManager(order3, "fieldaccess");
verifyObjectInEntityManager(item3, "fieldaccess");
commitTransaction(em);
clearCache("fieldaccess");
beginTransaction(em);
verifyObjectInEntityManager(customer, "fieldaccess");
verifyObjectInEntityManager(order1, "fieldaccess");
verifyObjectInEntityManager(item1, "fieldaccess");
verifyObjectInEntityManager(order2, "fieldaccess");
verifyObjectInEntityManager(item2, "fieldaccess");
verifyObjectInEntityManager(order3, "fieldaccess");
verifyObjectInEntityManager(item3, "fieldaccess");
commitTransaction(em);
clearCache("fieldaccess");
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.relationships.Order in project eclipselink by eclipse-ee4j.
the class RelationshipModelJUnitTestSuite method testPersistCustomer.
// Test that persisting a customer works correctly.
public void testPersistCustomer() {
Customer customer = RelationshipsExamples.customerExample4();
Item item1 = RelationshipsExamples.itemExample1();
Order order1 = RelationshipsExamples.orderExample1();
customer.addOrder(order1);
order1.setItem(item1);
Item item2 = RelationshipsExamples.itemExample2();
Order order2 = RelationshipsExamples.orderExample2();
customer.addOrder(order2);
order2.setItem(item2);
Item item3 = RelationshipsExamples.itemExample3();
Order order3 = RelationshipsExamples.orderExample3();
customer.addOrder(order3);
order3.setItem(item3);
EntityManager em = createEntityManager("fieldaccess");
try {
beginTransaction(em);
em.persist(customer);
commitTransaction(em);
beginTransaction(em);
verifyObjectInEntityManager(customer, "fieldaccess");
verifyObjectInEntityManager(order1, "fieldaccess");
verifyObjectInEntityManager(order2, "fieldaccess");
verifyObjectInEntityManager(item1, "fieldaccess");
verifyObjectInEntityManager(item2, "fieldaccess");
commitTransaction(em);
clearCache("fieldaccess");
beginTransaction(em);
verifyObjectInEntityManager(customer, "fieldaccess");
verifyObjectInEntityManager(order1, "fieldaccess");
verifyObjectInEntityManager(order2, "fieldaccess");
verifyObjectInEntityManager(item1, "fieldaccess");
verifyObjectInEntityManager(item2, "fieldaccess");
commitTransaction(em);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.relationships.Order in project eclipselink by eclipse-ee4j.
the class RelationshipModelJUnitTestSuite method testNamedQueryWithArgumentsTest.
// Bug#4646580 Query arguments are added in EJBQL
public void testNamedQueryWithArgumentsTest() {
Integer[] cusIDs = new Integer[3];
Integer[] orderIDs = new Integer[3];
Integer[] itemIDs = new Integer[3];
Exception exception = null;
List list = null;
Customer cusClone1 = RelationshipsExamples.customerExample1();
Item item1 = RelationshipsExamples.itemExample1();
Order order1 = RelationshipsExamples.orderExample1();
order1.setCustomer(cusClone1);
order1.setItem(item1);
EntityManager em = createEntityManager("fieldaccess");
try {
beginTransaction(em);
em.persist(cusClone1);
em.persist(order1);
commitTransaction(em);
cusIDs[0] = cusClone1.getCustomerId();
orderIDs[0] = order1.getOrderId();
itemIDs[0] = item1.getItemId();
clearCache("fieldaccess");
try {
ServerSession ss = getServerSession("fieldaccess");
Vector vec = new Vector();
vec.add(itemIDs[0]);
list = (List) ss.executeQuery("findAllFieldAccessOrdersByItem", vec);
} catch (Exception ex) {
exception = ex;
}
beginTransaction(em);
Customer cus1 = em.find(Customer.class, cusIDs[0]);
em.remove(cus1);
Order ord1 = em.find(Order.class, orderIDs[0]);
em.remove(ord1);
Item it1 = em.find(Item.class, itemIDs[0]);
em.remove(it1);
commitTransaction(em);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
}
if (exception != null) {
fail("An exception is thrown: " + exception);
}
if (list.size() != 1) {
fail("One order is expected but " + list.size() + " was returned");
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.relationships.Order in project eclipselink by eclipse-ee4j.
the class RelationshipModelJUnitTestSuite method testReadCustomer.
// Test reading a customer works correctly.
public void testReadCustomer() {
Customer customer = RelationshipsExamples.customerExample4();
EntityManager em = createEntityManager("fieldaccess");
QuerySQLTracker counter = null;
try {
beginTransaction(em);
Item item1 = RelationshipsExamples.itemExample1();
Order order1 = RelationshipsExamples.orderExample1();
customer.addOrder(order1);
order1.setItem(item1);
Item item2 = RelationshipsExamples.itemExample2();
Order order2 = RelationshipsExamples.orderExample2();
customer.addOrder(order2);
order2.setItem(item2);
Item item3 = RelationshipsExamples.itemExample3();
Order order3 = RelationshipsExamples.orderExample3();
customer.addOrder(order3);
order3.setItem(item3);
em.persist(customer);
commitTransaction(em);
closeEntityManager(em);
clearCache("fieldaccess");
em = createEntityManager("fieldaccess");
beginTransaction(em);
counter = new QuerySQLTracker(getServerSession("fieldaccess"));
customer = em.find(Customer.class, customer.getCustomerId());
for (Order order : customer.getOrders()) {
order.getCustomer();
}
if (isWeavingEnabled("fieldaccess") && counter.getSqlStatements().size() > 2) {
fail("Should have been 2 queries but was: " + counter.getSqlStatements().size());
}
commitTransaction(em);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
if (counter != null) {
counter.remove();
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.testing.models.jpa.fieldaccess.relationships.Order in project eclipselink by eclipse-ee4j.
the class RelationshipModelJUnitTestSuite method testDeleteCustomer.
// Test that deleting a customer works correctly.
public void testDeleteCustomer() {
Customer customer = RelationshipsExamples.customerExample4();
EntityManager em = createEntityManager("fieldaccess");
try {
beginTransaction(em);
Item item1 = RelationshipsExamples.itemExample1();
Order order1 = RelationshipsExamples.orderExample1();
customer.addOrder(order1);
order1.setItem(item1);
Item item2 = RelationshipsExamples.itemExample2();
Order order2 = RelationshipsExamples.orderExample2();
customer.addOrder(order2);
order2.setItem(item2);
Item item3 = RelationshipsExamples.itemExample3();
Order order3 = RelationshipsExamples.orderExample3();
customer.addOrder(order3);
order3.setItem(item3);
em.persist(customer);
commitTransaction(em);
closeEntityManager(em);
clearCache("fieldaccess");
em = createEntityManager("fieldaccess");
beginTransaction(em);
customer = em.find(Customer.class, customer.getCustomerId());
em.remove(customer);
commitTransaction(em);
beginTransaction(em);
verifyDelete(customer, "fieldaccess");
commitTransaction(em);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
Aggregations