Browse Source

datasource access makes the template fail

issue/1929-upgrade-hsql
Jens Schauder 1 year ago
parent
commit
535897513e
No known key found for this signature in database
GPG Key ID: 74F6C554AE971567
  1. 1
      spring-data-jdbc/pom.xml
  2. 56
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java

1
spring-data-jdbc/pom.xml

@ -109,6 +109,7 @@ @@ -109,6 +109,7 @@
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
<scope>test</scope>
<classifier>debug</classifier>
</dependency>
<dependency>

56
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java

@ -15,11 +15,17 @@ @@ -15,11 +15,17 @@
*/
package org.springframework.data.jdbc.repository;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@ -53,6 +59,7 @@ import org.springframework.jdbc.support.KeyHolder; @@ -53,6 +59,7 @@ import org.springframework.jdbc.support.KeyHolder;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests {
public static final String INSERT_MAIN = "INSERT INTO \"DUMMY_ENTITY2\" (\"ID\", \"TEST\") VALUES";
@Autowired NamedParameterJdbcTemplate template;
@Autowired DummyEntityRepository repository;
@Autowired Dialect dialect;
@ -79,31 +86,58 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { @@ -79,31 +86,58 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests {
@Test
@Order(1)
void jdbcTemplateOne() {
System.out.println("insertJdbcTemplate");
insert();
void dsOne() {
insertDataSource();
}
@Test
@Order(2)
void dsTwo() {
insertDataSource();
}
private void insertDataSource() {
try (Connection connection = dataSource.getConnection()) {
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_MAIN + "(?, ?)", Statement.RETURN_GENERATED_KEYS);
preparedStatement.setInt(1, 4711);
preparedStatement.setString(2, "text1");
preparedStatement.executeUpdate();
try (ResultSet resultSet = preparedStatement.getGeneratedKeys()) {
while (resultSet.next()) {
System.out.println("rs element");
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
@Test
@Order(10)
void jdbcTemplateOne() {
insertJdbcTemplate();
}
@Test
@Order(20)
void jdbcTemplateTwo() {
System.out.println("rerunJdbcTemplate");
insert();
insertJdbcTemplate();
}
private void insert() {
private void insertJdbcTemplate() {
Map<String, ?> params = Map.of("id", 4711, "test", "text1");
MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource(params);
SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] {sqlParameterSource};
KeyHolder keyHolder = new GeneratedKeyHolder();
template.update("INSERT INTO \"DUMMY_ENTITY2\" (\"ID\", \"TEST\") VALUES (:id, :test)", sqlParameterSource,
template.update(INSERT_MAIN + " (:id, :test)", sqlParameterSource,
keyHolder);
}
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {
List<DummyEntity> findByTest(String test);
}

Loading…
Cancel
Save