diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java index 0794769435..8b901c12c6 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java @@ -221,7 +221,8 @@ private JdbcValue writeValue(@Nullable Object value, TypeInformation typeInfo TypeInformation actualType = typeInformation.getActualType(); - // tuple-binding + // allow tuple-binding for collection of byte arrays to be used as BINARY, + // we do not want to convert to column arrays. if (actualType != null && actualType.getType().isArray() && !actualType.getType().equals(byte[].class)) { TypeInformation nestedElementType = actualType.getRequiredActualType(); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java index c11335f216..0704a16ca0 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java @@ -34,6 +34,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.function.Consumer; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; @@ -41,6 +42,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.context.ApplicationListener; @@ -50,7 +52,16 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.data.annotation.Id; -import org.springframework.data.domain.*; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.data.domain.Limit; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.ScrollPosition; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Window; import org.springframework.data.jdbc.core.mapping.AggregateReference; import org.springframework.data.jdbc.repository.query.Modifying; import org.springframework.data.jdbc.repository.query.Query; @@ -107,18 +118,6 @@ public class JdbcRepositoryIntegrationTests { @Autowired WithDelimitedColumnRepository withDelimitedColumnRepository; - private static DummyEntity createDummyEntity() { - return createDummyEntity("Entity Name"); - } - - private static DummyEntity createDummyEntity(String entityName) { - - DummyEntity entity = new DummyEntity(); - entity.setName(entityName); - - return entity; - } - @BeforeEach public void before() { @@ -130,7 +129,7 @@ public void before() { @Test // DATAJDBC-95 public void savesAnEntity() { - DummyEntity entity = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); assertThat(JdbcTestUtils.countRowsInTableWhere(template.getJdbcOperations(), "dummy_entity", "id_Prop = " + entity.getIdProp())).isEqualTo(1); @@ -139,7 +138,7 @@ public void savesAnEntity() { @Test // DATAJDBC-95 public void saveAndLoadAnEntity() { - DummyEntity entity = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); assertThat(repository.findById(entity.getIdProp())).hasValueSatisfying(it -> { @@ -151,8 +150,8 @@ public void saveAndLoadAnEntity() { @Test // DATAJDBC-97 public void insertsManyEntities() { - DummyEntity entity = createDummyEntity(); - DummyEntity other = createDummyEntity(); + DummyEntity entity = createEntity(); + DummyEntity other = createEntity(); repository.saveAll(asList(entity, other)); @@ -164,7 +163,7 @@ public void insertsManyEntities() { @Test // DATAJDBC-97 public void existsReturnsTrueIffEntityExists() { - DummyEntity entity = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); assertThat(repository.existsById(entity.getIdProp())).isTrue(); assertThat(repository.existsById(entity.getIdProp() + 1)).isFalse(); @@ -173,8 +172,8 @@ public void existsReturnsTrueIffEntityExists() { @Test // DATAJDBC-97 public void findAllFindsAllEntities() { - DummyEntity entity = repository.save(createDummyEntity()); - DummyEntity other = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); + DummyEntity other = repository.save(createEntity()); Iterable all = repository.findAll(); @@ -186,8 +185,8 @@ public void findAllFindsAllEntities() { @Test // DATAJDBC-97 public void findAllFindsAllSpecifiedEntities() { - DummyEntity entity = repository.save(createDummyEntity()); - DummyEntity other = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); + DummyEntity other = repository.save(createEntity()); assertThat(repository.findAllById(asList(entity.getIdProp(), other.getIdProp())))// .extracting(DummyEntity::getIdProp)// @@ -197,9 +196,9 @@ public void findAllFindsAllSpecifiedEntities() { @Test // DATAJDBC-97 public void countsEntities() { - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); + repository.save(createEntity()); + repository.save(createEntity()); + repository.save(createEntity()); assertThat(repository.count()).isEqualTo(3L); } @@ -207,9 +206,9 @@ public void countsEntities() { @Test // DATAJDBC-97 public void deleteById() { - DummyEntity one = repository.save(createDummyEntity()); - DummyEntity two = repository.save(createDummyEntity()); - DummyEntity three = repository.save(createDummyEntity()); + DummyEntity one = repository.save(createEntity()); + DummyEntity two = repository.save(createEntity()); + DummyEntity three = repository.save(createEntity()); repository.deleteById(two.getIdProp()); @@ -221,9 +220,9 @@ public void deleteById() { @Test // DATAJDBC-97 public void deleteByEntity() { - DummyEntity one = repository.save(createDummyEntity()); - DummyEntity two = repository.save(createDummyEntity()); - DummyEntity three = repository.save(createDummyEntity()); + DummyEntity one = repository.save(createEntity()); + DummyEntity two = repository.save(createEntity()); + DummyEntity three = repository.save(createEntity()); repository.delete(one); @@ -235,9 +234,9 @@ public void deleteByEntity() { @Test // DATAJDBC-97 public void deleteByList() { - DummyEntity one = repository.save(createDummyEntity()); - DummyEntity two = repository.save(createDummyEntity()); - DummyEntity three = repository.save(createDummyEntity()); + DummyEntity one = repository.save(createEntity()); + DummyEntity two = repository.save(createEntity()); + DummyEntity three = repository.save(createEntity()); repository.deleteAll(asList(one, three)); @@ -249,9 +248,9 @@ public void deleteByList() { @Test // DATAJDBC-629 public void deleteByIdList() { - DummyEntity one = repository.save(createDummyEntity()); - DummyEntity two = repository.save(createDummyEntity()); - DummyEntity three = repository.save(createDummyEntity()); + DummyEntity one = repository.save(createEntity()); + DummyEntity two = repository.save(createEntity()); + DummyEntity three = repository.save(createEntity()); repository.deleteAllById(asList(one.idProp, three.idProp)); @@ -263,9 +262,9 @@ public void deleteByIdList() { @Test // DATAJDBC-97 public void deleteAll() { - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); + repository.save(createEntity()); + repository.save(createEntity()); + repository.save(createEntity()); assertThat(repository.findAll()).isNotEmpty(); @@ -277,7 +276,7 @@ public void deleteAll() { @Test // DATAJDBC-98 public void update() { - DummyEntity entity = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); entity.setName("something else"); DummyEntity saved = repository.save(entity); @@ -290,8 +289,8 @@ public void update() { @Test // DATAJDBC-98 public void updateMany() { - DummyEntity entity = repository.save(createDummyEntity()); - DummyEntity other = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); + DummyEntity other = repository.save(createEntity()); entity.setName("something else"); other.setName("others Name"); @@ -306,9 +305,9 @@ public void updateMany() { @Test // GH-537 void insertsOrUpdatesManyEntities() { - DummyEntity entity = repository.save(createDummyEntity()); + DummyEntity entity = repository.save(createEntity()); entity.setName("something else"); - DummyEntity other = createDummyEntity(); + DummyEntity other = createEntity(); other.setName("others name"); repository.saveAll(asList(other, entity)); @@ -342,7 +341,7 @@ public void executeQueryWithParameterRequiringConversion() { @Test // DATAJDBC-318 public void queryMethodShouldEmitEvents() { - repository.save(createDummyEntity()); + repository.save(createEntity()); eventListener.events.clear(); repository.findAllWithSql(); @@ -353,7 +352,7 @@ public void queryMethodShouldEmitEvents() { @Test // DATAJDBC-318 public void queryMethodWithCustomRowMapperDoesNotEmitEvents() { - repository.save(createDummyEntity()); + repository.save(createEntity()); eventListener.events.clear(); repository.findAllWithCustomMapper(); @@ -364,14 +363,14 @@ public void queryMethodWithCustomRowMapperDoesNotEmitEvents() { @Test // DATAJDBC-234 public void findAllByQueryName() { - repository.save(createDummyEntity()); + repository.save(createEntity()); assertThat(repository.findAllByNamedQuery()).hasSize(1); } @Test void findAllByFirstnameWithLock() { - DummyEntity dummyEntity = createDummyEntity(); + DummyEntity dummyEntity = createEntity(); repository.save(dummyEntity); assertThat(repository.findAllByName(dummyEntity.getName())).hasSize(1); } @@ -379,14 +378,14 @@ void findAllByFirstnameWithLock() { @Test // GH-1022 public void findAllByCustomQueryName() { - repository.save(createDummyEntity()); + repository.save(createEntity()); assertThat(repository.findAllByCustomNamedQuery()).hasSize(1); } @Test // DATAJDBC-341 public void findWithMissingQuery() { - DummyEntity dummy = repository.save(createDummyEntity()); + DummyEntity dummy = repository.save(createEntity()); DummyEntity loaded = repository.withMissingColumn(dummy.idProp); @@ -398,7 +397,7 @@ public void findWithMissingQuery() { @Test // DATAJDBC-529 public void existsWorksAsExpected() { - DummyEntity dummy = repository.save(createDummyEntity()); + DummyEntity dummy = repository.save(createEntity()); assertSoftly(softly -> { @@ -414,7 +413,7 @@ public void existsWorksAsExpected() { @Test // DATAJDBC-604 public void existsInWorksAsExpected() { - DummyEntity dummy = repository.save(createDummyEntity()); + DummyEntity dummy = repository.save(createEntity()); assertSoftly(softly -> { @@ -430,7 +429,7 @@ public void existsInWorksAsExpected() { @Test // DATAJDBC-604 public void existsNotInWorksAsExpected() { - DummyEntity dummy = repository.save(createDummyEntity()); + DummyEntity dummy = repository.save(createEntity()); assertSoftly(softly -> { @@ -446,10 +445,10 @@ public void existsNotInWorksAsExpected() { @Test // DATAJDBC-534 public void countByQueryDerivation() { - DummyEntity one = createDummyEntity(); - DummyEntity two = createDummyEntity(); + DummyEntity one = createEntity(); + DummyEntity two = createEntity(); two.name = "other"; - DummyEntity three = createDummyEntity(); + DummyEntity three = createEntity(); repository.saveAll(asList(one, two, three)); @@ -458,7 +457,7 @@ public void countByQueryDerivation() { @Test // GH-619 public void findBySpElWorksAsExpected() { - DummyEntity r = repository.save(createDummyEntity()); + DummyEntity r = repository.save(createEntity()); // assign the new id to the global ID provider holder; this is similar to Spring Security's SecurityContextHolder MyIdContextProvider.ExtensionRoot.ID = r.getIdProp(); @@ -530,7 +529,7 @@ public void queryByOffsetDateTime() { @Test // GH-971 public void stringQueryProjectionShouldReturnProjectedEntities() { - repository.save(createDummyEntity()); + repository.save(createEntity()); List result = repository.findProjectedWithSql(DummyProjection.class); @@ -541,7 +540,7 @@ public void stringQueryProjectionShouldReturnProjectedEntities() { @Test // GH-971 public void stringQueryProjectionShouldReturnDtoProjectedEntities() { - repository.save(createDummyEntity()); + repository.save(createEntity()); List result = repository.findProjectedWithSql(DtoProjection.class); @@ -552,7 +551,7 @@ public void stringQueryProjectionShouldReturnDtoProjectedEntities() { @Test // GH-971 public void partTreeQueryProjectionShouldReturnProjectedEntities() { - repository.save(createDummyEntity()); + repository.save(createEntity()); List result = repository.findProjectedByName("Entity Name"); @@ -563,7 +562,7 @@ public void partTreeQueryProjectionShouldReturnProjectedEntities() { @Test // GH-971 public void pageQueryProjectionShouldReturnProjectedEntities() { - repository.save(createDummyEntity()); + repository.save(createEntity()); Page result = repository.findPageProjectionByName("Entity Name", PageRequest.ofSize(10)); @@ -581,8 +580,8 @@ void intervalCalculation() { @Test // GH-908 void derivedQueryWithBooleanLiteralFindsCorrectValues() { - repository.save(createDummyEntity()); - DummyEntity entity = createDummyEntity(); + repository.save(createEntity()); + DummyEntity entity = createEntity(); entity.flag = true; entity = repository.save(entity); @@ -594,8 +593,8 @@ void derivedQueryWithBooleanLiteralFindsCorrectValues() { @Test // GH-987 void queryBySimpleReference() { - DummyEntity one = repository.save(createDummyEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity one = repository.save(createEntity()); + DummyEntity two = createEntity(); two.ref = AggregateReference.to(one.idProp); two = repository.save(two); @@ -607,8 +606,8 @@ void queryBySimpleReference() { @Test // GH-987 void queryByAggregateReference() { - DummyEntity one = repository.save(createDummyEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity one = repository.save(createEntity()); + DummyEntity two = createEntity(); two.ref = AggregateReference.to(one.idProp); two = repository.save(two); @@ -620,7 +619,7 @@ void queryByAggregateReference() { @Test // GH-1167 void stringResult() { - repository.save(createDummyEntity()); // just ensure we have data in the table + repository.save(createEntity()); // just ensure we have data in the table assertThat(repository.returnInput("HELLO")).isEqualTo("HELLO"); } @@ -628,7 +627,7 @@ void stringResult() { @Test // GH-1167 void nullStringResult() { - repository.save(createDummyEntity()); // just ensure we have data in the table + repository.save(createEntity()); // just ensure we have data in the table assertThat(repository.returnInput(null)).isNull(); } @@ -726,11 +725,11 @@ void manyInsertsAndUpdatesWithNestedEntities() { @Test // GH-1192 void findOneByExampleShouldGetOne() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); - DummyEntity dummyEntity2 = createDummyEntity(); + DummyEntity dummyEntity2 = createEntity(); dummyEntity2.setName("Diego"); repository.save(dummyEntity2); @@ -743,10 +742,10 @@ void findOneByExampleShouldGetOne() { @Test // GH-1192 void findOneByExampleMultipleMatchShouldGetOne() { - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); + repository.save(createEntity()); + repository.save(createEntity()); - Example example = Example.of(createDummyEntity()); + Example example = Example.of(createEntity()); assertThatThrownBy(() -> repository.findOne(example)).isInstanceOf(IncorrectResultSizeDataAccessException.class) .hasMessageContaining("expected 1, actual 2"); @@ -755,7 +754,7 @@ void findOneByExampleMultipleMatchShouldGetOne() { @Test // GH-1192 void findOneByExampleShouldGetNone() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); @@ -769,11 +768,11 @@ void findOneByExampleShouldGetNone() { @Test // GH-1192 void findAllByExampleShouldGetOne() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); - DummyEntity dummyEntity2 = createDummyEntity(); + DummyEntity dummyEntity2 = createEntity(); dummyEntity2.setName("Diego"); repository.save(dummyEntity2); @@ -788,10 +787,10 @@ void findAllByExampleShouldGetOne() { @Test // GH-1192 void findAllByExampleMultipleMatchShouldGetOne() { - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); + repository.save(createEntity()); + repository.save(createEntity()); - Example example = Example.of(createDummyEntity()); + Example example = Example.of(createEntity()); Iterable allFound = repository.findAll(example); @@ -804,7 +803,7 @@ void findAllByExampleMultipleMatchShouldGetOne() { @Test // GH-1192 void findAllByExampleShouldGetNone() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); @@ -819,12 +818,12 @@ void findAllByExampleShouldGetNone() { @Test // GH-1192 void findAllByExamplePageableShouldGetOne() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); - DummyEntity dummyEntity2 = createDummyEntity(); + DummyEntity dummyEntity2 = createEntity(); dummyEntity2.setName("Diego"); repository.save(dummyEntity2); @@ -841,10 +840,10 @@ void findAllByExamplePageableShouldGetOne() { @Test // GH-1192 void findAllByExamplePageableMultipleMatchShouldGetOne() { - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); + repository.save(createEntity()); + repository.save(createEntity()); - Example example = Example.of(createDummyEntity()); + Example example = Example.of(createEntity()); Pageable pageRequest = PageRequest.of(0, 10); Iterable allFound = repository.findAll(example, pageRequest); @@ -858,7 +857,7 @@ void findAllByExamplePageableMultipleMatchShouldGetOne() { @Test // GH-1192 void findAllByExamplePageableShouldGetNone() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); @@ -874,10 +873,10 @@ void findAllByExamplePageableShouldGetNone() { @Test // GH-1192 void findAllByExamplePageableOutsidePageShouldGetNone() { - repository.save(createDummyEntity()); - repository.save(createDummyEntity()); + repository.save(createEntity()); + repository.save(createEntity()); - Example example = Example.of(createDummyEntity()); + Example example = Example.of(createEntity()); Pageable pageRequest = PageRequest.of(10, 10); Iterable allFound = repository.findAll(example, pageRequest); @@ -892,14 +891,14 @@ void findAllByExamplePageableOutsidePageShouldGetNone() { void findAllByExamplePageable(Pageable pageRequest, int size, int totalPages, List notContains) { for (int i = 0; i < 100; i++) { - DummyEntity dummyEntity = createDummyEntity(); + DummyEntity dummyEntity = createEntity(); dummyEntity.setFlag(true); dummyEntity.setName("" + i); repository.save(dummyEntity); } - DummyEntity dummyEntityExample = createDummyEntity(); + DummyEntity dummyEntityExample = createEntity(); dummyEntityExample.setName(null); dummyEntityExample.setFlag(true); @@ -939,11 +938,11 @@ public static Stream findAllByExamplePageableSource() { @Test // GH-1192 void existsByExampleShouldGetOne() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); - DummyEntity dummyEntity2 = createDummyEntity(); + DummyEntity dummyEntity2 = createEntity(); dummyEntity2.setName("Diego"); repository.save(dummyEntity2); @@ -957,13 +956,13 @@ void existsByExampleShouldGetOne() { @Test // GH-1192 void existsByExampleMultipleMatchShouldGetOne() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); repository.save(dummyEntity1); - DummyEntity dummyEntity2 = createDummyEntity(); + DummyEntity dummyEntity2 = createEntity(); repository.save(dummyEntity2); - Example example = Example.of(createDummyEntity()); + Example example = Example.of(createEntity()); boolean exists = repository.exists(example); assertThat(exists).isTrue(); @@ -972,7 +971,7 @@ void existsByExampleMultipleMatchShouldGetOne() { @Test // GH-1192 void existsByExampleShouldGetNone() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); @@ -989,14 +988,14 @@ void existsByExampleComplex() { Instant pointInTime = Instant.now().truncatedTo(ChronoUnit.MILLIS).minusSeconds(10000); - repository.save(createDummyEntity()); + repository.save(createEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName("Diego"); two.setPointInTime(pointInTime); repository.save(two); - DummyEntity exampleEntitiy = createDummyEntity(); + DummyEntity exampleEntitiy = createEntity(); exampleEntitiy.setName("Diego"); exampleEntitiy.setPointInTime(pointInTime); @@ -1009,12 +1008,12 @@ void existsByExampleComplex() { @Test // GH-1192 void countByExampleShouldGetOne() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); - DummyEntity dummyEntity2 = createDummyEntity(); + DummyEntity dummyEntity2 = createEntity(); dummyEntity2.setName("Diego"); repository.save(dummyEntity2); @@ -1029,13 +1028,13 @@ void countByExampleShouldGetOne() { @Test // GH-1192 void countByExampleMultipleMatchShouldGetOne() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); repository.save(dummyEntity1); - DummyEntity dummyEntity2 = createDummyEntity(); + DummyEntity dummyEntity2 = createEntity(); repository.save(dummyEntity2); - Example example = Example.of(createDummyEntity()); + Example example = Example.of(createEntity()); long count = repository.count(example); assertThat(count).isEqualTo(2); @@ -1044,7 +1043,7 @@ void countByExampleMultipleMatchShouldGetOne() { @Test // GH-1192 void countByExampleShouldGetNone() { - DummyEntity dummyEntity1 = createDummyEntity(); + DummyEntity dummyEntity1 = createEntity(); dummyEntity1.setFlag(true); repository.save(dummyEntity1); @@ -1060,14 +1059,14 @@ void countByExampleShouldGetNone() { void countByExampleComplex() { Instant pointInTime = Instant.now().minusSeconds(10000).truncatedTo(ChronoUnit.MILLIS); - repository.save(createDummyEntity()); + repository.save(createEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName("Diego"); two.setPointInTime(pointInTime); repository.save(two); - DummyEntity exampleEntitiy = createDummyEntity(); + DummyEntity exampleEntitiy = createEntity(); exampleEntitiy.setName("Diego"); exampleEntitiy.setPointInTime(pointInTime); @@ -1083,7 +1082,7 @@ void fetchByExampleFluentAllSimple() { String searchName = "Diego"; Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName(searchName); two.setPointInTime(now.minusSeconds(10000)); @@ -1092,7 +1091,7 @@ void fetchByExampleFluentAllSimple() { // I'm looking at you MariaDb. two = repository.findById(two.idProp).orElseThrow(); - DummyEntity third = createDummyEntity(); + DummyEntity third = createEntity(); third.setName(searchName); third.setPointInTime(now.minusSeconds(200000)); third = repository.save(third); @@ -1100,7 +1099,7 @@ void fetchByExampleFluentAllSimple() { // I'm looking at you MariaDb. third = repository.findById(third.idProp).orElseThrow(); - DummyEntity exampleEntitiy = createDummyEntity(); + DummyEntity exampleEntitiy = createEntity(); exampleEntitiy.setName(searchName); Example example = Example.of(exampleEntitiy); @@ -1151,20 +1150,20 @@ void fetchByExampleFluentCountSimple() { String searchName = "Diego"; Instant now = Instant.now(); - repository.save(createDummyEntity()); + repository.save(createEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName(searchName); two.setPointInTime(now.minusSeconds(10000)); repository.save(two); - DummyEntity third = createDummyEntity(); + DummyEntity third = createEntity(); third.setName(searchName); third.setPointInTime(now.minusSeconds(200000)); repository.save(third); - DummyEntity exampleEntitiy = createDummyEntity(); + DummyEntity exampleEntitiy = createEntity(); exampleEntitiy.setName(searchName); Example example = Example.of(exampleEntitiy); @@ -1179,9 +1178,9 @@ void fetchByExampleFluentOnlyInstantFirstSimple() { String searchName = "Diego"; Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS); - repository.save(createDummyEntity()); + repository.save(createEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName(searchName); two.setPointInTime(now.minusSeconds(10000)); @@ -1190,12 +1189,12 @@ void fetchByExampleFluentOnlyInstantFirstSimple() { // I'm looking at you MariaDb. two = repository.findById(two.idProp).orElseThrow(); - DummyEntity third = createDummyEntity(); + DummyEntity third = createEntity(); third.setName(searchName); third.setPointInTime(now.minusSeconds(200000)); repository.save(third); - DummyEntity exampleEntity = createDummyEntity(); + DummyEntity exampleEntity = createEntity(); exampleEntity.setName(searchName); Example example = Example.of(exampleEntity); @@ -1212,19 +1211,19 @@ void fetchByExampleFluentOnlyInstantOneValueError() { String searchName = "Diego"; Instant now = Instant.now(); - repository.save(createDummyEntity()); + repository.save(createEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName(searchName); two.setPointInTime(now.minusSeconds(10000)); repository.save(two); - DummyEntity third = createDummyEntity(); + DummyEntity third = createEntity(); third.setName(searchName); third.setPointInTime(now.minusSeconds(200000)); repository.save(third); - DummyEntity exampleEntitiy = createDummyEntity(); + DummyEntity exampleEntitiy = createEntity(); exampleEntitiy.setName(searchName); Example example = Example.of(exampleEntitiy); @@ -1239,9 +1238,9 @@ void fetchByExampleFluentOnlyInstantOneValueSimple() { String searchName = "Diego"; Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS); - repository.save(createDummyEntity()); + repository.save(createEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName(searchName); two.setPointInTime(now.minusSeconds(10000)); two = repository.save(two); @@ -1249,7 +1248,7 @@ void fetchByExampleFluentOnlyInstantOneValueSimple() { // I'm looking at you MariaDb. two = repository.findById(two.idProp).orElseThrow(); - DummyEntity exampleEntitiy = createDummyEntity(); + DummyEntity exampleEntitiy = createEntity(); exampleEntitiy.setName(searchName); Example example = Example.of(exampleEntitiy); @@ -1265,14 +1264,14 @@ void fetchByExampleFluentOnlyInstantOneValueAsSimple() { String searchName = "Diego"; Instant now = Instant.now(); - repository.save(createDummyEntity()); + repository.save(createEntity()); - DummyEntity two = createDummyEntity(); + DummyEntity two = createEntity(); two.setName(searchName); two.setPointInTime(now.minusSeconds(10000)); two = repository.save(two); - DummyEntity exampleEntity = createDummyEntity(); + DummyEntity exampleEntity = createEntity(); exampleEntity.setName(searchName); Example example = Example.of(exampleEntity); @@ -1333,9 +1332,9 @@ void withDelimitedColumnTest() { @EnabledOnFeature(TestDatabaseFeatures.Feature.WHERE_IN_TUPLE) void queryWithTupleIn() { - DummyEntity one = repository.save(createDummyEntity("one")); - DummyEntity two = repository.save(createDummyEntity("two")); - DummyEntity three = repository.save(createDummyEntity("three")); + DummyEntity one = repository.save(createEntity("one")); + DummyEntity two = repository.save(createEntity("two")); + DummyEntity three = repository.save(createEntity("three")); List tuples = List.of(new Object[] { two.idProp, "two" }, // matches "two" new Object[] { three.idProp, "two" } // matches nothing @@ -1349,22 +1348,12 @@ void queryWithTupleIn() { @Test // GH-1900 void queryByListOfByteArray() { - byte[] oneBytes = { 1, 2, 3, 4, 5, 6, 7, 8 }; - DummyEntity one = createDummyEntity("one"); - one.setBytes(oneBytes); - one = repository.save(one); - - byte[] twoBytes = { 8, 7, 6, 5, 4, 3, 2, 1 }; - DummyEntity two = createDummyEntity("two"); - two.setBytes(twoBytes); - two = repository.save(two); + DummyEntity one = repository.save(createEntity("one", it -> it.setBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }))); + DummyEntity two = repository.save(createEntity("two", it -> it.setBytes(new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }))); + DummyEntity three = repository + .save(createEntity("three", it -> it.setBytes(new byte[] { 3, 3, 3, 3, 3, 3, 3, 3 }))); - byte[] threeBytes = { 3, 3, 3, 3, 3, 3, 3, 3 }; - DummyEntity three = createDummyEntity("three"); - three.setBytes(threeBytes); - three = repository.save(three); - - List result = repository.findByBytesIn(List.of(threeBytes, oneBytes)); + List result = repository.findByBytesIn(List.of(three.getBytes(), one.getBytes())); assertThat(result).extracting("idProp").containsExactlyInAnyOrder(one.idProp, three.idProp); } @@ -1372,22 +1361,12 @@ void queryByListOfByteArray() { @Test // GH-1900 void queryByByteArray() { - byte[] oneBytes = { 1, 2, 3, 4, 5, 6, 7, 8 }; - DummyEntity one = createDummyEntity("one"); - one.setBytes(oneBytes); - one = repository.save(one); - - byte[] twoBytes = { 8, 7, 6, 5, 4, 3, 2, 1 }; - DummyEntity two = createDummyEntity("two"); - two.setBytes(twoBytes); - two = repository.save(two); - - byte[] threeBytes = { 3, 3, 3, 3, 3, 3, 3, 3 }; - DummyEntity three = createDummyEntity("three"); - three.setBytes(threeBytes); - three = repository.save(three); + DummyEntity one = repository.save(createEntity("one", it -> it.setBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }))); + DummyEntity two = repository.save(createEntity("two", it -> it.setBytes(new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 }))); + DummyEntity three = repository + .save(createEntity("three", it -> it.setBytes(new byte[] { 3, 3, 3, 3, 3, 3, 3, 3 }))); - List result = repository.findByBytes(twoBytes); + List result = repository.findByBytes(two.getBytes()); assertThat(result).extracting("idProp").containsExactly(two.idProp); } @@ -1419,7 +1398,7 @@ private Instant createDummyBeforeAndAfterNow() { Instant now = Instant.now(); - DummyEntity first = createDummyEntity(); + DummyEntity first = createEntity(); Instant earlier = now.minusSeconds(1000L); OffsetDateTime earlierPlus3 = earlier.atOffset(ZoneOffset.ofHours(3)); first.setPointInTime(earlier); @@ -1427,7 +1406,7 @@ private Instant createDummyBeforeAndAfterNow() { first.setName("first"); - DummyEntity second = createDummyEntity(); + DummyEntity second = createEntity(); Instant later = now.plusSeconds(1000L); OffsetDateTime laterPlus3 = later.atOffset(ZoneOffset.ofHours(3)); second.setPointInTime(later); @@ -1842,6 +1821,24 @@ public Object getRootObject() { } } + private static DummyEntity createEntity() { + return createEntity("Entity Name"); + } + + private static DummyEntity createEntity(String entityName) { + return createEntity(entityName, it -> {}); + } + + private static DummyEntity createEntity(String entityName, Consumer customizer) { + + DummyEntity entity = new DummyEntity(); + entity.setName(entityName); + + customizer.accept(entity); + + return entity; + } + static class DummyEntity { String name; @@ -1936,6 +1933,10 @@ public void setBytes(byte[] bytes) { this.bytes = bytes; } + public byte[] getBytes() { + return bytes; + } + @Override public String toString() { return "DummyEntity{" + "name='" + name + '\'' + ", idProp=" + idProp + '}';