return (Record) val;
}
else if (sourceType instanceof CompositeType) {
CompositeType compType = (CompositeType) sourceType;
Object[] attributeVals;
if (val instanceof Struct) {
Struct struct = (Struct) val;
attributeVals = struct.getAttributes();
}
else if (SQLData.class.isInstance(val)) {
PGSQLOutputImpl out = new PGSQLOutputImpl(connection, compType);
((SQLData) val).writeSQL(out);
attributeVals = out.getAttributeValues();
}
else {
throw createCoercionException(val.getClass(), Record.class);
}
if (compType.getAttributes().size() != attributeVals.length) {
throw createCoercionException(val.getClass(), Record.class);
}
for (int c = 0; c < attributeVals.length; ++c) {
Type attrType = compType.getAttribute(c + 1).type;
Class<?> attrTargetType = mapSetType(format, attrType);
attributeVals[c] = coerce(format, attributeVals[c], attrType, attrTargetType, typeMap, zone, connection);
}