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