Search in sources :

Example 1 with ParameterSourceFactory

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

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

Example 3 with ParameterSourceFactory

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

Aggregations

BeanFactory (org.springframework.beans.factory.BeanFactory)3 ExpressionEvaluatingParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.ExpressionEvaluatingParameterSourceFactory)3 ParameterSource (org.springframework.integration.jpa.support.parametersource.ParameterSource)3 ParameterSourceFactory (org.springframework.integration.jpa.support.parametersource.ParameterSourceFactory)3 StudentDomain (org.springframework.integration.jpa.test.entity.StudentDomain)3