Search in sources :

Example 1 with ExpressionEvaluatingParameterSourceFactory

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

the class AbstractJpaOperationsTests method testExecuteUpdateWithNamedQuery.

public void testExecuteUpdateWithNamedQuery() {
    final JpaOperations jpaOperations = getJpaOperations(entityManager);
    final StudentDomain student = JpaTestUtils.getTestStudent();
    ParameterSourceFactory requestParameterSourceFactory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
    ParameterSource source = requestParameterSourceFactory.createParameterSource(student);
    int updatedRecords = jpaOperations.executeUpdateWithNamedQuery("updateStudent", source);
    entityManager.flush();
    Assert.assertTrue(1 == updatedRecords);
    Assert.assertNull(student.getRollNumber());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) ParameterSource(org.springframework.integration.jpa.support.parametersource.ParameterSource) BeanFactory(org.springframework.beans.factory.BeanFactory) ParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ParameterSourceFactory) ExpressionEvaluatingParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory) ExpressionEvaluatingParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)

Example 2 with ExpressionEvaluatingParameterSourceFactory

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

the class AbstractJpaOperationsTests method testExecuteUpdateWithNativeQuery.

public void testExecuteUpdateWithNativeQuery() {
    final JpaOperations jpaOperations = getJpaOperations(entityManager);
    final StudentDomain student = JpaTestUtils.getTestStudent();
    ExpressionEvaluatingParameterSourceFactory requestParameterSourceFactory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
    ParameterSource source = requestParameterSourceFactory.createParameterSource(student);
    int updatedRecords = jpaOperations.executeUpdateWithNativeQuery("update Student " + "set lastName = :lastName, lastUpdated = :lastUpdated " + "where rollNumber in (select max(a.rollNumber) from Student a)", source);
    entityManager.flush();
    Assert.assertTrue(1 == updatedRecords);
    Assert.assertNull(student.getRollNumber());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) ParameterSource(org.springframework.integration.jpa.support.parametersource.ParameterSource) BeanFactory(org.springframework.beans.factory.BeanFactory) ExpressionEvaluatingParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)

Example 3 with ExpressionEvaluatingParameterSourceFactory

use of org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory 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)

Example 4 with ExpressionEvaluatingParameterSourceFactory

use of org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory 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 5 with ExpressionEvaluatingParameterSourceFactory

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

the class AbstractJpaOperationsTests method testExecuteUpdateWithNativeNamedQuery.

public void testExecuteUpdateWithNativeNamedQuery() {
    final JpaOperations jpaOperations = getJpaOperations(entityManager);
    final StudentDomain student = JpaTestUtils.getTestStudent();
    ParameterSourceFactory requestParameterSourceFactory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
    ParameterSource source = requestParameterSourceFactory.createParameterSource(student);
    int updatedRecords = jpaOperations.executeUpdateWithNamedQuery("updateStudentNativeQuery", source);
    entityManager.flush();
    Assert.assertTrue(1 == updatedRecords);
    Assert.assertNull(student.getRollNumber());
}
Also used : StudentDomain(org.springframework.integration.jpa.test.entity.StudentDomain) ParameterSource(org.springframework.integration.jpa.support.parametersource.ParameterSource) BeanFactory(org.springframework.beans.factory.BeanFactory) ParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ParameterSourceFactory) ExpressionEvaluatingParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory) ExpressionEvaluatingParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)

Aggregations

ExpressionEvaluatingParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)7 BeanFactory (org.springframework.beans.factory.BeanFactory)6 ParameterSource (org.springframework.integration.jpa.support.parametersource.ParameterSource)4 StudentDomain (org.springframework.integration.jpa.test.entity.StudentDomain)4 ParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.ParameterSourceFactory)3 JpaParameter (org.springframework.integration.jpa.support.JpaParameter)2 BeanPropertyParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.BeanPropertyParameterSourceFactory)1