Spring 集成Jpa |在 java dsl 中使用 Jpa 插入行
Spring integration Jpa | To insert row with Jpa in java dsl
我在互联网上搜索了很多,但找不到以下内容的句柄:
插入行的具体示例JpaUpdatingOutboundEndpointSpec
。
@Bean
public JpaUpdatingOutboundEndpointSpec insertToTable() {
return Jpa.updatingGateway(entityManger)
.entityClass(EntitySample.class);
}
以上够了吗?
请帮助我。
没错,在某些情况下,该代码可能就足够了。从这里知道您将如何使用此代码会很棒。虽然同时我会与您分享我的测试配置和测试本身:
@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());
}
您可以在框架的测试 class 中找到更多关于 Spring 集成 Java DSL for JPA 的测试:https://github.com/spring-projects/spring-integration/blob/master/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/dsl/JpaTests.java
我在互联网上搜索了很多,但找不到以下内容的句柄:
插入行的具体示例JpaUpdatingOutboundEndpointSpec
。
@Bean
public JpaUpdatingOutboundEndpointSpec insertToTable() {
return Jpa.updatingGateway(entityManger)
.entityClass(EntitySample.class);
}
以上够了吗?
请帮助我。
没错,在某些情况下,该代码可能就足够了。从这里知道您将如何使用此代码会很棒。虽然同时我会与您分享我的测试配置和测试本身:
@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());
}
您可以在框架的测试 class 中找到更多关于 Spring 集成 Java DSL for JPA 的测试:https://github.com/spring-projects/spring-integration/blob/master/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/dsl/JpaTests.java