/** Test updates. */ public void testUpdate() { EntityManager em = createEntityManager(); beginTransaction(em); Order order = new Order(); try { order.id = this.nextId++; order.orderedBy = "ACME"; order.address = new Address(); order.address.city = "Ottawa"; em.persist(order); commitTransaction(em); } finally { closeEntityManagerAndTransaction(em); } clearCache(); em = createEntityManager(); beginTransaction(em); try { order = em.find(Order.class, this.existingOrder.id); order.orderedBy = "Fred Jones"; order.address.addressee = "Fred Jones"; commitTransaction(em); } finally { closeEntityManagerAndTransaction(em); } clearCache(); em = createEntityManager(); beginTransaction(em); try { Order fromDatabase = em.find(Order.class, order.id); compareObjects(order, fromDatabase); } finally { closeEntityManagerAndTransaction(em); } }
/** Test refresh. */ public void testRefresh() { EntityManager em = createEntityManager(); beginTransaction(em); Order order = new Order(); try { order.id = this.nextId++; order.orderedBy = "ACME"; order.address = new Address(); order.address.city = "Ottawa"; em.persist(order); commitTransaction(em); } finally { closeEntityManagerAndTransaction(em); } clearCache(); em = createEntityManager(); beginTransaction(em); try { order = em.find(Order.class, order.id); order.orderedBy = "Fred Jones"; em.refresh(order); if (order.orderedBy.equals("Fred Jones")) { fail("Refresh failed: " + order.orderedBy); } } finally { closeEntityManagerAndTransaction(em); } }
/** Test inserts. */ public void testInsert() { EntityManager em = createEntityManager(); beginTransaction(em); Order order = new Order(); try { order.id = this.nextId++; order.orderedBy = "ACME"; order.address = new Address(); order.address.city = "Ottawa"; em.persist(order); order.customer = new Customer(); order.customer.id = String.valueOf(this.nextId++); order.customer.name = "ACME"; em.persist(order.customer); commitTransaction(em); } finally { closeEntityManagerAndTransaction(em); } clearCache(); em = createEntityManager(); beginTransaction(em); try { Order fromDatabase = em.find(Order.class, order.id); compareObjects(order, fromDatabase); } finally { closeEntityManagerAndTransaction(em); } }
public void testSetup() { EntityManager em = createEntityManager(); // First clear old data from store. beginTransaction(em); KVStore store = ((OracleNoSQLConnection) em.unwrap(javax.resource.cci.Connection.class)).getStore(); Iterator<Key> iterator = store.storeKeysIterator(Direction.UNORDERED, 0); while (iterator.hasNext()) { store.multiDelete(iterator.next(), null, null); } commitTransaction(em); beginTransaction(em); try { for (int index = 0; index < 10; index++) { existingOrder = new Order(); existingOrder.id = this.nextId++; existingOrder.orderedBy = "ACME"; existingOrder.address = new Address(); existingOrder.address.city = "Ottawa"; existingOrder.address.addressee = "Bob Jones"; existingOrder.address.state = "CA"; existingOrder.address.country = "Mexico"; existingOrder.address.zipCode = "12345"; LineItem line = new LineItem(); line.itemName = "stuff"; line.itemPrice = new BigDecimal("10.99"); line.lineNumber = 1; line.quantity = 100; existingOrder.lineItems.add(line); line = new LineItem(); line.itemName = "more stuff"; line.itemPrice = new BigDecimal("20.99"); line.lineNumber = 2; line.quantity = 50; existingOrder.lineItems.add(line); existingOrder.comments.add("priority order"); existingOrder.comments.add("next day"); em.persist(existingOrder); } commitTransaction(em); } finally { closeEntityManagerAndTransaction(em); } clearCache(); }
/** Test deletes. */ public void testDelete() { EntityManager em = createEntityManager(); beginTransaction(em); Order order = new Order(); try { order.id = this.nextId++; order.orderedBy = "ACME"; order.address = new Address(); order.address.city = "Ottawa"; em.persist(order); commitTransaction(em); } finally { closeEntityManagerAndTransaction(em); } clearCache(); em = createEntityManager(); beginTransaction(em); try { order = em.find(Order.class, order.id); em.remove(order); commitTransaction(em); } finally { closeEntityManagerAndTransaction(em); } clearCache(); em = createEntityManager(); beginTransaction(em); try { Order fromDatabase = em.find(Order.class, order.id); if (fromDatabase != null) { fail("Object not deleted: " + fromDatabase); } } finally { closeEntityManagerAndTransaction(em); } }