use of org.eclipse.persistence.testing.models.jpa.nosql.Order in project eclipselink by eclipse-ee4j.
the class NoSQLJPATest method testRefresh.
/**
* Test refresh.
*/
@Test
public void testRefresh() {
EntityManagerHelper.beginTransaction(em);
Order order = new Order();
try {
order.orderedBy = "ACME";
order.address = new Address();
order.address.city = "Ottawa";
em.persist(order);
EntityManagerHelper.commitTransaction(em);
} finally {
EntityManagerHelper.clearCache(em);
EntityManagerHelper.closeEntityManagerAndTransaction(em);
}
em = EntityManagerHelper.createEntityManager(PU_NAME);
EntityManagerHelper.beginTransaction(em);
try {
order = em.find(Order.class, order.id);
order.orderedBy = "Fred Jones";
em.refresh(order);
assertEquals(String.format("Refresh failed: %s", order.orderedBy), "ACME", order.orderedBy);
} finally {
em.remove(order);
}
}
use of org.eclipse.persistence.testing.models.jpa.nosql.Order in project eclipselink by eclipse-ee4j.
the class NoSQLJPATest method testUpdate.
/**
* Test updates.
*/
@Test
public void testUpdate() {
EntityManagerHelper.beginTransaction(em);
Order order = new Order();
String orderId = null;
try {
order.orderedBy = "ACME";
order.address = new Address();
order.address.city = "Ottawa";
em.persist(order);
EntityManagerHelper.commitTransaction(em);
orderId = order.id;
} finally {
EntityManagerHelper.clearCache(em);
EntityManagerHelper.closeEntityManagerAndTransaction(em);
}
em = EntityManagerHelper.createEntityManager(PU_NAME);
EntityManagerHelper.beginTransaction(em);
try {
final Order existingOrder = getRandomOrder();
order = em.find(Order.class, existingOrder.id);
order.orderedBy = "Fred Jones";
order.address.addressee = "Fred Jones";
EntityManagerHelper.commitTransaction(em);
} finally {
EntityManagerHelper.clearCache(em);
EntityManagerHelper.closeEntityManagerAndTransaction(em);
}
em = EntityManagerHelper.createEntityManager(PU_NAME);
EntityManagerHelper.beginTransaction(em);
try {
Order fromDatabase = em.find(Order.class, order.id);
EntityManagerHelper.compareObjects(order, fromDatabase, em);
} finally {
Order toDelete = em.find(Order.class, orderId);
em.remove(toDelete);
}
}
use of org.eclipse.persistence.testing.models.jpa.nosql.Order in project eclipselink by eclipse-ee4j.
the class NoSQLJPATest method testNativeQuery.
/**
* Test native query.
*/
@Test
public void testNativeQuery() {
MappedInteraction interaction = new MappedInteraction();
final Order existingOrder = getRandomOrder();
interaction.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.GET.name());
interaction.addArgumentValue("[ORDER," + existingOrder.id + "]", "");
final Query query1 = em.unwrap(JpaEntityManager.class).createQuery(interaction);
@SuppressWarnings("unchecked") final List<Object> result1 = query1.getResultList();
assertEquals(String.format("Expected result of size 1, got %d", result1.size()), 1, result1.size());
assertTrue(String.format("Result is not instance of Record but %s", result1.get(0).getClass().getSimpleName()), (result1.get(0) instanceof DataRecord));
assertTrue(String.format("Incorrect result: %s", result1), (((DataRecord) result1.get(0)).containsKey("[ORDER," + existingOrder.id + "]")));
interaction = new XMLInteraction();
interaction.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.GET.name());
interaction.addArgumentValue("@id", existingOrder.id);
final Query query2 = em.unwrap(JpaEntityManager.class).createQuery(interaction, Order.class);
@SuppressWarnings("unchecked") final List<Object> result2 = query2.getResultList();
assertEquals(String.format("Expected result of size 1, got %d", result2.size()), 1, result2.size());
assertTrue(String.format("Result is not instance of Order but %s", result2.get(0).getClass().getSimpleName()), (result2.get(0) instanceof Order));
}
use of org.eclipse.persistence.testing.models.jpa.nosql.Order in project eclipselink by eclipse-ee4j.
the class NoSQLJPATest method testMerge.
/**
* Test merge.
*/
@Test
public void testMerge() {
EntityManagerHelper.beginTransaction(em);
Order order = new Order();
String orderId = null;
try {
order.orderedBy = "ACME";
order.address = new Address();
order.address.city = "Ottawa";
em.persist(order);
EntityManagerHelper.commitTransaction(em);
orderId = order.id;
} finally {
EntityManagerHelper.clearCache(em);
EntityManagerHelper.closeEntityManagerAndTransaction(em);
}
em = EntityManagerHelper.createEntityManager(PU_NAME);
EntityManagerHelper.beginTransaction(em);
try {
order = em.find(Order.class, order.id);
order.orderedBy = "Fred Jones";
order.address.addressee = "Fred Jones";
} finally {
EntityManagerHelper.closeEntityManagerAndTransaction(em);
}
em = EntityManagerHelper.createEntityManager(PU_NAME);
EntityManagerHelper.beginTransaction(em);
try {
em.merge(order);
EntityManagerHelper.commitTransaction(em);
} finally {
EntityManagerHelper.clearCache(em);
EntityManagerHelper.closeEntityManagerAndTransaction(em);
}
em = EntityManagerHelper.createEntityManager(PU_NAME);
EntityManagerHelper.beginTransaction(em);
try {
Order fromDatabase = em.find(Order.class, order.id);
EntityManagerHelper.compareObjects(order, fromDatabase, em);
} finally {
Order toDelete = em.find(Order.class, orderId);
em.remove(toDelete);
}
}
use of org.eclipse.persistence.testing.models.jpa.nosql.Order in project eclipselink by eclipse-ee4j.
the class NoSQLJPATest method testJPQL.
/**
* Test JPQL.
*/
@Test
public void testJPQL() {
// We need known amount of records in DB.
initModel();
final TypedQuery<Order> query1 = em.createQuery("Select o from Order o", Order.class);
final int count1 = query1.getResultList().size();
assertEquals(String.format("Find all did not work, expected 10 got: %d", count1), 10, count1);
final Order existingOrder = getRandomOrder();
final TypedQuery<Order> query2 = em.createQuery("Select o from Order o where o.id = :id", Order.class);
query2.setParameter("id", existingOrder.id);
final int count2 = query2.getResultList().size();
assertEquals(String.format("Find all did not work, expected 1 got: %d", count2), 1, count2);
}
Aggregations