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());
}
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);
}
}
Aggregations