Skip to content

Do not convert binary data in List<byte[]> to array SQL type #1903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOperations operations,
@Nullable RowMapper<?> defaultRowMapper, JdbcConverter converter,
QueryMethodEvaluationContextProvider evaluationContextProvider) {
this(queryMethod.getRequiredQuery(), queryMethod, operations, result -> (RowMapper<Object>) defaultRowMapper, converter, evaluationContextProvider);
this(queryMethod.getRequiredQuery(), queryMethod, operations, result -> (RowMapper<Object>) defaultRowMapper,
converter, evaluationContextProvider);
}

/**
Expand Down Expand Up @@ -244,7 +245,7 @@ private JdbcValue writeValue(@Nullable Object value, TypeInformation<?> typeInfo
TypeInformation<?> actualType = typeInformation.getActualType();

// tuple-binding
if (actualType != null && actualType.getType().isArray()) {
if (actualType != null && actualType.getType().isArray() && !actualType.getType().equals(byte[].class)) {

TypeInformation<?> nestedElementType = actualType.getRequiredActualType();
return writeCollection(collection, parameter.getActualSqlType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
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;
Expand All @@ -51,23 +50,13 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.annotation.Id;
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.domain.*;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.testing.ConditionalOnDatabase;
import org.springframework.data.jdbc.testing.DatabaseType;
import org.springframework.data.jdbc.testing.EnabledOnDatabase;
import org.springframework.data.jdbc.testing.EnabledOnFeature;
import org.springframework.data.jdbc.testing.IntegrationTest;
import org.springframework.data.jdbc.testing.TestConfiguration;
Expand Down Expand Up @@ -1357,6 +1346,52 @@ void queryWithTupleIn() {
assertThat(result).containsOnly(two);
}

@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);

byte[] threeBytes = { 3, 3, 3, 3, 3, 3, 3, 3 };
DummyEntity three = createDummyEntity("three");
three.setBytes(threeBytes);
three = repository.save(three);

List<DummyEntity> result = repository.findByBytesIn(List.of(threeBytes, oneBytes));

assertThat(result).extracting("idProp").containsExactlyInAnyOrder(one.idProp, three.idProp);
}

@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);

List<DummyEntity> result = repository.findByBytes(twoBytes);

assertThat(result).extracting("idProp").containsExactly(two.idProp);
}

private Root createRoot(String namePrefix) {

return new Root(null, namePrefix,
Expand Down Expand Up @@ -1487,6 +1522,12 @@ interface DummyEntityRepository extends CrudRepository<DummyEntity, Long>, Query

@Query("SELECT * FROM DUMMY_ENTITY WHERE (ID_PROP, NAME) IN (:tuples)")
List<DummyEntity> findByListInTuple(List<Object[]> tuples);

@Query("SELECT * FROM DUMMY_ENTITY WHERE BYTES IN (:bytes)")
List<DummyEntity> findByBytesIn(List<byte[]> bytes);

@Query("SELECT * FROM DUMMY_ENTITY WHERE BYTES = :bytes")
List<DummyEntity> findByBytes(byte[] bytes);
}

interface RootRepository extends ListCrudRepository<Root, Long> {
Expand Down Expand Up @@ -1810,6 +1851,7 @@ static class DummyEntity {
boolean flag;
AggregateReference<DummyEntity, Long> ref;
Direction direction;
byte[] bytes = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };

public DummyEntity(String name) {
this.name = name;
Expand Down Expand Up @@ -1890,6 +1932,10 @@ public int hashCode() {
return Objects.hash(name, pointInTime, offsetDateTime, idProp, flag, ref, direction);
}

public void setBytes(byte[] bytes) {
this.bytes = bytes;
}

@Override
public String toString() {
return "DummyEntity{" + "name='" + name + '\'' + ", idProp=" + idProp + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ CREATE TABLE dummy_entity
OFFSET_DATE_TIME TIMESTAMP, -- with time zone is only supported with z/OS
FLAG BOOLEAN,
REF BIGINT,
DIRECTION VARCHAR(100)
DIRECTION VARCHAR(100),
BYTES BINARY(8)
);

CREATE TABLE ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ CREATE TABLE dummy_entity
OFFSET_DATE_TIME TIMESTAMP WITH TIME ZONE,
FLAG BOOLEAN,
REF BIGINT,
DIRECTION VARCHAR(100)
DIRECTION VARCHAR(100),
BYTES BINARY(8)
);

CREATE TABLE ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ CREATE TABLE dummy_entity
OFFSET_DATE_TIME TIMESTAMP WITH TIME ZONE,
FLAG BOOLEAN,
REF BIGINT,
DIRECTION VARCHAR(100)
DIRECTION VARCHAR(100),
BYTES BINARY(8)
);

CREATE TABLE ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ CREATE TABLE dummy_entity
OFFSET_DATE_TIME TIMESTAMP(3),
FLAG BOOLEAN,
REF BIGINT,
DIRECTION VARCHAR(100)
DIRECTION VARCHAR(100),
BYTES BINARY(8)
);

CREATE TABLE ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ CREATE TABLE dummy_entity
OFFSET_DATE_TIME DATETIMEOFFSET,
FLAG BIT,
REF BIGINT,
DIRECTION VARCHAR(100)
DIRECTION VARCHAR(100),
BYTES VARBINARY(8)
);

CREATE TABLE ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ CREATE TABLE DUMMY_ENTITY
OFFSET_DATE_TIME TIMESTAMP(3) DEFAULT NULL,
FLAG BIT(1),
REF BIGINT,
DIRECTION VARCHAR(100)
DIRECTION VARCHAR(100),
BYTES BINARY(8)
);

CREATE TABLE ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ CREATE TABLE DUMMY_ENTITY
OFFSET_DATE_TIME TIMESTAMP WITH TIME ZONE,
FLAG NUMBER(1,0),
REF NUMBER,
DIRECTION VARCHAR2(100)
DIRECTION VARCHAR2(100),
BYTES RAW(8)
);

CREATE TABLE ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ CREATE TABLE dummy_entity
OFFSET_DATE_TIME TIMESTAMP WITH TIME ZONE,
FLAG BOOLEAN,
REF BIGINT,
DIRECTION VARCHAR(100)
DIRECTION VARCHAR(100),
BYTES BYTEA
);

CREATE TABLE ROOT
Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-1900-byte-array-to-uuid-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Loading