use of org.eclipse.persistence.eis.interactions.MappedInteraction in project eclipselink by eclipse-ee4j.
the class NoSQLSimpleTest method testNative.
/**
* Test native Oracle NoSQL queries.
*/
@Test
public void testNative() throws Exception {
final MappedInteraction insertCall = new MappedInteraction();
insertCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.PUT.name());
insertCall.addArgumentValue("Order/1234", "foo");
final DataModifyQuery insert = new DataModifyQuery(insertCall);
session.executeQuery(insert);
final MappedInteraction readCall = new MappedInteraction();
readCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.GET.name());
readCall.addArgumentValue("Order/1234", "");
final DataReadQuery read = new DataReadQuery(readCall);
@SuppressWarnings("unchecked") final List<DataRecord> result = (List<DataRecord>) session.executeQuery(read);
final String value = new String((byte[]) result.get(0).get("Order/1234"));
assertEquals("foo expected: " + value, "foo", value);
}
use of org.eclipse.persistence.eis.interactions.MappedInteraction 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.eis.interactions.MappedInteraction in project eclipselink by eclipse-ee4j.
the class MongoPlatform method initializeDefaultQueries.
/**
* INTERNAL:
* Allow the platform to initialize the CRUD queries to defaults.
* Configure the CRUD operations using GET/PUT and DELETE.
*/
@Override
public void initializeDefaultQueries(DescriptorQueryManager queryManager, AbstractSession session) {
// Insert
if (!queryManager.hasInsertQuery()) {
EISInteraction call = new MappedInteraction();
call.setProperty(MongoPlatform.OPERATION, MongoOperation.INSERT);
call.setProperty(MongoPlatform.COLLECTION, ((EISDescriptor) queryManager.getDescriptor()).getDataTypeName());
queryManager.setInsertCall(call);
}
// Update
if (!queryManager.hasUpdateQuery()) {
EISInteraction call = new MappedInteraction();
call.setProperty(MongoPlatform.OPERATION, MongoOperation.UPDATE);
call.setProperty(MongoPlatform.COLLECTION, ((EISDescriptor) queryManager.getDescriptor()).getDataTypeName());
queryManager.setUpdateCall(call);
}
// Read
if (!queryManager.hasReadObjectQuery()) {
MappedInteraction call = new MappedInteraction();
call.setProperty(MongoPlatform.OPERATION, MongoOperation.FIND);
call.setProperty(MongoPlatform.COLLECTION, ((EISDescriptor) queryManager.getDescriptor()).getDataTypeName());
for (DatabaseField field : queryManager.getDescriptor().getPrimaryKeyFields()) {
call.addArgument(field.getName());
}
queryManager.setReadObjectCall(call);
}
// Delete
if (!queryManager.hasDeleteQuery()) {
MappedInteraction call = new MappedInteraction();
call.setProperty(MongoPlatform.OPERATION, MongoOperation.REMOVE);
call.setProperty(MongoPlatform.COLLECTION, ((EISDescriptor) queryManager.getDescriptor()).getDataTypeName());
for (DatabaseField field : queryManager.getDescriptor().getPrimaryKeyFields()) {
call.addArgument(field.getName());
}
queryManager.setDeleteCall(call);
}
}
use of org.eclipse.persistence.eis.interactions.MappedInteraction 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.MappedInteraction 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