[#2279] UUIDs aren't correctly deserialised from Postgres UDTs
This commit is contained in:
parent
935d74628b
commit
48628892e2
@ -36,6 +36,7 @@
|
||||
|
||||
package org.jooq.test;
|
||||
|
||||
import static org.jooq.impl.Factory.val;
|
||||
import static org.jooq.test.postgres.generatedclasses.Routines.fSearchBook;
|
||||
import static org.jooq.test.postgres.generatedclasses.Tables.T_639_NUMBERS_TABLE;
|
||||
import static org.jooq.test.postgres.generatedclasses.Tables.T_725_LOB_TEST;
|
||||
@ -69,6 +70,7 @@ import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Table;
|
||||
@ -107,6 +109,7 @@ import org.jooq.test.postgres.generatedclasses.tables.records.VLibraryRecord;
|
||||
import org.jooq.test.postgres.generatedclasses.tables.records.XUnusedRecord;
|
||||
import org.jooq.test.postgres.generatedclasses.udt.UAddressType;
|
||||
import org.jooq.test.postgres.generatedclasses.udt.UStreetType;
|
||||
import org.jooq.test.postgres.generatedclasses.udt.records.UUuidsRecord;
|
||||
import org.jooq.types.UByte;
|
||||
import org.jooq.types.UInteger;
|
||||
import org.jooq.types.ULong;
|
||||
@ -889,4 +892,23 @@ public class PostgresTest extends jOOQAbstractTest<
|
||||
assertEquals(geometry, r2.getPgGeometry());
|
||||
assertEquals(interval, r2.getPgInterval());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostgresUDTTypes() throws Exception {
|
||||
UUID uuid1 = UUID.randomUUID();
|
||||
UUID uuid2 = UUID.randomUUID();
|
||||
|
||||
UUID[] array = new UUID[] { uuid1, uuid2 };
|
||||
|
||||
UUuidsRecord uuids = new UUuidsRecord();
|
||||
uuids.setU1(uuid1);
|
||||
uuids.setU2(array);
|
||||
|
||||
Field<UUuidsRecord> val = val(uuids).as("val");
|
||||
Record1<UUuidsRecord> record = create().select(val).fetchOne();
|
||||
assertEquals(uuids, record.getValue(val));
|
||||
assertEquals(uuid1, record.getValue(val).getU1());
|
||||
assertEquals(uuid1, record.getValue(val).getU2()[0]);
|
||||
assertEquals(uuid2, record.getValue(val).getU2()[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,6 +78,7 @@ import java.util.UUID;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.InsertSetMoreStep;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
@ -1580,4 +1581,27 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
.execute());
|
||||
assertEquals(uuid2, create().fetchOne(TExoticTypes()).getValue(TExoticTypes_UUID()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUUIDArrayDataType() throws Exception {
|
||||
if (TArrays() == null) {
|
||||
log.info("SKIPPING", "Skipping UUID ARRAY data type tests");
|
||||
return;
|
||||
}
|
||||
|
||||
UUID uuid1 = UUID.randomUUID();
|
||||
UUID uuid2 = UUID.randomUUID();
|
||||
|
||||
UUID[] array = new UUID[] { uuid1, uuid2 };
|
||||
Field<UUID[]> val = val(array).as("array");
|
||||
|
||||
Record1<UUID[]> record = create()
|
||||
.select(val)
|
||||
.fetchOne();
|
||||
|
||||
assertEquals(UUID[].class, record.getValue(val).getClass());
|
||||
assertEquals(2, record.getValue(val).length);
|
||||
assertEquals(uuid1, record.getValue(val)[0]);
|
||||
assertEquals(uuid2, record.getValue(val)[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2002,6 +2002,11 @@ public abstract class jOOQAbstractTest<
|
||||
new DataTypeTests(this).testUUIDDataType();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUUIDArrayDataType() throws Exception {
|
||||
new DataTypeTests(this).testUUIDArrayDataType();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTableWithHint() throws Exception {
|
||||
new ExoticTests(this).testTableWithHint();
|
||||
|
||||
@ -69,6 +69,13 @@ DROP TYPE IF EXISTS u_street_type/
|
||||
DROP TYPE IF EXISTS u_book_status/
|
||||
DROP TYPE IF EXISTS u_country/
|
||||
DROP TYPE IF EXISTS u_959/
|
||||
DROP TYPE IF EXISTS u_uuids/
|
||||
|
||||
CREATE TYPE u_uuids AS (
|
||||
u1 uuid,
|
||||
u2 uuid[]
|
||||
)
|
||||
/
|
||||
|
||||
CREATE TYPE u_959 AS ENUM('abstract', 'assert', 'boolean', 'break', 'byte', 'case', 'catch',
|
||||
'char', 'class', 'const', 'continue', 'default', 'double', 'do',
|
||||
|
||||
@ -2254,7 +2254,7 @@ final class Utils {
|
||||
else if (type == ULong.class) {
|
||||
return (T) ULong.valueOf(string);
|
||||
}
|
||||
else if(type == UUID.class) {
|
||||
else if (type == UUID.class) {
|
||||
return (T) UUID.fromString(string);
|
||||
}
|
||||
else if (type.isArray()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user