|
|
|
@ -679,8 +679,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
* in between. |
|
|
|
* in between. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (value instanceof Document document) { |
|
|
|
if (value instanceof Document document) { |
|
|
|
if(property.isMap()) { |
|
|
|
if (property.isMap()) { |
|
|
|
if(document.isEmpty() || document.values().iterator().next() instanceof DBRef) { |
|
|
|
if (document.isEmpty() || peek(document.values()) instanceof DBRef) { |
|
|
|
accessor.setProperty(property, dbRefResolver.resolveDbRef(property, null, callback, handler)); |
|
|
|
accessor.setProperty(property, dbRefResolver.resolveDbRef(property, null, callback, handler)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
accessor.setProperty(property, readMap(context, document, property.getTypeInformation())); |
|
|
|
accessor.setProperty(property, readMap(context, document, property.getTypeInformation())); |
|
|
|
@ -688,8 +688,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
accessor.setProperty(property, read(property.getActualType(), document)); |
|
|
|
accessor.setProperty(property, read(property.getActualType(), document)); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (value instanceof Collection<?> collection && collection.size() > 0 |
|
|
|
} else if (value instanceof Collection<?> collection && !collection.isEmpty() |
|
|
|
&& collection.iterator().next() instanceof Document) { |
|
|
|
&& peek(collection) instanceof Document) { |
|
|
|
accessor.setProperty(property, readCollectionOrArray(context, collection, property.getTypeInformation())); |
|
|
|
accessor.setProperty(property, readCollectionOrArray(context, collection, property.getTypeInformation())); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
accessor.setProperty(property, dbRefResolver.resolveDbRef(property, null, callback, handler)); |
|
|
|
accessor.setProperty(property, dbRefResolver.resolveDbRef(property, null, callback, handler)); |
|
|
|
@ -722,8 +722,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DATAMONGO-913
|
|
|
|
// DATAMONGO-913
|
|
|
|
if (object instanceof LazyLoadingProxy) { |
|
|
|
if (object instanceof LazyLoadingProxy proxy) { |
|
|
|
return ((LazyLoadingProxy) object).toDBRef(); |
|
|
|
return proxy.toDBRef(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return createDBRef(object, referringProperty); |
|
|
|
return createDBRef(object, referringProperty); |
|
|
|
@ -1022,11 +1022,13 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
.getPointer(); |
|
|
|
.getPointer(); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
return writeCollectionInternal(targetCollection, TypeInformation.of(DocumentPointer.class), new ArrayList<>(targetCollection.size())); |
|
|
|
return writeCollectionInternal(targetCollection, TypeInformation.of(DocumentPointer.class), |
|
|
|
|
|
|
|
new ArrayList<>(targetCollection.size())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (property.hasExplicitWriteTarget()) { |
|
|
|
if (property.hasExplicitWriteTarget()) { |
|
|
|
return writeCollectionInternal(collection, new FieldTypeInformation<>(property), new ArrayList<>(collection.size())); |
|
|
|
return writeCollectionInternal(collection, new FieldTypeInformation<>(property), |
|
|
|
|
|
|
|
new ArrayList<>(collection.size())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return writeCollectionInternal(collection, property.getTypeInformation(), new ArrayList<>(collection.size())); |
|
|
|
return writeCollectionInternal(collection, property.getTypeInformation(), new ArrayList<>(collection.size())); |
|
|
|
@ -1674,7 +1676,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Object> result = bulkReadAndConvertDBRefs(context, Collections.singletonList(dbref), type); |
|
|
|
List<Object> result = bulkReadAndConvertDBRefs(context, Collections.singletonList(dbref), type); |
|
|
|
return CollectionUtils.isEmpty(result) ? null : result.iterator().next(); |
|
|
|
return CollectionUtils.isEmpty(result) ? null : peek(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
|
|
@ -1699,10 +1701,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
return Collections.emptyList(); |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Document> referencedRawDocuments = dbrefs.size() == 1 |
|
|
|
List<Document> referencedRawDocuments = dbrefs.size() == 1 ? Collections.singletonList(readRef(peek(dbrefs))) |
|
|
|
? Collections.singletonList(readRef(dbrefs.iterator().next())) |
|
|
|
|
|
|
|
: bulkReadRefs(dbrefs); |
|
|
|
: bulkReadRefs(dbrefs); |
|
|
|
String collectionName = dbrefs.iterator().next().getCollectionName(); |
|
|
|
String collectionName = peek(dbrefs).getCollectionName(); |
|
|
|
|
|
|
|
|
|
|
|
List<T> targetList = new ArrayList<>(dbrefs.size()); |
|
|
|
List<T> targetList = new ArrayList<>(dbrefs.size()); |
|
|
|
|
|
|
|
|
|
|
|
@ -1847,6 +1848,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> T peek(Iterable<T> result) { |
|
|
|
|
|
|
|
return result.iterator().next(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Predicate<MongoPersistentProperty> isIdentifier(PersistentEntity<?, ?> entity) { |
|
|
|
static Predicate<MongoPersistentProperty> isIdentifier(PersistentEntity<?, ?> entity) { |
|
|
|
return entity::isIdProperty; |
|
|
|
return entity::isIdProperty; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1925,7 +1930,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App |
|
|
|
|
|
|
|
|
|
|
|
public MongoDbPropertyValueProvider withContext(ConversionContext context) { |
|
|
|
public MongoDbPropertyValueProvider withContext(ConversionContext context) { |
|
|
|
|
|
|
|
|
|
|
|
return context == this.context ? this : new MongoDbPropertyValueProvider(context, accessor, evaluator); |
|
|
|
return context == this.context ? this |
|
|
|
|
|
|
|
: new MongoDbPropertyValueProvider(context, accessor, evaluator); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|