From 947e330e9d4cfc537213554f855f6c551e4d3652 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 31 Aug 2023 13:15:50 +0200 Subject: [PATCH] Polish "Include JdbcClientAutoConfiguration in @JdbcTest and @DataJpaTest slices" See gh-37122 --- .../jdbc/ExampleJdbcClientRepository.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleJdbcClientRepository.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleJdbcClientRepository.java index 1140090d4b..3ba4216471 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleJdbcClientRepository.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleJdbcClientRepository.java @@ -18,10 +18,7 @@ package org.springframework.boot.test.autoconfigure.jdbc; import java.util.Collection; -import jakarta.transaction.Transactional; - import org.springframework.jdbc.core.simple.JdbcClient; -import org.springframework.stereotype.Repository; /** * Example repository used with {@link JdbcClient JdbcClient} and @@ -29,33 +26,31 @@ import org.springframework.stereotype.Repository; * * @author Yanming Zhou */ -@Repository -public class ExampleJdbcClientRepository { +class ExampleJdbcClientRepository { private static final ExampleEntityRowMapper ROW_MAPPER = new ExampleEntityRowMapper(); private final JdbcClient jdbcClient; - public ExampleJdbcClientRepository(JdbcClient jdbcClient) { + ExampleJdbcClientRepository(JdbcClient jdbcClient) { this.jdbcClient = jdbcClient; } - @Transactional - public void save(ExampleEntity entity) { + void save(ExampleEntity entity) { this.jdbcClient.sql("insert into example (id, name) values (:id, :name)") .param("id", entity.getId()) .param("name", entity.getName()) .update(); } - public ExampleEntity findById(int id) { - return this.jdbcClient.sql("select id, name from example where id =:id") + ExampleEntity findById(int id) { + return this.jdbcClient.sql("select id, name from example where id = :id") .param("id", id) .query(ROW_MAPPER) .single(); } - public Collection findAll() { + Collection findAll() { return this.jdbcClient.sql("select id, name from example").query(ROW_MAPPER).list(); }