[#7140] Add support for converting java.sql.Struct to UDTRecord

This commit is contained in:
lukaseder 2018-02-02 11:08:33 +01:00
parent 9def7171d3
commit 60aae83a42

View File

@ -55,6 +55,7 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.sql.Date;
import java.sql.Struct;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Instant;
@ -84,6 +85,7 @@ import org.jooq.EnumType;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.SQLDialect;
import org.jooq.UDTRecord;
import org.jooq.exception.DataTypeException;
import org.jooq.tools.jdbc.MockArray;
import org.jooq.types.UByte;
@ -996,6 +998,21 @@ public final class Convert {
return record.into(toClass);
}
else if (Struct.class.isAssignableFrom(fromClass)) {
Struct struct = (Struct) from;
if (UDTRecord.class.isAssignableFrom(toClass)) {
try {
UDTRecord<?> record = ((UDTRecord<?>) toClass.newInstance());
record.from(struct.getAttributes());
return (U) record;
}
catch (Exception e) {
throw new DataTypeException("Cannot convert from " + fromClass + " to " + toClass, e);
}
}
}