I have searched quite some bit on the internet, but could not get a handle for below:
A concrete example to insert a row with JpaUpdatingOutboundEndpointSpec
.
@Bean
public JpaUpdatingOutboundEndpointSpec insertToTable() {
return Jpa.updatingGateway(entityManger)
.entityClass(EntitySample.class);
}
Will above be enough?
Please help me.
That's correct, that code might be really enough in some case. From here it would be great to know how you are going to use this code. Although meanwhile I'll share with you my configuration from the test and a test per se:
@Bean
public IntegrationFlow outboundAdapterFlow(EntityManagerFactory entityManagerFactory) {
return f -> f
.handle(Jpa.outboundAdapter(entityManagerFactory)
.entityClass(StudentDomain.class)
.persistMode(PersistMode.PERSIST),
e -> e.transactional(true));
}
...
@Autowired
@Qualifier("outboundAdapterFlow.input")
private MessageChannel outboundAdapterFlowInput;
@Test
public void testOutboundAdapterFlow() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
List<?> results1 = jdbcTemplate.queryForList("Select * from Student");
assertNotNull(results1);
assertTrue(results1.size() == 3);
Calendar dateOfBirth = Calendar.getInstance();
dateOfBirth.set(1981, 9, 27);
StudentDomain student = new StudentDomain()
.withFirstName("Artem")
.withLastName("Bilan")
.withGender(Gender.MALE)
.withDateOfBirth(dateOfBirth.getTime())
.withLastUpdated(new Date());
assertNull(student.getRollNumber());
this.outboundAdapterFlowInput.send(MessageBuilder.withPayload(student).build());
List<?> results2 = jdbcTemplate.queryForList("Select * from Student");
assertNotNull(results2);
assertTrue(results2.size() == 4);
assertNotNull(student.getRollNumber());
}
You can find more tests about Spring Integration Java DSL for JPA in the test class fo the framework: https://github.com/spring-projects/spring-integration/blob/master/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/dsl/JpaTests.java