Search in sources :

Example 6 with JpaParameter

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

the class JpaExecutorTests method getJpaExecutorForPayloadAsParamSource.

private JpaExecutor getJpaExecutorForPayloadAsParamSource(String query) {
    JpaExecutor executor = new JpaExecutor(entityManager);
    ExpressionEvaluatingParameterSourceFactory factory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
    factory.setParameters(Collections.singletonList(new JpaParameter("firstName", null, "#this")));
    executor.setParameterSourceFactory(factory);
    executor.setJpaQuery(query);
    executor.setExpectSingleResult(true);
    executor.setUsePayloadAsParameterSource(true);
    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)

Example 7 with JpaParameter

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

the class JpaMessageHandlerParserTests method testJpaMessageHandlerParserWithEntityManagerFactory.

@Test
public void testJpaMessageHandlerParserWithEntityManagerFactory() throws Exception {
    setUp("JpaMessageHandlerParserTestsWithEmFactory.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("select student from Student 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);
}
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 8 with JpaParameter

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

the class ExpressionEvaluatingParameterSourceFactoryTests method testPositionalExpressionParameters.

@Test
public void testPositionalExpressionParameters() {
    List<JpaParameter> parameters = new ArrayList<JpaParameter>();
    parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
    parameters.add(new JpaParameter("bar", null));
    factory.setParameters(parameters);
    PositionSupportingParameterSource source = factory.createParameterSource("very important");
    String position0 = (String) source.getValueByPosition(0);
    String position1 = (String) source.getValueByPosition(1);
    assertEquals("VERY IMPORTANT", position0);
    assertEquals("bar", position1);
}
Also used : JpaParameter(org.springframework.integration.jpa.support.JpaParameter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with JpaParameter

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

the class ExpressionEvaluatingParameterSourceFactoryTests method testPositionalStaticParameters.

@Test
public void testPositionalStaticParameters() {
    List<JpaParameter> parameters = new ArrayList<JpaParameter>();
    parameters.add(new JpaParameter("foo", null));
    parameters.add(new JpaParameter("bar", null));
    factory.setParameters(parameters);
    PositionSupportingParameterSource source = factory.createParameterSource("not important");
    String position0 = (String) source.getValueByPosition(0);
    String position1 = (String) source.getValueByPosition(1);
    assertEquals("foo", position0);
    assertEquals("bar", position1);
}
Also used : JpaParameter(org.springframework.integration.jpa.support.JpaParameter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with JpaParameter

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

the class ExpressionEvaluatingParameterSourceFactoryTests method testPositionalExpressionParameters2.

@Test
public void testPositionalExpressionParameters2() {
    List<JpaParameter> parameters = new ArrayList<JpaParameter>();
    parameters.add(new JpaParameter("bar", null));
    parameters.add(new JpaParameter(null, "#root.toUpperCase()"));
    factory.setParameters(parameters);
    PositionSupportingParameterSource source = factory.createParameterSource("very important");
    String position0 = (String) source.getValueByPosition(0);
    String position1 = (String) source.getValueByPosition(1);
    assertEquals("VERY IMPORTANT", position1);
    assertEquals("bar", position0);
}
Also used : JpaParameter(org.springframework.integration.jpa.support.JpaParameter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

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