DATACMNS-921 - ResultProcessor now gracefully falls back to approximate collections if necessary.
When handling collection results, we now create an approximate collection in case the creation of the exact same collection fails.
This commit is contained in:
@@ -143,7 +143,7 @@ public class ResultProcessor {
|
||||
if (source instanceof Collection && method.isCollectionQuery()) {
|
||||
|
||||
Collection<?> collection = (Collection<?>) source;
|
||||
Collection<Object> target = CollectionFactory.createCollection(collection.getClass(), collection.size());
|
||||
Collection<Object> target = createCollectionFor(collection);
|
||||
|
||||
for (Object columns : collection) {
|
||||
target.add(type.isInstance(columns) ? columns : converter.convert(columns));
|
||||
@@ -159,6 +159,22 @@ public class ResultProcessor {
|
||||
return (T) converter.convert(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Collection} for the given source. Will try to create an instance of the source collection's
|
||||
* type first falling back to creating an approximate collection if the former fails.
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private static Collection<Object> createCollectionFor(Collection<?> source) {
|
||||
|
||||
try {
|
||||
return CollectionFactory.createCollection(source.getClass(), source.size());
|
||||
} catch (RuntimeException o_O) {
|
||||
return CollectionFactory.createApproximateCollection(source, source.size());
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor(staticName = "of")
|
||||
private static class ChainingConverter implements Converter<Object, Object> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user