Search in sources :

Example 1 with XMLInteraction

use of org.eclipse.persistence.eis.interactions.XMLInteraction in project eclipselink by eclipse-ee4j.

the class NoSQLModelTest method testReadWrite.

/**
 * Testing reading and writing using {@link DatabaseSession}.
 */
@Test
public void testReadWrite() throws Exception {
    final Address address = ModelHelper.buildAddress();
    final List<LineItem> lineItems = ModelHelper.buildLineItemsList();
    final Order order = ModelHelper.buildOrder(address, lineItems);
    final XMLInteraction insertCall = new XMLInteraction();
    insertCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.PUT.name());
    final InsertObjectQuery insert = new InsertObjectQuery(order);
    insert.setCall(insertCall);
    session.executeQuery(insert);
    final XMLInteraction readCall = new XMLInteraction();
    readCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.GET.name());
    readCall.addArgumentValue("@id", order.id);
    session.getIdentityMapAccessor().initializeIdentityMaps();
    final Order dbOrder = (Order) session.readObject(Order.class, readCall);
    assertNotNull("Returned Order instance is null", dbOrder);
    assertEquals(String.format("Order not returned properly: %s", dbOrder), order.address.city, dbOrder.address.city);
}
Also used : Order(org.eclipse.persistence.testing.models.order.Order) Address(org.eclipse.persistence.testing.models.order.Address) LineItem(org.eclipse.persistence.testing.models.order.LineItem) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery) XMLInteraction(org.eclipse.persistence.eis.interactions.XMLInteraction) Test(org.junit.Test)

Example 2 with XMLInteraction

use of org.eclipse.persistence.eis.interactions.XMLInteraction in project eclipselink by eclipse-ee4j.

the class NoSQLModelTest method setupOrderDescriptor.

/**
 * Setup {@link Order} class descriptor.
 * @param session Database session.
 */
private static void setupOrderDescriptor(final DatabaseSession session) {
    final ClassDescriptor descriptor = session.getDescriptor(Order.class);
    descriptor.getPrimaryKeyFields().clear();
    descriptor.addPrimaryKeyField(new XMLField("@id"));
    ((EISDirectMapping) descriptor.getMappingForAttributeName("id")).setFieldName("@id");
    // Insert
    final XMLInteraction insertCall = new XMLInteraction();
    insertCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.PUT);
    descriptor.getQueryManager().setInsertCall(insertCall);
    // Update
    final XMLInteraction updateCall = new XMLInteraction();
    updateCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.PUT);
    descriptor.getQueryManager().setUpdateCall(updateCall);
    // Read
    final XMLInteraction readCall = new XMLInteraction();
    readCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.GET);
    readCall.addArgument("@id");
    descriptor.getQueryManager().setReadObjectCall(readCall);
    // Delete
    final XMLInteraction deleteCall = new XMLInteraction();
    deleteCall.setProperty(OracleNoSQLPlatform.OPERATION, OracleNoSQLOperation.DELETE);
    deleteCall.addArgument("@id");
    descriptor.getQueryManager().setDeleteCall(deleteCall);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping) XMLInteraction(org.eclipse.persistence.eis.interactions.XMLInteraction)

Example 3 with XMLInteraction

use of org.eclipse.persistence.eis.interactions.XMLInteraction 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));
}
Also used : Order(org.eclipse.persistence.testing.models.jpa.nosql.Order) MappedInteraction(org.eclipse.persistence.eis.interactions.MappedInteraction) TypedQuery(jakarta.persistence.TypedQuery) Query(jakarta.persistence.Query) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) DataRecord(org.eclipse.persistence.sessions.DataRecord) XMLInteraction(org.eclipse.persistence.eis.interactions.XMLInteraction) Test(org.junit.Test)

Example 4 with XMLInteraction

use of org.eclipse.persistence.eis.interactions.XMLInteraction in project eclipselink by eclipse-ee4j.

the class OrderAmendments method addToOrderDescriptor.

public static void addToOrderDescriptor(ClassDescriptor descriptor) {
    // Define common Interaction properties.
    descriptor.setProperty(AQPlatform.QUEUE, "raw_order_queue");
    // Schema name is configured in test.properties and looks like tests are working without setting it here.
    // descriptor.setProperty(AQPlatform.SCHEMA, "aquser");
    // Insert
    XMLInteraction insertCall = new XMLInteraction();
    insertCall.setProperty(AQPlatform.QUEUE_OPERATION, "enqueue");
    insertCall.setInputRootElementName("insert-order");
    descriptor.getQueryManager().setInsertCall(insertCall);
    // Read
    XMLInteraction request = new XMLInteraction();
    request.setProperty(AQPlatform.QUEUE_OPERATION, "enqueue");
    request.setInputRootElementName("read-order");
    request.addArgument("@id");
    XMLInteraction response = new XMLInteraction();
    response.setProperty(AQPlatform.QUEUE_OPERATION, "dequeue");
    ReadObjectQuery query = new ReadObjectQuery();
    query.addCall(request);
    query.addCall(response);
    descriptor.getQueryManager().setReadObjectQuery(query);
}
Also used : ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) XMLInteraction(org.eclipse.persistence.eis.interactions.XMLInteraction)

Example 5 with XMLInteraction

use of org.eclipse.persistence.eis.interactions.XMLInteraction in project eclipselink by eclipse-ee4j.

the class EISObjectPersistenceXMLProject method buildXMLInteractionDescriptor.

protected ClassDescriptor buildXMLInteractionDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(XMLInteraction.class);
    descriptor.descriptorIsAggregate();
    descriptor.getInheritancePolicy().setParentClass(Call.class);
    XMLDirectMapping functionNameMapping = new XMLDirectMapping();
    functionNameMapping.setAttributeName("functionName");
    functionNameMapping.setGetMethodName("getFunctionName");
    functionNameMapping.setSetMethodName("setFunctionName");
    functionNameMapping.setXPath(getPrimaryNamespaceXPath() + "function-name/text()");
    functionNameMapping.setNullValue("");
    descriptor.addMapping(functionNameMapping);
    XMLDirectMapping inputRecordNameMapping = new XMLDirectMapping();
    inputRecordNameMapping.setAttributeName("inputRecordName");
    inputRecordNameMapping.setGetMethodName("getInputRecordName");
    inputRecordNameMapping.setSetMethodName("setInputRecordName");
    inputRecordNameMapping.setXPath(getPrimaryNamespaceXPath() + "input-record-name/text()");
    inputRecordNameMapping.setNullValue("");
    descriptor.addMapping(inputRecordNameMapping);
    XMLDirectMapping inputRootElementNameMapping = new XMLDirectMapping();
    inputRootElementNameMapping.setAttributeName("inputRootElementName");
    inputRootElementNameMapping.setGetMethodName("getInputRootElementName");
    inputRootElementNameMapping.setSetMethodName("setInputRootElementName");
    inputRootElementNameMapping.setXPath(getPrimaryNamespaceXPath() + "input-root-element-name/text()");
    inputRootElementNameMapping.setNullValue("");
    descriptor.addMapping(inputRootElementNameMapping);
    XMLDirectMapping inputResultPathMapping = new XMLDirectMapping();
    inputResultPathMapping.setAttributeName("inputResultPath");
    inputResultPathMapping.setGetMethodName("getInputResultPath");
    inputResultPathMapping.setSetMethodName("setInputResultPath");
    inputResultPathMapping.setXPath(getPrimaryNamespaceXPath() + "input-result-path/text()");
    inputResultPathMapping.setNullValue("");
    descriptor.addMapping(inputResultPathMapping);
    XMLDirectMapping outputResultPathMapping = new XMLDirectMapping();
    outputResultPathMapping.setAttributeName("outputResultPath");
    outputResultPathMapping.setGetMethodName("getOutputResultPath");
    outputResultPathMapping.setSetMethodName("setOutputResultPath");
    outputResultPathMapping.setXPath(getPrimaryNamespaceXPath() + "output-result-path/text()");
    outputResultPathMapping.setNullValue("");
    descriptor.addMapping(outputResultPathMapping);
    XMLCompositeCollectionMapping argumentsMapping = new XMLCompositeCollectionMapping();
    // Handle translation of argument lists to interaction-arguments.
    argumentsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            XMLInteraction interaction = (XMLInteraction) object;
            Vector<String> argumentNames = interaction.getArgumentNames();
            Vector<?> arguments = interaction.getArguments();
            Vector<InteractionArgument> interactionArguments = new Vector<>(arguments.size());
            for (int index = 0; index < arguments.size(); index++) {
                InteractionArgument interactionArgument = new InteractionArgument();
                interactionArgument.setArgumentName(argumentNames.get(index));
                Object argument = arguments.get(index);
                if (argument instanceof DatabaseField) {
                    interactionArgument.setKey(argument);
                } else {
                    interactionArgument.setValue(argument);
                }
                interactionArguments.add(interactionArgument);
            }
            return interactionArguments;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            XMLInteraction interaction = (XMLInteraction) object;
            @SuppressWarnings({ "unchecked" }) Vector<InteractionArgument> interactionArguments = (Vector<InteractionArgument>) value;
            Vector<DatabaseField> arguments = new Vector<>(interactionArguments.size());
            Vector<String> argumentNames = new Vector<>(interactionArguments.size());
            Vector<Object> values = new Vector<>(interactionArguments.size());
            for (int index = 0; index < interactionArguments.size(); index++) {
                InteractionArgument interactionArgument = interactionArguments.get(index);
                if (interactionArgument.getKey() != null) {
                    arguments.add(new DatabaseField((String) interactionArgument.getKey()));
                }
                if (interactionArgument.getValue() != null) {
                    values.add(interactionArgument.getValue());
                }
                if (interactionArgument.getArgumentName() != null) {
                    argumentNames.add(interactionArgument.getArgumentName());
                }
            }
            if (!arguments.isEmpty()) {
                interaction.setArguments(arguments);
            } else if (!values.isEmpty()) {
                interaction.setArguments(values);
            }
            if (!argumentNames.isEmpty()) {
                interaction.setArgumentNames(argumentNames);
            }
        }
    });
    argumentsMapping.setAttributeName("arguments");
    argumentsMapping.setXPath(getPrimaryNamespaceXPath() + "input-arguments/" + getPrimaryNamespaceXPath() + "argument");
    argumentsMapping.setReferenceClass(InteractionArgument.class);
    descriptor.addMapping(argumentsMapping);
    XMLCompositeCollectionMapping outputArgumentsMapping = new XMLCompositeCollectionMapping();
    // Handle translation of argument lists to interaction-arguments.
    outputArgumentsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            XMLInteraction interaction = (XMLInteraction) object;
            Vector<DatabaseField> arguments = interaction.getOutputArguments();
            Vector<String> argumentNames = interaction.getOutputArgumentNames();
            Vector<InteractionArgument> interactionArguments = new Vector<>(arguments.size());
            for (int index = 0; index < arguments.size(); index++) {
                InteractionArgument interactionArgument = new InteractionArgument();
                interactionArgument.setKey(arguments.get(index).getName());
                interactionArgument.setArgumentName(argumentNames.get(index));
                interactionArguments.add(interactionArgument);
            }
            return interactionArguments;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            XMLInteraction interaction = (XMLInteraction) object;
            @SuppressWarnings({ "unchecked" }) Vector<InteractionArgument> interactionArguments = (Vector<InteractionArgument>) value;
            Vector<DatabaseField> arguments = new Vector<>(interactionArguments.size());
            Vector<String> argumentNames = new Vector<>(interactionArguments.size());
            for (int index = 0; index < interactionArguments.size(); index++) {
                InteractionArgument interactionArgument = interactionArguments.get(index);
                arguments.add(new DatabaseField((String) interactionArgument.getKey()));
                argumentNames.add(interactionArgument.getArgumentName());
            }
            interaction.setOutputArguments(arguments);
            interaction.setOutputArgumentNames(argumentNames);
        }
    });
    outputArgumentsMapping.setAttributeName("outputArguments");
    outputArgumentsMapping.setXPath(getPrimaryNamespaceXPath() + "output-arguments/" + getPrimaryNamespaceXPath() + "argument");
    outputArgumentsMapping.setReferenceClass(InteractionArgument.class);
    descriptor.addMapping(outputArgumentsMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) InteractionArgument(org.eclipse.persistence.internal.descriptors.InteractionArgument) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) XMLInteraction(org.eclipse.persistence.eis.interactions.XMLInteraction) Vector(java.util.Vector)

Aggregations

XMLInteraction (org.eclipse.persistence.eis.interactions.XMLInteraction)10 Test (org.junit.Test)4 MappedInteraction (org.eclipse.persistence.eis.interactions.MappedInteraction)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 InsertObjectQuery (org.eclipse.persistence.queries.InsertObjectQuery)2 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)2 Address (org.eclipse.persistence.testing.models.order.Address)2 LineItem (org.eclipse.persistence.testing.models.order.LineItem)2 Order (org.eclipse.persistence.testing.models.order.Order)2 Query (jakarta.persistence.Query)1 TypedQuery (jakarta.persistence.TypedQuery)1 MappedRecord (jakarta.resource.cci.MappedRecord)1 StringWriter (java.io.StringWriter)1 Vector (java.util.Vector)1 AQDequeueOption (oracle.AQ.AQDequeueOption)1 EISDescriptor (org.eclipse.persistence.eis.EISDescriptor)1 EISException (org.eclipse.persistence.eis.EISException)1 EISMappedRecord (org.eclipse.persistence.eis.EISMappedRecord)1 EISInteraction (org.eclipse.persistence.eis.interactions.EISInteraction)1