#186 - Consider byte[] binary data when mapping entities.

We now exclude byte[] properties from being mapped to array types. To map data to a 1-dimensional BYTE[] Postgres type, properties can be declared as Collection<Byte> or Byte[].
This commit is contained in:
Mark Paluch
2019-09-13 14:34:00 +02:00
parent 5ef8285288
commit 1096838dec
12 changed files with 113 additions and 15 deletions

View File

@@ -219,6 +219,36 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
assertThat(jdbc.queryForMap("SELECT id, name, manual FROM legoset")).hasEntrySatisfying("id", numberOf(42055));
}
@Test // gh-2
public void insertTypedObjectWithBinary() {
LegoSet legoSet = new LegoSet();
legoSet.setId(42055);
legoSet.setName("SCHAUFELRADBAGGER");
legoSet.setManual(12);
legoSet.setCert(new byte[] { 1, 2, 3, 4, 5 });
DatabaseClient databaseClient = DatabaseClient.create(connectionFactory);
databaseClient.insert().into(LegoSet.class)//
.using(legoSet) //
.fetch() //
.rowsUpdated() //
.as(StepVerifier::create) //
.expectNext(1) //
.verifyComplete();
databaseClient.select().from(LegoSet.class) //
.matching(where("name").is("SCHAUFELRADBAGGER")) //
.fetch() //
.first() //
.as(StepVerifier::create) //
.assertNext(actual -> {
assertThat(actual.getCert()).isEqualTo(new byte[] { 1, 2, 3, 4, 5 });
}).verifyComplete();
}
@Test // gh-64
public void update() {
@@ -491,5 +521,6 @@ public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegr
@Id int id;
String name;
Integer manual;
byte[] cert;
}
}

View File

@@ -24,6 +24,7 @@ import reactor.test.StepVerifier;
import javax.sql.DataSource;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.dao.DataAccessException;
@@ -83,6 +84,11 @@ public class MySqlDatabaseClientIntegrationTests extends AbstractDatabaseClientI
.verifyComplete();
}
@Ignore("https://github.com/mirromutth/r2dbc-mysql/issues/62")
@Test
@Override
public void insertTypedObjectWithBinary() {}
@Table("boolean_mapping")
@Data
static class BooleanMapping {

View File

@@ -171,6 +171,11 @@ public abstract class ReactiveDataAccessStrategyTestSupport {
testType(PrimitiveTypes::setUuid, PrimitiveTypes::getUuid, UUID.randomUUID(), "uuid");
}
@Test // gh-186
public void shouldReadAndWriteBinary() {
testType(PrimitiveTypes::setBinary, PrimitiveTypes::getBinary, "hello".getBytes(), "binary");
}
private <T> void testType(BiConsumer<PrimitiveTypes, T> setter, Function<PrimitiveTypes, T> getter, T testValue,
String fieldname) {
@@ -224,6 +229,8 @@ public abstract class ReactiveDataAccessStrategyTestSupport {
OffsetDateTime offsetDateTime;
ZonedDateTime zonedDateTime;
byte[] binary;
UUID uuid;
}
}

View File

@@ -33,7 +33,8 @@ public class H2TestSupport {
public static String CREATE_TABLE_LEGOSET = "CREATE TABLE legoset (\n" //
+ " id integer CONSTRAINT id PRIMARY KEY,\n" //
+ " name varchar(255) NOT NULL,\n" //
+ " manual integer NULL\n" //
+ " manual integer NULL\n," //
+ " cert bytea NULL\n" //
+ ");";
public static String CREATE_TABLE_LEGOSET_WITH_ID_GENERATION = "CREATE TABLE legoset (\n" //

View File

@@ -43,7 +43,8 @@ public class MySqlTestSupport {
public static String CREATE_TABLE_LEGOSET = "CREATE TABLE legoset (\n" //
+ " id integer PRIMARY KEY,\n" //
+ " name varchar(255) NOT NULL,\n" //
+ " manual integer NULL\n" //
+ " manual integer NULL\n," //
+ " cert varbinary(255) NULL\n" //
+ ") ENGINE=InnoDB;";
public static String CREATE_TABLE_LEGOSET_WITH_ID_GENERATION = "CREATE TABLE legoset (\n" //

View File

@@ -26,7 +26,8 @@ public class PostgresTestSupport {
public static String CREATE_TABLE_LEGOSET = "CREATE TABLE legoset (\n" //
+ " id integer CONSTRAINT id PRIMARY KEY,\n" //
+ " name varchar(255) NOT NULL,\n" //
+ " manual integer NULL\n" //
+ " manual integer NULL\n," //
+ " cert bytea NULL\n" //
+ ");";
public static String CREATE_TABLE_LEGOSET_WITH_ID_GENERATION = "CREATE TABLE legoset (\n" //

View File

@@ -18,7 +18,8 @@ public class SqlServerTestSupport {
public static String CREATE_TABLE_LEGOSET = "CREATE TABLE legoset (\n" //
+ " id integer PRIMARY KEY,\n" //
+ " name varchar(255) NOT NULL,\n" //
+ " manual integer NULL\n" //
+ " manual integer NULL\n," //
+ " cert varbinary(255) NULL\n" //
+ ");";
public static String CREATE_TABLE_LEGOSET_WITH_ID_GENERATION = "CREATE TABLE legoset (\n" //