use of org.eclipse.persistence.eis.interactions.QueryStringInteraction in project eclipselink by eclipse-ee4j.
the class MongoDatabaseTestSuite method testNativeQuery.
/**
* Test native query.
*/
public void testNativeQuery() {
EntityManager em = createEntityManager();
MappedInteraction interaction = new MappedInteraction();
interaction.setProperty(MongoPlatform.OPERATION, MongoOperation.FIND.name());
interaction.setProperty(MongoPlatform.COLLECTION, "ORDER");
interaction.setProperty(MongoPlatform.BATCH_SIZE, "10");
interaction.setProperty(MongoPlatform.READ_PREFERENCE, "PRIMARY");
interaction.addArgumentValue("_id", existingOrder.id);
Query query = em.unwrap(JpaEntityManager.class).createQuery(interaction);
List result = query.getResultList();
if ((result.size() != 1) || (!(result.get(0) instanceof DataRecord)) || !(((DataRecord) result.get(0)).get("_id").equals(existingOrder.id))) {
fail("Incorrect result: " + result);
}
interaction = new MappedInteraction();
interaction.setProperty(MongoPlatform.OPERATION, MongoOperation.FIND.name());
interaction.setProperty(MongoPlatform.COLLECTION, "ORDER");
interaction.setProperty(MongoPlatform.BATCH_SIZE, "10");
interaction.setProperty(MongoPlatform.READ_PREFERENCE, "PRIMARY");
interaction.addArgumentValue("_id", existingOrder.id);
query = em.unwrap(JpaEntityManager.class).createQuery(interaction, Order.class);
Order order = (Order) query.getSingleResult();
if ((order == null) || (!order.id.equals(existingOrder.id))) {
fail("Incorrect result: " + order);
}
QueryStringInteraction mqlInteraction = new QueryStringInteraction();
mqlInteraction.setQueryString("db.ORDER.findOne({\"_id\":\"" + existingOrder.id + "\"})");
query = em.unwrap(JpaEntityManager.class).createQuery(mqlInteraction, Order.class);
order = (Order) query.getSingleResult();
if ((order == null) || (!order.id.equals(existingOrder.id))) {
fail("Incorrect result: " + order);
}
query = em.createNativeQuery("db.ORDER.findOne({\"_id\":\"" + existingOrder.id + "\"})", Order.class);
order = (Order) query.getSingleResult();
if ((order == null) || (!order.id.equals(existingOrder.id))) {
fail("Incorrect result: " + order);
}
}
use of org.eclipse.persistence.eis.interactions.QueryStringInteraction in project eclipselink by eclipse-ee4j.
the class MongoTestSuite method testNativeQuery.
/**
* Test native query.
*/
public void testNativeQuery() {
EntityManager em = createEntityManager();
MappedInteraction interaction = new MappedInteraction();
interaction.setProperty(MongoPlatform.OPERATION, MongoOperation.FIND.name());
interaction.setProperty(MongoPlatform.COLLECTION, "ORDER");
interaction.setProperty(MongoPlatform.BATCH_SIZE, "10");
interaction.setProperty(MongoPlatform.READ_PREFERENCE, "PRIMARY");
interaction.addArgumentValue("_id", existingOrder.id);
Query query = em.unwrap(JpaEntityManager.class).createQuery(interaction);
List result = query.getResultList();
if ((result.size() != 1) || (!(result.get(0) instanceof DataRecord)) || !(((DataRecord) result.get(0)).get("_id").equals(existingOrder.id))) {
fail("Incorrect result: " + result);
}
interaction = new MappedInteraction();
interaction.setProperty(MongoPlatform.OPERATION, MongoOperation.FIND.name());
interaction.setProperty(MongoPlatform.COLLECTION, "ORDER");
interaction.setProperty(MongoPlatform.BATCH_SIZE, "10");
interaction.setProperty(MongoPlatform.READ_PREFERENCE, "PRIMARY");
interaction.addArgumentValue("_id", existingOrder.id);
query = em.unwrap(JpaEntityManager.class).createQuery(interaction, Order.class);
Order order = (Order) query.getSingleResult();
if ((order == null) || (!order.id.equals(existingOrder.id))) {
fail("Incorrect result: " + order);
}
QueryStringInteraction mqlInteraction = new QueryStringInteraction();
mqlInteraction.setQueryString("db.ORDER.findOne({\"_id\":\"" + existingOrder.id + "\"})");
query = em.unwrap(JpaEntityManager.class).createQuery(mqlInteraction, Order.class);
order = (Order) query.getSingleResult();
if ((order == null) || (!order.id.equals(existingOrder.id))) {
fail("Incorrect result: " + order);
}
query = em.createNativeQuery("db.ORDER.findOne({\"_id\":\"" + existingOrder.id + "\"})", Order.class);
order = (Order) query.getSingleResult();
if ((order == null) || (!order.id.equals(existingOrder.id))) {
fail("Incorrect result: " + order);
}
}
Aggregations