Search in sources :

Example 6 with ExpressionEvaluatingParameterSourceFactory

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

the class AbstractJpaOperationsTests method testExecuteUpdate.

public void testExecuteUpdate() {
    final JpaOperations jpaOperations = getJpaOperations(entityManager);
    final StudentDomain student = JpaTestUtils.getTestStudent();
    List<?> students = jpaOperations.getResultListForClass(StudentDomain.class, 0, 0);
    Assert.assertTrue(students.size() == 3);
    ParameterSourceFactory requestParameterSourceFactory = new ExpressionEvaluatingParameterSourceFactory(mock(BeanFactory.class));
    ParameterSource source = requestParameterSourceFactory.createParameterSource(student);
    int updatedRecords = jpaOperations.executeUpdate("update Student s " + "set s.lastName = :lastName, s.lastUpdated = :lastUpdated " + "where s.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) 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 7 with ExpressionEvaluatingParameterSourceFactory

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

the class JpaExecutor method afterPropertiesSet.

/**
 * Verify and sets the parameters. E.g. initializes the to be used
 * {@link ParameterSourceFactory}.
 */
@Override
public void afterPropertiesSet() {
    if (!CollectionUtils.isEmpty(this.jpaParameters)) {
        if (this.parameterSourceFactory == null) {
            ExpressionEvaluatingParameterSourceFactory expressionSourceFactory = new ExpressionEvaluatingParameterSourceFactory(this.beanFactory);
            expressionSourceFactory.setParameters(this.jpaParameters);
            this.parameterSourceFactory = expressionSourceFactory;
        } else {
            if (!(this.parameterSourceFactory instanceof ExpressionEvaluatingParameterSourceFactory)) {
                throw new IllegalStateException("You are providing 'JpaParameters'. " + "Was expecting the the provided jpaParameterSourceFactory " + "to be an instance of 'ExpressionEvaluatingJpaParameterSourceFactory', " + "however the provided one is of type '" + this.parameterSourceFactory.getClass().getName() + "'");
            }
        }
        if (this.usePayloadAsParameterSource == null) {
            this.usePayloadAsParameterSource = false;
        }
    } else {
        if (this.parameterSourceFactory == null) {
            this.parameterSourceFactory = new BeanPropertyParameterSourceFactory();
        }
        if (this.usePayloadAsParameterSource == null) {
            this.usePayloadAsParameterSource = true;
        }
    }
    if (this.flushSize > 0) {
        this.flush = true;
    } else if (this.flush) {
        this.flushSize = 1;
    }
    if (this.evaluationContext == null) {
        this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory);
    }
}
Also used : BeanPropertyParameterSourceFactory(org.springframework.integration.jpa.support.parametersource.BeanPropertyParameterSourceFactory) 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