Search in sources :

Example 1 with JpaParameter

use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.

the class ExpressionEvaluatingParameterSourceFactoryTests method testMapInputWithMappedExpressionResolveStatic.

@Test
public void testMapInputWithMappedExpressionResolveStatic() {
    List<JpaParameter> parameters = new ArrayList<JpaParameter>();
    parameters.add(new JpaParameter("spam", null, "#staticParameters['foo'].toUpperCase()"));
    parameters.add(new JpaParameter("foo", "bar", null));
    factory.setParameters(parameters);
    ParameterSource source = factory.createParameterSource(Collections.singletonMap("crap", "bucket"));
    assertTrue(source.hasValue("spam"));
    assertEquals("BAR", source.getValue("spam"));
}
Also used : JpaParameter(org.springframework.integration.jpa.support.JpaParameter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with JpaParameter

use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.

the class JpaMessageHandlerParserTests method testProcedureParametersAreSet.

@SuppressWarnings("unchecked")
@Test
public void testProcedureParametersAreSet() throws Exception {
    setUp("JpaMessageHandlerParserTestsWithEmFactory.xml", getClass());
    final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
    final List<JpaParameter> jpaParameters = TestUtils.getPropertyValue(jpaExecutor, "jpaParameters", List.class);
    assertTrue(jpaParameters.size() == 3);
    JpaParameter parameter1 = jpaParameters.get(0);
    JpaParameter parameter2 = jpaParameters.get(1);
    JpaParameter parameter3 = jpaParameters.get(2);
    assertEquals("firstName", parameter1.getName());
    assertEquals("firstaName", parameter2.getName());
    assertEquals("updatedDateTime", parameter3.getName());
    assertEquals("kenny", parameter1.getValue());
    assertEquals("cartman", parameter2.getValue());
    assertNull(parameter3.getValue());
    assertNull(parameter1.getExpression());
    assertNull(parameter2.getExpression());
    assertEquals("new java.util.Date()", parameter3.getExpression());
}
Also used : JpaParameter(org.springframework.integration.jpa.support.JpaParameter) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) Test(org.junit.Test)

Example 3 with JpaParameter

use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.

the class JpaMessageHandlerParserTests method testJpaMessageHandlerParser.

@Test
public void testJpaMessageHandlerParser() throws Exception {
    setUp("JpaMessageHandlerParserTests.xml", getClass());
    final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class);
    assertEquals("target", inputChannel.getComponentName());
    final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
    assertNotNull(jpaExecutor);
    final String query = TestUtils.getPropertyValue(jpaExecutor, "jpaQuery", String.class);
    assertEquals("from Student", query);
    final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
    assertNotNull(jpaOperations);
    final PersistMode persistMode = TestUtils.getPropertyValue(jpaExecutor, "persistMode", PersistMode.class);
    assertEquals(PersistMode.PERSIST, persistMode);
    @SuppressWarnings("unchecked") List<JpaParameter> jpaParameters = TestUtils.getPropertyValue(jpaExecutor, "jpaParameters", List.class);
    assertNotNull(jpaParameters);
    assertTrue(jpaParameters.size() == 3);
    assertEquals(Integer.valueOf(10), TestUtils.getPropertyValue(jpaExecutor, "flushSize", Integer.class));
    assertTrue(TestUtils.getPropertyValue(jpaExecutor, "clearOnFlush", Boolean.class));
}
Also used : PersistMode(org.springframework.integration.jpa.support.PersistMode) JpaParameter(org.springframework.integration.jpa.support.JpaParameter) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) JpaOperations(org.springframework.integration.jpa.core.JpaOperations) Test(org.junit.Test)

Example 4 with JpaParameter

use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.

the class ExpressionEvaluatingParameterSourceUtils method convertStaticParameters.

/**
 * Utility method that converts a Collection of {@link JpaParameter} to
 * a Map containing only static parameters.
 *
 * @param jpaParameters Must not be null.
 * @return Map containing only the static parameters. Will never be null.
 */
public static Map<String, Object> convertStaticParameters(Collection<JpaParameter> jpaParameters) {
    Assert.notNull(jpaParameters, "The Collection of jpaParameters must not be null.");
    for (JpaParameter parameter : jpaParameters) {
        Assert.notNull(parameter, "'jpaParameters' must not contain null values.");
    }
    final Map<String, Object> staticParameters = new HashMap<String, Object>();
    for (JpaParameter parameter : jpaParameters) {
        if (parameter.getValue() != null) {
            staticParameters.put(parameter.getName(), parameter.getValue());
        }
    }
    return staticParameters;
}
Also used : JpaParameter(org.springframework.integration.jpa.support.JpaParameter) HashMap(java.util.HashMap)

Example 5 with JpaParameter

use of org.springframework.integration.jpa.support.JpaParameter in project spring-integration by spring-projects.

the class JpaExecutorTests method getJpaExecutorForMessageAsParamSource.

private JpaExecutor getJpaExecutorForMessageAsParamSource(String query) {
    JpaExecutor executor = new JpaExecutor(entityManager);
    ExpressionEvaluatingParameterSourceFactory factory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
    factory.setParameters(Collections.singletonList(new JpaParameter("firstName", null, "payload['firstName']")));
    executor.setParameterSourceFactory(factory);
    executor.setJpaQuery(query);
    executor.setExpectSingleResult(true);
    executor.setUsePayloadAsParameterSource(false);
    executor.afterPropertiesSet();
    return executor;
}
Also used : JpaParameter(org.springframework.integration.jpa.support.JpaParameter) BeanFactory(org.springframework.beans.factory.BeanFactory) ExpressionEvaluatingParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)

Aggregations

JpaParameter (org.springframework.integration.jpa.support.JpaParameter)11 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)3 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)2 JpaOperations (org.springframework.integration.jpa.core.JpaOperations)2 PersistMode (org.springframework.integration.jpa.support.PersistMode)2 ExpressionEvaluatingParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)2 HashMap (java.util.HashMap)1