|
41 | 41 | import org.junit.jupiter.params.ParameterizedTest;
|
42 | 42 | import org.junit.jupiter.params.provider.Arguments;
|
43 | 43 | import org.junit.jupiter.params.provider.MethodSource;
|
44 |
| - |
45 | 44 | import org.springframework.beans.factory.annotation.Autowired;
|
46 | 45 | import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
47 | 46 | import org.springframework.context.ApplicationListener;
|
|
51 | 50 | import org.springframework.core.io.ClassPathResource;
|
52 | 51 | import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
53 | 52 | import org.springframework.data.annotation.Id;
|
54 |
| -import org.springframework.data.domain.Example; |
55 |
| -import org.springframework.data.domain.ExampleMatcher; |
56 |
| -import org.springframework.data.domain.Limit; |
57 |
| -import org.springframework.data.domain.Page; |
58 |
| -import org.springframework.data.domain.PageRequest; |
59 |
| -import org.springframework.data.domain.Pageable; |
60 |
| -import org.springframework.data.domain.ScrollPosition; |
61 |
| -import org.springframework.data.domain.Slice; |
62 |
| -import org.springframework.data.domain.Sort; |
63 |
| -import org.springframework.data.domain.Window; |
| 53 | +import org.springframework.data.domain.*; |
64 | 54 | import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
65 | 55 | import org.springframework.data.jdbc.repository.query.Modifying;
|
66 | 56 | import org.springframework.data.jdbc.repository.query.Query;
|
67 | 57 | import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
68 | 58 | import org.springframework.data.jdbc.testing.ConditionalOnDatabase;
|
69 | 59 | import org.springframework.data.jdbc.testing.DatabaseType;
|
70 |
| -import org.springframework.data.jdbc.testing.EnabledOnDatabase; |
71 | 60 | import org.springframework.data.jdbc.testing.EnabledOnFeature;
|
72 | 61 | import org.springframework.data.jdbc.testing.IntegrationTest;
|
73 | 62 | import org.springframework.data.jdbc.testing.TestConfiguration;
|
@@ -1357,6 +1346,52 @@ void queryWithTupleIn() {
|
1357 | 1346 | assertThat(result).containsOnly(two);
|
1358 | 1347 | }
|
1359 | 1348 |
|
| 1349 | + @Test // GH-1900 |
| 1350 | + void queryByListOfByteArray() { |
| 1351 | + |
| 1352 | + byte[] oneBytes = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 1353 | + DummyEntity one = createDummyEntity("one"); |
| 1354 | + one.setBytes(oneBytes); |
| 1355 | + one = repository.save(one); |
| 1356 | + |
| 1357 | + byte[] twoBytes = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 1358 | + DummyEntity two = createDummyEntity("two"); |
| 1359 | + two.setBytes(twoBytes); |
| 1360 | + two = repository.save(two); |
| 1361 | + |
| 1362 | + byte[] threeBytes = { 3, 3, 3, 3, 3, 3, 3, 3 }; |
| 1363 | + DummyEntity three = createDummyEntity("three"); |
| 1364 | + three.setBytes(threeBytes); |
| 1365 | + three = repository.save(three); |
| 1366 | + |
| 1367 | + List<DummyEntity> result = repository.findByBytesIn(List.of(threeBytes, oneBytes)); |
| 1368 | + |
| 1369 | + assertThat(result).extracting("idProp").containsExactlyInAnyOrder(one.idProp, three.idProp); |
| 1370 | + } |
| 1371 | + |
| 1372 | + @Test // GH-1900 |
| 1373 | + void queryByByteArray() { |
| 1374 | + |
| 1375 | + byte[] oneBytes = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
| 1376 | + DummyEntity one = createDummyEntity("one"); |
| 1377 | + one.setBytes(oneBytes); |
| 1378 | + one = repository.save(one); |
| 1379 | + |
| 1380 | + byte[] twoBytes = { 8, 7, 6, 5, 4, 3, 2, 1 }; |
| 1381 | + DummyEntity two = createDummyEntity("two"); |
| 1382 | + two.setBytes(twoBytes); |
| 1383 | + two = repository.save(two); |
| 1384 | + |
| 1385 | + byte[] threeBytes = { 3, 3, 3, 3, 3, 3, 3, 3 }; |
| 1386 | + DummyEntity three = createDummyEntity("three"); |
| 1387 | + three.setBytes(threeBytes); |
| 1388 | + three = repository.save(three); |
| 1389 | + |
| 1390 | + List<DummyEntity> result = repository.findByBytes(twoBytes); |
| 1391 | + |
| 1392 | + assertThat(result).extracting("idProp").containsExactly(two.idProp); |
| 1393 | + } |
| 1394 | + |
1360 | 1395 | private Root createRoot(String namePrefix) {
|
1361 | 1396 |
|
1362 | 1397 | return new Root(null, namePrefix,
|
@@ -1487,6 +1522,12 @@ interface DummyEntityRepository extends CrudRepository<DummyEntity, Long>, Query
|
1487 | 1522 |
|
1488 | 1523 | @Query("SELECT * FROM DUMMY_ENTITY WHERE (ID_PROP, NAME) IN (:tuples)")
|
1489 | 1524 | List<DummyEntity> findByListInTuple(List<Object[]> tuples);
|
| 1525 | + |
| 1526 | + @Query("SELECT * FROM DUMMY_ENTITY WHERE BYTES IN (:bytes)") |
| 1527 | + List<DummyEntity> findByBytesIn(List<byte[]> bytes); |
| 1528 | + |
| 1529 | + @Query("SELECT * FROM DUMMY_ENTITY WHERE BYTES = :bytes") |
| 1530 | + List<DummyEntity> findByBytes(byte[] bytes); |
1490 | 1531 | }
|
1491 | 1532 |
|
1492 | 1533 | interface RootRepository extends ListCrudRepository<Root, Long> {
|
@@ -1810,6 +1851,7 @@ static class DummyEntity {
|
1810 | 1851 | boolean flag;
|
1811 | 1852 | AggregateReference<DummyEntity, Long> ref;
|
1812 | 1853 | Direction direction;
|
| 1854 | + byte[] bytes = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; |
1813 | 1855 |
|
1814 | 1856 | public DummyEntity(String name) {
|
1815 | 1857 | this.name = name;
|
@@ -1890,6 +1932,10 @@ public int hashCode() {
|
1890 | 1932 | return Objects.hash(name, pointInTime, offsetDateTime, idProp, flag, ref, direction);
|
1891 | 1933 | }
|
1892 | 1934 |
|
| 1935 | + public void setBytes(byte[] bytes) { |
| 1936 | + this.bytes = bytes; |
| 1937 | + } |
| 1938 | + |
1893 | 1939 | @Override
|
1894 | 1940 | public String toString() {
|
1895 | 1941 | return "DummyEntity{" + "name='" + name + '\'' + ", idProp=" + idProp + '}';
|
|
0 commit comments