DATAMONGO-1609 - Fix compile errors.
Still way to go: - Failures: 113, Errors: 836, Skipped: 16
This commit is contained in:
committed by
Oliver Gierke
parent
826d00afa7
commit
90bb6262f9
@@ -120,7 +120,7 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
private MongoPersistentEntity<?> lookupPersistentEntity(Class<?> entityType, String collection) {
|
||||
|
||||
if (entityType != null) {
|
||||
return mapper.getMappingContext().getPersistentEntity(entityType);
|
||||
return mapper.getMappingContext().getRequiredPersistentEntity(entityType);
|
||||
}
|
||||
|
||||
Collection<? extends MongoPersistentEntity<?>> entities = mapper.getMappingContext().getPersistentEntities();
|
||||
|
||||
@@ -684,7 +684,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
List<GeoResult<T>> result = new ArrayList<GeoResult<T>>(results.size());
|
||||
|
||||
int index = 0;
|
||||
int elementsToSkip = near.getSkip() != null ? near.getSkip() : 0;
|
||||
long elementsToSkip = near.getSkip() != null ? near.getSkip() : 0;
|
||||
|
||||
for (Object element : results) {
|
||||
|
||||
@@ -2521,7 +2521,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
|
||||
|
||||
try {
|
||||
if (query.getSkip() > 0) {
|
||||
cursorToUse = cursorToUse.skip(query.getSkip());
|
||||
cursorToUse = cursorToUse.skip((int)query.getSkip());
|
||||
}
|
||||
if (query.getLimit() > 0) {
|
||||
cursorToUse = cursorToUse.limit(query.getLimit());
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -610,8 +611,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
*/
|
||||
public <T> Mono<T> findById(Object id, Class<T> entityClass, String collectionName) {
|
||||
|
||||
MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityClass);
|
||||
MongoPersistentProperty idProperty = persistentEntity == null ? null : persistentEntity.getIdProperty();
|
||||
Optional<? extends MongoPersistentEntity<?>> persistentEntity = mappingContext.getPersistentEntity(entityClass);
|
||||
MongoPersistentProperty idProperty = persistentEntity.isPresent() ? persistentEntity.get().getIdProperty().orElse(null) : null;
|
||||
|
||||
String idKey = idProperty == null ? ID_FIELD : idProperty.getName();
|
||||
|
||||
@@ -859,11 +860,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
final Map<String, List<T>> elementsByCollection = new HashMap<String, List<T>>();
|
||||
|
||||
listToSave.forEach(element -> {
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(element.getClass());
|
||||
|
||||
if (entity == null) {
|
||||
throw new InvalidDataAccessApiUsageException("No PersistentEntity information found for " + element.getClass());
|
||||
}
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(element.getClass());
|
||||
|
||||
String collection = entity.getCollection();
|
||||
List<T> collectionElements = elementsByCollection.get(collection);
|
||||
@@ -965,14 +962,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
ConvertingPropertyAccessor convertingAccessor = new ConvertingPropertyAccessor(
|
||||
entity.getPropertyAccessor(objectToSave), mongoConverter.getConversionService());
|
||||
|
||||
MongoPersistentProperty idProperty = entity.getIdProperty();
|
||||
MongoPersistentProperty versionProperty = entity.getVersionProperty();
|
||||
MongoPersistentProperty idProperty = entity.getIdProperty().orElseThrow(() -> new IllegalArgumentException("No id property present!"));
|
||||
MongoPersistentProperty versionProperty = entity.getVersionProperty().orElseThrow(() -> new IllegalArgumentException("No version property present!"));;
|
||||
|
||||
Object version = convertingAccessor.getProperty(versionProperty);
|
||||
Number versionNumber = convertingAccessor.getProperty(versionProperty, Number.class);
|
||||
Optional<Object> version = convertingAccessor.getProperty(versionProperty);
|
||||
Optional<Number> versionNumber = convertingAccessor.getProperty(versionProperty, Number.class);
|
||||
|
||||
// Fresh instance -> initialize version property
|
||||
if (version == null) {
|
||||
if (!version.isPresent()) {
|
||||
return doInsert(collectionName, objectToSave, mongoConverter);
|
||||
}
|
||||
|
||||
@@ -983,7 +980,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
Query query = new Query(Criteria.where(idProperty.getName()).is(id).and(versionProperty.getName()).is(version));
|
||||
|
||||
// Bump version number
|
||||
convertingAccessor.setProperty(versionProperty, versionNumber.longValue() + 1);
|
||||
convertingAccessor.setProperty(versionProperty, Optional.of(versionNumber.orElse(0).longValue() + 1));
|
||||
|
||||
ReactiveMongoTemplate.this.maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
|
||||
@@ -1229,7 +1226,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
private void increaseVersionForUpdateIfNecessary(MongoPersistentEntity<?> persistentEntity, Update update) {
|
||||
|
||||
if (persistentEntity != null && persistentEntity.hasVersionProperty()) {
|
||||
String versionFieldName = persistentEntity.getVersionProperty().getFieldName();
|
||||
String versionFieldName = persistentEntity.getVersionProperty().get().getFieldName();
|
||||
if (!update.modifies(versionFieldName)) {
|
||||
update.inc(versionFieldName, 1L);
|
||||
}
|
||||
@@ -1242,7 +1239,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return false;
|
||||
}
|
||||
|
||||
return document.containsKey(persistentEntity.getVersionProperty().getFieldName());
|
||||
return document.containsKey(persistentEntity.getVersionProperty().get().getFieldName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -1304,14 +1301,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return Collections.singletonMap(ID_FIELD, ((Document) object).get(ID_FIELD)).entrySet().iterator().next();
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(objectType);
|
||||
MongoPersistentProperty idProp = entity == null ? null : entity.getIdProperty();
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = mappingContext.getPersistentEntity(objectType);
|
||||
MongoPersistentProperty idProp = entity.isPresent() ? entity.get().getIdProperty().orElse(null) : null;
|
||||
|
||||
if (idProp == null) {
|
||||
throw new MappingException("No id property found for object of type " + objectType);
|
||||
}
|
||||
|
||||
Object idValue = entity.getPropertyAccessor(object).getProperty(idProp);
|
||||
Object idValue = entity.get().getPropertyAccessor(object).getProperty(idProp);
|
||||
return Collections.singletonMap(idProp.getFieldName(), idValue).entrySet().iterator().next();
|
||||
}
|
||||
|
||||
@@ -1352,18 +1349,18 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
private void assertUpdateableIdIfNotSet(Object entity) {
|
||||
|
||||
MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entity.getClass());
|
||||
MongoPersistentProperty idProperty = persistentEntity == null ? null : persistentEntity.getIdProperty();
|
||||
Optional<? extends MongoPersistentEntity<?>> persistentEntity = mappingContext.getPersistentEntity(entity.getClass());
|
||||
Optional<MongoPersistentProperty> idProperty = persistentEntity.isPresent() ? persistentEntity.get().getIdProperty() : Optional.empty();
|
||||
|
||||
if (idProperty == null) {
|
||||
if (!idProperty.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object idValue = persistentEntity.getPropertyAccessor(entity).getProperty(idProperty);
|
||||
Optional<Object> idValue = persistentEntity.get().getPropertyAccessor(entity).getProperty(idProperty.get());
|
||||
|
||||
if (idValue == null && !MongoSimpleTypes.AUTOGENERATED_ID_TYPES.contains(idProperty.getType())) {
|
||||
if (!idValue.isPresent() && !MongoSimpleTypes.AUTOGENERATED_ID_TYPES.contains(idProperty.get().getType())) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
String.format("Cannot autogenerate id of type %s for entity of type %s!", idProperty.getType().getName(),
|
||||
String.format("Cannot autogenerate id of type %s for entity of type %s!", idProperty.get().getType().getName(),
|
||||
entity.getClass().getName()));
|
||||
}
|
||||
}
|
||||
@@ -1535,7 +1532,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
*/
|
||||
protected <T> Mono<T> doFindOne(String collectionName, Document query, Document fields, Class<T> entityClass) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
Document mappedFields = fields == null ? null : queryMapper.getMappedObject(fields, entity);
|
||||
|
||||
@@ -1585,7 +1582,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
protected <S, T> Flux<T> doFind(String collectionName, Document query, Document fields, Class<S> entityClass,
|
||||
FindPublisherPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
Document mappedFields = queryMapper.getMappedFields(fields, entity);
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
@@ -1638,7 +1635,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
serializeToJsonSafely(query), fields, sort, entityClass, collectionName));
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
return executeFindOneInternal(new FindAndRemoveCallback(queryMapper.getMappedObject(query, entity), fields, sort),
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
@@ -1654,11 +1651,11 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
optionsToUse = options;
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
return Mono.defer(() -> {
|
||||
|
||||
increaseVersionForUpdateIfNecessary(entity, update);
|
||||
increaseVersionForUpdateIfNecessary(entity.get(), update);
|
||||
|
||||
Document mappedQuery = queryMapper.getMappedObject(query, entity);
|
||||
Document mappedUpdate = updateMapper.getMappedObject(update.getUpdateObject(), entity);
|
||||
@@ -1706,14 +1703,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
ConversionService conversionService = mongoConverter.getConversionService();
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(savedObject.getClass());
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(savedObject.getClass());
|
||||
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(savedObject);
|
||||
|
||||
if (accessor.getProperty(idProp) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
new ConvertingPropertyAccessor(accessor, conversionService).setProperty(idProp, id);
|
||||
new ConvertingPropertyAccessor(accessor, conversionService).setProperty(idProp, Optional.ofNullable(id));
|
||||
}
|
||||
|
||||
private MongoCollection<Document> getAndPrepareCollection(MongoDatabase db, String collectionName) {
|
||||
@@ -1901,12 +1898,12 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
}
|
||||
|
||||
private MongoPersistentEntity<?> getPersistentEntity(Class<?> type) {
|
||||
return type == null ? null : mappingContext.getPersistentEntity(type);
|
||||
return type == null ? null : mappingContext.getPersistentEntity(type).orElse(null);
|
||||
}
|
||||
|
||||
private MongoPersistentProperty getIdPropertyFor(Class<?> type) {
|
||||
MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(type);
|
||||
return persistentEntity == null ? null : persistentEntity.getIdProperty();
|
||||
Optional<? extends MongoPersistentEntity<?>> persistentEntity = mappingContext.getPersistentEntity(type);
|
||||
return persistentEntity.isPresent() ? persistentEntity.get().getIdProperty().orElse(null) : null;
|
||||
}
|
||||
|
||||
private <T> String determineEntityCollectionName(T obj) {
|
||||
@@ -1925,13 +1922,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
"No class parameter provided, entity collection can't be determined!");
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
if (entity == null) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"No Persistent Entity information found for the class " + entityClass.getName());
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(entityClass);
|
||||
return entity.getCollection();
|
||||
}
|
||||
|
||||
@@ -1986,7 +1977,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
if (mongoPersistentEntity != null && mongoPersistentEntity.hasVersionProperty()) {
|
||||
ConvertingPropertyAccessor accessor = new ConvertingPropertyAccessor(
|
||||
mongoPersistentEntity.getPropertyAccessor(entity), mongoConverter.getConversionService());
|
||||
accessor.setProperty(mongoPersistentEntity.getVersionProperty(), 0);
|
||||
accessor.setProperty(mongoPersistentEntity.getVersionProperty().get(), Optional.of(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2290,7 +2281,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
try {
|
||||
if (query.getSkip() > 0) {
|
||||
findPublisherToUse = findPublisherToUse.skip(query.getSkip());
|
||||
findPublisherToUse = findPublisherToUse.skip((int)query.getSkip());
|
||||
}
|
||||
if (query.getLimit() > 0) {
|
||||
findPublisherToUse = findPublisherToUse.limit(query.getLimit());
|
||||
@@ -2346,9 +2337,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
static class NoOpDbRefResolver implements DbRefResolver {
|
||||
|
||||
@Override
|
||||
public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback,
|
||||
public Optional<Object> resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback,
|
||||
DbRefProxyHandler proxyHandler) {
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -77,7 +78,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
*/
|
||||
@Override
|
||||
public Iterable<? extends IndexDefinitionHolder> resolveIndexFor(TypeInformation<?> typeInformation) {
|
||||
return resolveIndexForEntity(mappingContext.getPersistentEntity(typeInformation));
|
||||
return resolveIndexForEntity(mappingContext.getRequiredPersistentEntity(typeInformation));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +93,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
public List<IndexDefinitionHolder> resolveIndexForEntity(final MongoPersistentEntity<?> root) {
|
||||
|
||||
Assert.notNull(root, "Index cannot be resolved for given 'null' entity.");
|
||||
Document document = root.findAnnotation(Document.class);
|
||||
Document document = root.findAnnotation(Document.class).orElseThrow(() -> new IllegalArgumentException("Given entity is not collection root."));
|
||||
Assert.notNull(document, "Given entity is not collection root.");
|
||||
|
||||
final List<IndexDefinitionHolder> indexInformation = new ArrayList<MongoPersistentEntityIndexResolver.IndexDefinitionHolder>();
|
||||
@@ -140,7 +141,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
private List<IndexDefinitionHolder> resolveIndexForClass(final TypeInformation<?> type, final String path,
|
||||
final String collection, final CycleGuard guard) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(type);
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type);
|
||||
|
||||
final List<IndexDefinitionHolder> indexInformation = new ArrayList<MongoPersistentEntityIndexResolver.IndexDefinitionHolder>();
|
||||
indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions(path, collection, entity));
|
||||
@@ -253,14 +254,14 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
indexDefinitionBuilder.withLanguageOverride(persistentProperty.getFieldName());
|
||||
}
|
||||
|
||||
TextIndexed indexed = persistentProperty.findAnnotation(TextIndexed.class);
|
||||
Optional<TextIndexed> indexed = persistentProperty.findAnnotation(TextIndexed.class);
|
||||
|
||||
if (includeOptions.isForce() || indexed != null || persistentProperty.isEntity()) {
|
||||
if (includeOptions.isForce() || indexed.isPresent()|| persistentProperty.isEntity()) {
|
||||
|
||||
String propertyDotPath = (StringUtils.hasText(dotPath) ? dotPath + "." : "")
|
||||
+ persistentProperty.getFieldName();
|
||||
|
||||
Float weight = indexed != null ? indexed.weight()
|
||||
Float weight = indexed != null ? indexed.get().weight()
|
||||
: (includeOptions.getParentFieldSpec() != null ? includeOptions.getParentFieldSpec().getWeight() : 1.0F);
|
||||
|
||||
if (persistentProperty.isEntity()) {
|
||||
@@ -273,7 +274,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
|
||||
try {
|
||||
appendTextIndexInformation(propertyDotPath, indexDefinitionBuilder,
|
||||
mappingContext.getPersistentEntity(persistentProperty.getActualType()), optionsForNestedType, guard);
|
||||
mappingContext.getRequiredPersistentEntity(persistentProperty.getActualType()), optionsForNestedType, guard);
|
||||
} catch (CyclicPropertyReferenceException e) {
|
||||
LOGGER.info(e.getMessage(), e);
|
||||
} catch (InvalidDataAccessApiUsageException e) {
|
||||
@@ -302,18 +303,18 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
MongoPersistentEntity<?> entity) {
|
||||
|
||||
List<IndexDefinitionHolder> indexDefinitions = new ArrayList<MongoPersistentEntityIndexResolver.IndexDefinitionHolder>();
|
||||
CompoundIndexes indexes = entity.findAnnotation(CompoundIndexes.class);
|
||||
Optional<CompoundIndexes> indexes = entity.findAnnotation(CompoundIndexes.class);
|
||||
|
||||
if (indexes != null) {
|
||||
for (CompoundIndex index : indexes.value()) {
|
||||
if (indexes.isPresent()) {
|
||||
for (CompoundIndex index : indexes.get().value()) {
|
||||
indexDefinitions.add(createCompoundIndexDefinition(dotPath, fallbackCollection, index, entity));
|
||||
}
|
||||
}
|
||||
|
||||
CompoundIndex index = entity.findAnnotation(CompoundIndex.class);
|
||||
Optional<CompoundIndex> index = entity.findAnnotation(CompoundIndex.class);
|
||||
|
||||
if (index != null) {
|
||||
indexDefinitions.add(createCompoundIndexDefinition(dotPath, fallbackCollection, index, entity));
|
||||
if (index.isPresent()) {
|
||||
indexDefinitions.add(createCompoundIndexDefinition(dotPath, fallbackCollection, index.get(), entity));
|
||||
}
|
||||
|
||||
return indexDefinitions;
|
||||
@@ -380,29 +381,33 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
protected IndexDefinitionHolder createIndexDefinition(String dotPath, String collection,
|
||||
MongoPersistentProperty persitentProperty) {
|
||||
|
||||
Indexed index = persitentProperty.findAnnotation(Indexed.class);
|
||||
Optional<Indexed> index = persitentProperty.findAnnotation(Indexed.class);
|
||||
|
||||
Index indexDefinition = new Index().on(dotPath,
|
||||
IndexDirection.ASCENDING.equals(index.direction()) ? Sort.Direction.ASC : Sort.Direction.DESC);
|
||||
|
||||
if (!index.useGeneratedName()) {
|
||||
indexDefinition.named(pathAwareIndexName(index.name(), dotPath, persitentProperty));
|
||||
if(!index.isPresent()){
|
||||
return null;
|
||||
}
|
||||
|
||||
if (index.unique()) {
|
||||
Index indexDefinition = new Index().on(dotPath,
|
||||
IndexDirection.ASCENDING.equals(index.get().direction()) ? Sort.Direction.ASC : Sort.Direction.DESC);
|
||||
|
||||
if (!index.get().useGeneratedName()) {
|
||||
indexDefinition.named(pathAwareIndexName(index.get().name(), dotPath, persitentProperty));
|
||||
}
|
||||
|
||||
if (index.get().unique()) {
|
||||
indexDefinition.unique();
|
||||
}
|
||||
|
||||
if (index.sparse()) {
|
||||
if (index.get().sparse()) {
|
||||
indexDefinition.sparse();
|
||||
}
|
||||
|
||||
if (index.background()) {
|
||||
if (index.get().background()) {
|
||||
indexDefinition.background();
|
||||
}
|
||||
|
||||
if (index.expireAfterSeconds() >= 0) {
|
||||
indexDefinition.expire(index.expireAfterSeconds(), TimeUnit.SECONDS);
|
||||
if (index.get().expireAfterSeconds() >= 0) {
|
||||
indexDefinition.expire(index.get().expireAfterSeconds(), TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);
|
||||
@@ -420,17 +425,21 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
protected IndexDefinitionHolder createGeoSpatialIndexDefinition(String dotPath, String collection,
|
||||
MongoPersistentProperty persistentProperty) {
|
||||
|
||||
GeoSpatialIndexed index = persistentProperty.findAnnotation(GeoSpatialIndexed.class);
|
||||
Optional<GeoSpatialIndexed> index = persistentProperty.findAnnotation(GeoSpatialIndexed.class);
|
||||
|
||||
GeospatialIndex indexDefinition = new GeospatialIndex(dotPath);
|
||||
indexDefinition.withBits(index.bits());
|
||||
indexDefinition.withMin(index.min()).withMax(index.max());
|
||||
|
||||
if (!index.useGeneratedName()) {
|
||||
indexDefinition.named(pathAwareIndexName(index.name(), dotPath, persistentProperty));
|
||||
if(!index.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
indexDefinition.typed(index.type()).withBucketSize(index.bucketSize()).withAdditionalField(index.additionalField());
|
||||
GeospatialIndex indexDefinition = new GeospatialIndex(dotPath);
|
||||
indexDefinition.withBits(index.get().bits());
|
||||
indexDefinition.withMin(index.get().min()).withMax(index.get().max());
|
||||
|
||||
if (!index.get().useGeneratedName()) {
|
||||
indexDefinition.named(pathAwareIndexName(index.get().name(), dotPath, persistentProperty));
|
||||
}
|
||||
|
||||
indexDefinition.typed(index.get().type()).withBucketSize(index.get().bucketSize()).withAdditionalField(index.get().additionalField());
|
||||
|
||||
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.mapping.event;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
@@ -52,7 +54,7 @@ public class AuditingEventListener implements ApplicationListener<BeforeConvertE
|
||||
public void onApplicationEvent(BeforeConvertEvent<Object> event) {
|
||||
|
||||
Object entity = event.getSource();
|
||||
auditingHandlerFactory.getObject().markAudited(entity);
|
||||
auditingHandlerFactory.getObject().markAudited(Optional.ofNullable(entity));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -41,8 +41,8 @@ public final class NearQuery {
|
||||
private Distance minDistance;
|
||||
private Metric metric;
|
||||
private boolean spherical;
|
||||
private Integer num;
|
||||
private Integer skip;
|
||||
private Long num;
|
||||
private Long skip;
|
||||
|
||||
/**
|
||||
* Creates a new {@link NearQuery}.
|
||||
@@ -125,7 +125,7 @@ public final class NearQuery {
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public NearQuery num(int num) {
|
||||
public NearQuery num(long num) {
|
||||
this.num = num;
|
||||
return this;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public final class NearQuery {
|
||||
* @param skip
|
||||
* @return
|
||||
*/
|
||||
public NearQuery skip(int skip) {
|
||||
public NearQuery skip(long skip) {
|
||||
this.skip = skip;
|
||||
return this;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ public final class NearQuery {
|
||||
this.skip = query.getSkip();
|
||||
|
||||
if (query.getLimit() != 0) {
|
||||
this.num = query.getLimit();
|
||||
this.num = (long) query.getLimit();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -388,7 +388,7 @@ public final class NearQuery {
|
||||
/**
|
||||
* @return the number of elements to skip.
|
||||
*/
|
||||
public Integer getSkip() {
|
||||
public Long getSkip() {
|
||||
return skip;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class Query {
|
||||
private final Map<String, CriteriaDefinition> criteria = new LinkedHashMap<String, CriteriaDefinition>();
|
||||
private Field fieldSpec;
|
||||
private Sort sort;
|
||||
private int skip;
|
||||
private long skip;
|
||||
private int limit;
|
||||
private String hint;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class Query {
|
||||
* @param skip
|
||||
* @return
|
||||
*/
|
||||
public Query skip(int skip) {
|
||||
public Query skip(long skip) {
|
||||
this.skip = skip;
|
||||
return this;
|
||||
}
|
||||
@@ -255,7 +255,7 @@ public class Query {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getSkip() {
|
||||
public long getSkip() {
|
||||
return this.skip;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.springframework.data.mongodb.gridfs.GridFsCriteria.*;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bson.BsonObjectId;
|
||||
import org.bson.Document;
|
||||
@@ -262,7 +263,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
}
|
||||
|
||||
private Document getMappedQuery(Document query) {
|
||||
return query == null ? null : queryMapper.getMappedObject(query, null);
|
||||
return query == null ? null : queryMapper.getMappedObject(query, Optional.empty());
|
||||
}
|
||||
|
||||
private GridFSBucket getGridFs() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.mongodb.repository.cdi;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.spi.CreationalContext;
|
||||
@@ -49,7 +50,7 @@ public class MongoRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
* {@link CustomRepositoryImplementationDetector}, can be {@literal null}.
|
||||
*/
|
||||
public MongoRepositoryBean(Bean<MongoOperations> operations, Set<Annotation> qualifiers, Class<T> repositoryType,
|
||||
BeanManager beanManager, CustomRepositoryImplementationDetector detector) {
|
||||
BeanManager beanManager, Optional<CustomRepositoryImplementationDetector> detector) {
|
||||
|
||||
super(qualifiers, repositoryType, beanManager, detector);
|
||||
|
||||
@@ -62,7 +63,7 @@ public class MongoRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||
* @see org.springframework.data.repository.cdi.CdiRepositoryBean#create(javax.enterprise.context.spi.CreationalContext, java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType, Object customImplementation) {
|
||||
protected T create(CreationalContext<T> creationalContext, Class<T> repositoryType, Optional<Object> customImplementation) {
|
||||
|
||||
MongoOperations mongoOperations = getDependencyInstance(operations, MongoOperations.class);
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(mongoOperations);
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.event.Observes;
|
||||
@@ -112,6 +113,6 @@ public class MongoRepositoryExtension extends CdiRepositoryExtensionSupport {
|
||||
|
||||
// Construct and return the repository bean.
|
||||
return new MongoRepositoryBean<T>(mongoOperations, qualifiers, repositoryType, beanManager,
|
||||
getCustomImplementationDetector());
|
||||
Optional.ofNullable(getCustomImplementationDetector()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
@@ -85,7 +87,7 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
|
||||
|
||||
applyQueryMetaAttributesWhenPresent(query);
|
||||
|
||||
ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor);
|
||||
ResultProcessor processor = method.getResultProcessor().withDynamicProjection(Optional.of(accessor));
|
||||
String collection = method.getEntityInformation().getCollectionName();
|
||||
|
||||
MongoQueryExecution execution = getExecution(query, accessor,
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -102,7 +104,7 @@ public abstract class AbstractReactiveMongoQuery implements RepositoryQuery {
|
||||
|
||||
applyQueryMetaAttributesWhenPresent(query);
|
||||
|
||||
ResultProcessor processor = method.getResultProcessor().withDynamicProjection(parameterAccessor);
|
||||
ResultProcessor processor = method.getResultProcessor().withDynamicProjection(Optional.of(parameterAccessor));
|
||||
String collection = method.getEntityInformation().getCollectionName();
|
||||
|
||||
ReactiveMongoQueryExecution execution = getExecution(query, parameterAccessor,
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Range;
|
||||
@@ -96,7 +97,7 @@ public class ConvertingParameterAccessor implements MongoParameterAccessor {
|
||||
* @see org.springframework.data.repository.query.ParameterAccessor#getDynamicProjection()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getDynamicProjection() {
|
||||
public Optional<Class<?>> getDynamicProjection() {
|
||||
return delegate.getDynamicProjection();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.EntityInstantiator;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
@@ -58,7 +60,7 @@ class DtoInstantiatingConverter implements Converter<Object, Object> {
|
||||
|
||||
this.targetType = dtoType;
|
||||
this.context = context;
|
||||
this.instantiator = instantiator.getInstantiatorFor(context.getPersistentEntity(dtoType));
|
||||
this.instantiator = instantiator.getInstantiatorFor(context.getRequiredPersistentEntity(dtoType));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -72,18 +74,18 @@ class DtoInstantiatingConverter implements Converter<Object, Object> {
|
||||
return source;
|
||||
}
|
||||
|
||||
final PersistentEntity<?, ?> sourceEntity = context.getPersistentEntity(source.getClass());
|
||||
final PersistentEntity<?, ?> sourceEntity = context.getRequiredPersistentEntity(source.getClass());
|
||||
final PersistentPropertyAccessor sourceAccessor = sourceEntity.getPropertyAccessor(source);
|
||||
final PersistentEntity<?, ?> targetEntity = context.getPersistentEntity(targetType);
|
||||
final PersistentEntity<?, ?> targetEntity = context.getRequiredPersistentEntity(targetType);
|
||||
final PreferredConstructor<?, ? extends PersistentProperty<?>> constructor = targetEntity
|
||||
.getPersistenceConstructor();
|
||||
.getPersistenceConstructor().get();
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
Object dto = instantiator.createInstance(targetEntity, new ParameterValueProvider() {
|
||||
|
||||
@Override
|
||||
public Object getParameterValue(Parameter parameter) {
|
||||
return sourceAccessor.getProperty(sourceEntity.getPersistentProperty(parameter.getName()));
|
||||
public Optional<Object> getParameterValue(Parameter parameter) {
|
||||
return sourceAccessor.getProperty(sourceEntity.getPersistentProperty(parameter.getName().get().toString()).get());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -99,7 +101,7 @@ class DtoInstantiatingConverter implements Converter<Object, Object> {
|
||||
}
|
||||
|
||||
dtoAccessor.setProperty(property,
|
||||
sourceAccessor.getProperty(sourceEntity.getPersistentProperty(property.getName())));
|
||||
sourceAccessor.getProperty(sourceEntity.getPersistentProperty(property.getName()).get()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
|
||||
|
||||
if (componentType == null) {
|
||||
return i;
|
||||
} else if (componentType.equals(candidate.getComponentType().getType())) {
|
||||
} else if (componentType.equals(candidate.getComponentType().get().getType())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -407,7 +408,7 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
|
||||
|
||||
private boolean isSpherical(MongoPersistentProperty property) {
|
||||
|
||||
GeoSpatialIndexed index = property.findAnnotation(GeoSpatialIndexed.class);
|
||||
return index != null && index.type().equals(GeoSpatialIndexType.GEO_2DSPHERE);
|
||||
Optional<GeoSpatialIndexed> index = property.findAnnotation(GeoSpatialIndexed.class);
|
||||
return index.isPresent() && index.get().type().equals(GeoSpatialIndexType.GEO_2DSPHERE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
@@ -39,7 +40,6 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.repository.query.ResultProcessor;
|
||||
import org.springframework.data.repository.query.ReturnedType;
|
||||
import org.springframework.data.repository.support.PageableExecutionUtils;
|
||||
import org.springframework.data.repository.support.PageableExecutionUtils.TotalSupplier;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.data.util.StreamUtils;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
@@ -140,17 +140,14 @@ interface MongoQueryExecution {
|
||||
|
||||
// Adjust limit if page would exceed the overall limit
|
||||
if (overallLimit != 0 && pageable.getOffset() + pageable.getPageSize() > overallLimit) {
|
||||
query.limit(overallLimit - pageable.getOffset());
|
||||
query.limit((int)(overallLimit - pageable.getOffset()));
|
||||
}
|
||||
|
||||
return PageableExecutionUtils.getPage(operations.find(query, type, collection), pageable, new TotalSupplier() {
|
||||
|
||||
@Override
|
||||
public long get() {
|
||||
return PageableExecutionUtils.getPage(operations.find(query, type, collection), pageable, () -> {
|
||||
|
||||
long count = operations.count(query, type, collection);
|
||||
return overallLimit != 0 ? Math.min(count, overallLimit) : count;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -279,8 +276,8 @@ interface MongoQueryExecution {
|
||||
return false;
|
||||
}
|
||||
|
||||
TypeInformation<?> componentType = returnType.getComponentType();
|
||||
return componentType != null && GeoResult.class.equals(componentType.getType());
|
||||
Optional<TypeInformation<?>> componentType = returnType.getComponentType();
|
||||
return componentType.isPresent() && GeoResult.class.equals(componentType.get().getType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,10 +313,8 @@ interface MongoQueryExecution {
|
||||
GeoResults<Object> geoResults = doExecuteQuery(query, type, collection);
|
||||
|
||||
Page<GeoResult<Object>> page = PageableExecutionUtils.getPage(geoResults.getContent(), accessor.getPageable(),
|
||||
new TotalSupplier() {
|
||||
() -> {
|
||||
|
||||
@Override
|
||||
public long get() {
|
||||
|
||||
ConvertingParameterAccessor parameterAccessor = new ConvertingParameterAccessor(operations.getConverter(),
|
||||
accessor);
|
||||
@@ -327,7 +322,7 @@ interface MongoQueryExecution {
|
||||
.applyQueryMetaAttributesWhenPresent(mongoQuery.createCountQuery(parameterAccessor));
|
||||
|
||||
return operations.count(countQuery, collection);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// transform to GeoPage after applying optimization
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
@@ -134,18 +135,18 @@ public class MongoQueryMethod extends QueryMethod {
|
||||
if (ClassUtils.isPrimitiveOrWrapper(returnedObjectType)) {
|
||||
|
||||
this.metadata = new SimpleMongoEntityMetadata<Object>((Class<Object>) domainClass,
|
||||
mappingContext.getPersistentEntity(domainClass));
|
||||
mappingContext.getRequiredPersistentEntity(domainClass));
|
||||
|
||||
} else {
|
||||
|
||||
MongoPersistentEntity<?> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);
|
||||
MongoPersistentEntity<?> managedEntity = mappingContext.getPersistentEntity(domainClass);
|
||||
returnedEntity = returnedEntity == null || returnedEntity.getType().isInterface() ? managedEntity
|
||||
Optional<? extends MongoPersistentEntity<?>> returnedEntity = mappingContext.getPersistentEntity(returnedObjectType);
|
||||
MongoPersistentEntity<?> managedEntity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
returnedEntity = !returnedEntity.isPresent() || returnedEntity.get().getType().isInterface() ? Optional.of(managedEntity)
|
||||
: returnedEntity;
|
||||
MongoPersistentEntity<?> collectionEntity = domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity
|
||||
MongoPersistentEntity<?> collectionEntity = domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity.get()
|
||||
: managedEntity;
|
||||
|
||||
this.metadata = new SimpleMongoEntityMetadata<Object>((Class<Object>) returnedEntity.getType(),
|
||||
this.metadata = new SimpleMongoEntityMetadata<Object>((Class<Object>) returnedEntity.get().getType(),
|
||||
collectionEntity);
|
||||
}
|
||||
}
|
||||
@@ -183,7 +184,7 @@ public class MongoQueryMethod extends QueryMethod {
|
||||
|
||||
if (Iterable.class.isAssignableFrom(returnType)) {
|
||||
TypeInformation<?> from = ClassTypeInformation.fromReturnTypeOf(method);
|
||||
return GeoResult.class.equals(from.getComponentType().getType());
|
||||
return GeoResult.class.equals(from.getComponentType().get().getType());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.util.JSON;
|
||||
@@ -99,7 +101,7 @@ public class PartTreeMongoQuery extends AbstractMongoQuery {
|
||||
|
||||
if (!StringUtils.hasText(fieldSpec)) {
|
||||
|
||||
ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
|
||||
ReturnedType returnedType = processor.withDynamicProjection(Optional.of(accessor)).getReturnedType();
|
||||
|
||||
if (returnedType.isProjecting()) {
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -163,8 +165,8 @@ interface ReactiveMongoQueryExecution {
|
||||
return false;
|
||||
}
|
||||
|
||||
TypeInformation<?> componentType = returnType.getComponentType();
|
||||
return componentType != null && GeoResult.class.equals(componentType.getType());
|
||||
Optional<TypeInformation<?>> componentType = returnType.getComponentType();
|
||||
return componentType.isPresent() && GeoResult.class.equals(componentType.get().getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ public class ReactiveMongoQueryMethod extends MongoQueryMethod {
|
||||
|
||||
boolean multiWrapper = ReactiveWrappers.isMultiValueType(returnType.getType());
|
||||
boolean singleWrapperWithWrappedPageableResult = ReactiveWrappers.isSingleValueType(returnType.getType())
|
||||
&& (PAGE_TYPE.isAssignableFrom(returnType.getComponentType())
|
||||
|| SLICE_TYPE.isAssignableFrom(returnType.getComponentType()));
|
||||
&& (PAGE_TYPE.isAssignableFrom(returnType.getComponentType().get())
|
||||
|| SLICE_TYPE.isAssignableFrom(returnType.getComponentType().get()));
|
||||
|
||||
if (singleWrapperWithWrappedPageableResult) {
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
@@ -125,7 +125,7 @@ public class ReactiveMongoQueryMethod extends MongoQueryMethod {
|
||||
|
||||
if (ReactiveWrappers.supports(method.getReturnType())) {
|
||||
TypeInformation<?> from = ClassTypeInformation.fromReturnTypeOf(method);
|
||||
return GeoResult.class.equals(from.getComponentType().getType());
|
||||
return GeoResult.class.equals(from.getComponentType().get().getType());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
@@ -94,7 +96,7 @@ public class ReactivePartTreeMongoQuery extends AbstractReactiveMongoQuery {
|
||||
|
||||
if (!StringUtils.hasText(fieldSpec)) {
|
||||
|
||||
ReturnedType returnedType = processor.withDynamicProjection(accessor).getReturnedType();
|
||||
ReturnedType returnedType = processor.withDynamicProjection(Optional.of(accessor)).getReturnedType();
|
||||
|
||||
if (returnedType.isProjecting()) {
|
||||
returnedType.getInputProperties().forEach(query.fields()::include);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MappingMongoEntityInformation<T, ID extends Serializable> extends P
|
||||
* @see org.springframework.data.mongodb.repository.MongoEntityInformation#getIdAttribute()
|
||||
*/
|
||||
public String getIdAttribute() {
|
||||
return entityMetadata.getIdProperty().getName();
|
||||
return entityMetadata.getIdProperty().get().getName();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.repository.support;
|
||||
|
||||
import static org.springframework.data.querydsl.QueryDslUtils.*;
|
||||
import static org.springframework.data.querydsl.QuerydslUtils.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
@@ -32,7 +33,7 @@ import org.springframework.data.mongodb.repository.query.MongoQueryMethod;
|
||||
import org.springframework.data.mongodb.repository.query.PartTreeMongoQuery;
|
||||
import org.springframework.data.mongodb.repository.query.StringBasedMongoQuery;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
@@ -96,7 +97,7 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
|
||||
RXJAVA_OBSERVABLE_PRESENT && RxJava1CrudRepository.class.isAssignableFrom(metadata.getRepositoryInterface()));
|
||||
|
||||
boolean isQueryDslRepository = QUERY_DSL_PRESENT
|
||||
&& QueryDslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());
|
||||
&& QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());
|
||||
|
||||
if (isReactiveRepository) {
|
||||
|
||||
@@ -126,8 +127,8 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
|
||||
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key, org.springframework.data.repository.query.EvaluationContextProvider)
|
||||
*/
|
||||
@Override
|
||||
protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) {
|
||||
return new MongoQueryLookupStrategy(operations, evaluationContextProvider, mappingContext);
|
||||
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) {
|
||||
return Optional.of(new MongoQueryLookupStrategy(operations, evaluationContextProvider, mappingContext));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -142,13 +143,7 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
|
||||
private <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
|
||||
RepositoryInformation information) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(domainClass);
|
||||
|
||||
if (entity == null) {
|
||||
throw new MappingException(
|
||||
String.format("Could not lookup mapping metadata for domain class %s!", domainClass.getName()));
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
return MongoEntityInformationSupport.<T, ID> entityInformationFor(entity,
|
||||
information != null ? information.getIdType() : null);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Persistable;
|
||||
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
||||
@@ -76,10 +77,10 @@ class PersistableMongoEntityInformation<T, ID extends Serializable> implements M
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public ID getId(T t) {
|
||||
public Optional<ID> getId(T t) {
|
||||
|
||||
if (t instanceof Persistable) {
|
||||
return (ID) ((Persistable<ID>) t).getId();
|
||||
return Optional.ofNullable(((Persistable<ID>) t).getId());
|
||||
}
|
||||
|
||||
return delegate.getId(t);
|
||||
|
||||
@@ -27,12 +27,11 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
||||
import org.springframework.data.querydsl.EntityPathResolver;
|
||||
import org.springframework.data.querydsl.QSort;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.repository.core.EntityMetadata;
|
||||
import org.springframework.data.repository.support.PageableExecutionUtils;
|
||||
import org.springframework.data.repository.support.PageableExecutionUtils.TotalSupplier;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.querydsl.core.types.EntityPath;
|
||||
@@ -50,7 +49,7 @@ import com.querydsl.mongodb.AbstractMongodbQuery;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleMongoRepository<T, ID>
|
||||
implements QueryDslPredicateExecutor<T> {
|
||||
implements QuerydslPredicateExecutor<T> {
|
||||
|
||||
private final PathBuilder<T> builder;
|
||||
private final EntityInformation<T, ID> entityInformation;
|
||||
@@ -144,13 +143,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
|
||||
|
||||
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query = createQueryFor(predicate);
|
||||
|
||||
return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetchResults().getResults(), pageable, new TotalSupplier() {
|
||||
|
||||
@Override
|
||||
public long get() {
|
||||
return createQueryFor(predicate).fetchCount();
|
||||
}
|
||||
});
|
||||
return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetchResults().getResults(), pageable, () -> createQueryFor(predicate).fetchCount());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -162,13 +155,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
|
||||
|
||||
AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query = createQuery();
|
||||
|
||||
return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetchResults().getResults(), pageable, new TotalSupplier() {
|
||||
|
||||
@Override
|
||||
public long get() {
|
||||
return createQuery().fetchCount();
|
||||
}
|
||||
});
|
||||
return PageableExecutionUtils.getPage(applyPagination(query, pageable).fetchResults().getResults(), pageable, () -> createQuery().fetchCount());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -57,8 +57,7 @@ public abstract class QuerydslRepositorySupport {
|
||||
protected <T> AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> from(final EntityPath<T> path) {
|
||||
|
||||
Assert.notNull(path, "EntityPath must not be null!");
|
||||
|
||||
MongoPersistentEntity<?> entity = context.getPersistentEntity(path.getType());
|
||||
MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(path.getType());
|
||||
return from(path, entity.getCollection());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
@@ -97,8 +98,8 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup
|
||||
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key, org.springframework.data.repository.query.EvaluationContextProvider)
|
||||
*/
|
||||
@Override
|
||||
protected QueryLookupStrategy getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) {
|
||||
return new MongoQueryLookupStrategy(operations, evaluationContextProvider, mappingContext);
|
||||
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key, EvaluationContextProvider evaluationContextProvider) {
|
||||
return Optional.of(new MongoQueryLookupStrategy(operations, evaluationContextProvider, mappingContext));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -113,14 +114,14 @@ public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySup
|
||||
private <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
|
||||
RepositoryInformation information) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(domainClass);
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = mappingContext.getPersistentEntity(domainClass);
|
||||
|
||||
if (entity == null) {
|
||||
if (!entity.isPresent()) {
|
||||
throw new MappingException(
|
||||
String.format("Could not lookup mapping metadata for domain class %s!", domainClass.getName()));
|
||||
}
|
||||
|
||||
return new MappingMongoEntityInformation<T, ID>((MongoPersistentEntity<T>) entity,
|
||||
return new MappingMongoEntityInformation<T, ID>((MongoPersistentEntity<T>) entity.get(),
|
||||
information != null ? (Class<ID>) information.getIdType() : null);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.domain.Example;
|
||||
@@ -37,7 +38,6 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
|
||||
import org.springframework.data.repository.support.PageableExecutionUtils;
|
||||
import org.springframework.data.repository.support.PageableExecutionUtils.TotalSupplier;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -118,9 +118,9 @@ public class SimpleMongoRepository<T, ID extends Serializable> implements MongoR
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable)
|
||||
*/
|
||||
public T findOne(ID id) {
|
||||
public Optional<T> findOne(ID id) {
|
||||
Assert.notNull(id, "The given id must not be null!");
|
||||
return mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName());
|
||||
return Optional.ofNullable(mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName()));
|
||||
}
|
||||
|
||||
private Query getIdQuery(Object id) {
|
||||
@@ -165,7 +165,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> implements MongoR
|
||||
*/
|
||||
public void delete(T entity) {
|
||||
Assert.notNull(entity, "The given entity must not be null!");
|
||||
delete(entityInformation.getId(entity));
|
||||
delete(entityInformation.getId(entity).orElse(null));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -275,13 +275,9 @@ public class SimpleMongoRepository<T, ID extends Serializable> implements MongoR
|
||||
final Query q = new Query(new Criteria().alike(example)).with(pageable);
|
||||
|
||||
List<S> list = mongoOperations.find(q, example.getProbeType(), entityInformation.getCollectionName());
|
||||
return PageableExecutionUtils.getPage(list, pageable, new TotalSupplier() {
|
||||
|
||||
@Override
|
||||
public long get() {
|
||||
return mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName());
|
||||
}
|
||||
});
|
||||
return PageableExecutionUtils.getPage(list, pageable, () ->
|
||||
mongoOperations.count(q, example.getProbeType(), entityInformation.getCollectionName())
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -272,7 +272,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
|
||||
Assert.notNull(entity, "The given entity must not be null!");
|
||||
|
||||
return delete(entityInformation.getId(entity));
|
||||
return delete(entityInformation.getId(entity).get());
|
||||
}
|
||||
|
||||
// TODO: should this one really be void?
|
||||
@@ -280,7 +280,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null!");
|
||||
|
||||
return Flux.fromIterable(entities).flatMap(entity -> delete(entityInformation.getId(entity))).then();
|
||||
return Flux.fromIterable(entities).flatMap(entity -> delete(entityInformation.getId(entity).get())).then();
|
||||
}
|
||||
|
||||
// TODO: should this one really be void?
|
||||
@@ -289,7 +289,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
|
||||
|
||||
Assert.notNull(entityStream, "The given Publisher of entities must not be null!");
|
||||
|
||||
return Flux.from(entityStream).flatMap(entity -> delete(entityInformation.getId(entity))).then();
|
||||
return Flux.from(entityStream).flatMap(entity -> delete(entityInformation.getId(entity).get())).then();
|
||||
}
|
||||
|
||||
// TODO: should this one really be void?
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.repository.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -106,10 +107,10 @@ class SpringDataMongodbSerializer extends MongodbSerializer {
|
||||
}
|
||||
|
||||
Path<?> parent = metadata.getParent();
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(parent.getType());
|
||||
MongoPersistentProperty property = entity.getPersistentProperty(metadata.getName());
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(parent.getType());
|
||||
Optional<MongoPersistentProperty> property = entity.getPersistentProperty(metadata.getName());
|
||||
|
||||
return property == null ? super.getKeyForPath(expr, metadata) : property.getFieldName();
|
||||
return !property.isPresent() ? super.getKeyForPath(expr, metadata) : property.get().getFieldName();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -121,7 +122,7 @@ class SpringDataMongodbSerializer extends MongodbSerializer {
|
||||
|
||||
if (ID_KEY.equals(key)) {
|
||||
DBObject superIdValue = super.asDBObject(key, value);
|
||||
Document mappedIdValue = mapper.getMappedObject((BasicDBObject) superIdValue, null);
|
||||
Document mappedIdValue = mapper.getMappedObject((BasicDBObject) superIdValue, Optional.empty());
|
||||
return (DBObject) JSON.parse(mappedIdValue.toJson());
|
||||
}
|
||||
return super.asDBObject(key, value instanceof Pattern ? value : converter.convertToMongoType(value));
|
||||
@@ -200,8 +201,8 @@ class SpringDataMongodbSerializer extends MongodbSerializer {
|
||||
return null;
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(parent.getType());
|
||||
return entity != null ? entity.getPersistentProperty(path.getMetadata().getName()) : null;
|
||||
Optional<? extends MongoPersistentEntity<?>> entity = mappingContext.getPersistentEntity(parent.getType());
|
||||
return entity.isPresent() ? entity.get().getRequiredPersistentProperty(path.getMetadata().getName()) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -106,7 +106,7 @@ public class AbstractMongoConfigurationUnitTests {
|
||||
|
||||
AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
|
||||
MongoMappingContext mappingContext = context.getBean(MongoMappingContext.class);
|
||||
BasicMongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(Entity.class);
|
||||
BasicMongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
|
||||
StandardEvaluationContext spElContext = (StandardEvaluationContext) ReflectionTestUtils.getField(entity, "context");
|
||||
|
||||
assertThat(spElContext.getBeanResolver(), is(notNullValue()));
|
||||
|
||||
@@ -106,7 +106,7 @@ public class AbstractReactiveMongoConfigurationUnitTests {
|
||||
|
||||
AbstractApplicationContext context = new AnnotationConfigApplicationContext(SampleMongoConfiguration.class);
|
||||
MongoMappingContext mappingContext = context.getBean(MongoMappingContext.class);
|
||||
BasicMongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(Entity.class);
|
||||
BasicMongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
|
||||
StandardEvaluationContext spElContext = (StandardEvaluationContext) ReflectionTestUtils.getField(entity, "context");
|
||||
|
||||
assertThat(spElContext.getBeanResolver(), is(notNullValue()));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.mongodb.core;
|
||||
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.mongodb.core;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,12 +17,12 @@ package org.springframework.data.mongodb.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bson.Document;
|
||||
@@ -196,7 +196,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
template.updateFirst(query, update, Wrapper.class);
|
||||
|
||||
QueryMapper queryMapper = new QueryMapper(converter);
|
||||
Document reference = queryMapper.getMappedObject(update.getUpdateObject(), null);
|
||||
Document reference = queryMapper.getMappedObject(update.getUpdateObject(), Optional.empty());
|
||||
|
||||
verify(collection, times(1)).updateOne(Mockito.any(org.bson.Document.class), eq(reference),
|
||||
Mockito.any(UpdateOptions.class)); // .update(Mockito.any(Document.class), eq(reference), anyBoolean(),
|
||||
@@ -278,13 +278,8 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
verify(spy, times(1)).addApplicationListener(argThat(new ArgumentMatcher<MongoPersistentEntityIndexCreator>() {
|
||||
|
||||
@Override
|
||||
public boolean matches(Object argument) {
|
||||
|
||||
if (!(argument instanceof MongoPersistentEntityIndexCreator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((MongoPersistentEntityIndexCreator) argument).isIndexCreatorFor(mappingContext);
|
||||
public boolean matches(MongoPersistentEntityIndexCreator argument) {
|
||||
return argument.isIndexCreatorFor(mappingContext);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -574,7 +569,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
private MongoTemplate mockOutGetDb() {
|
||||
|
||||
MongoTemplate template = spy(this.template);
|
||||
stub(template.getDb()).toReturn(db);
|
||||
when(template.getDb()).thenReturn(db);
|
||||
return template;
|
||||
}
|
||||
|
||||
@@ -584,7 +579,7 @@ public class MongoTemplateUnitTests extends MongoOperationsUnitTests {
|
||||
@Override
|
||||
protected MongoOperations getOperationsForExceptionHandling() {
|
||||
MongoTemplate template = spy(this.template);
|
||||
stub(template.getDb()).toThrow(new MongoException("Error!"));
|
||||
when(template.getDb()).thenThrow(new MongoException("Error!"));
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -106,8 +107,8 @@ public class NoExplicitIdTests {
|
||||
Map<String, Object> map = mongoOps.findOne(query(where("someString").is(noid.someString)), Map.class,
|
||||
"typeWithoutIdProperty");
|
||||
|
||||
TypeWithoutIdProperty retrieved = repo.findOne(map.get("_id").toString());
|
||||
assertThat(retrieved.someString, is(noid.someString));
|
||||
Optional<TypeWithoutIdProperty> retrieved = repo.findOne(map.get("_id").toString());
|
||||
assertThat(retrieved.get().someString, is(noid.someString));
|
||||
}
|
||||
|
||||
static class TypeWithoutIdProperty {
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.mongodb.core;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.convert;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.springframework.data.mongodb.core.convert;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.mongodb.core.convert.LazyLoadingTestUtils.*;
|
||||
|
||||
@@ -473,9 +471,9 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
@Test // DATAMONGO-1012
|
||||
public void shouldEagerlyResolveIdPropertyWithFieldAccess() {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(ClassWithLazyDbRefs.class);
|
||||
MongoPersistentProperty property = entity.getPersistentProperty("dbRefToConcreteType");
|
||||
MongoPersistentEntity<?> propertyEntity = mappingContext.getPersistentEntity(property);
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(ClassWithLazyDbRefs.class);
|
||||
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToConcreteType");
|
||||
MongoPersistentEntity<?> propertyEntity = mappingContext.getRequiredPersistentEntity(property);
|
||||
|
||||
String idValue = new ObjectId().toString();
|
||||
DBRef dbRef = converter.toDBRef(new LazyDbRefTarget(idValue), property);
|
||||
@@ -485,7 +483,7 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
ClassWithLazyDbRefs result = converter.read(ClassWithLazyDbRefs.class, object);
|
||||
|
||||
PersistentPropertyAccessor accessor = propertyEntity.getPropertyAccessor(result.dbRefToConcreteType);
|
||||
MongoPersistentProperty idProperty = mappingContext.getPersistentEntity(LazyDbRefTarget.class).getIdProperty();
|
||||
MongoPersistentProperty idProperty = mappingContext.getRequiredPersistentEntity(LazyDbRefTarget.class).getIdProperty().get();
|
||||
|
||||
assertThat(accessor.getProperty(idProperty), is(notNullValue()));
|
||||
assertProxyIsResolved(result.dbRefToConcreteType, false);
|
||||
@@ -494,8 +492,8 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
@Test // DATAMONGO-1012
|
||||
public void shouldNotEagerlyResolveIdPropertyWithPropertyAccess() {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(ClassWithLazyDbRefs.class);
|
||||
MongoPersistentProperty property = entity.getPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(ClassWithLazyDbRefs.class);
|
||||
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");
|
||||
|
||||
String idValue = new ObjectId().toString();
|
||||
DBRef dbRef = converter.toDBRef(new LazyDbRefTargetPropertyAccess(idValue), property);
|
||||
@@ -512,8 +510,8 @@ public class DbRefMappingMongoConverterUnitTests {
|
||||
@Test // DATAMONGO-1076
|
||||
public void shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked() throws Exception {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(WithObjectMethodOverrideLazyDbRefs.class);
|
||||
MongoPersistentProperty property = entity.getPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");
|
||||
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(WithObjectMethodOverrideLazyDbRefs.class);
|
||||
MongoPersistentProperty property = entity.getRequiredPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");
|
||||
|
||||
String idValue = new ObjectId().toString();
|
||||
DBRef dbRef = converter.toDBRef(new LazyDbRefTargetPropertyAccess(idValue), property);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.mongodb.core.convert;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.junit.Assert.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.Before;
|
||||
@@ -186,13 +187,13 @@ public class DefaultMongoTypeMapperUnitTests {
|
||||
|
||||
private void readsTypeFromField(Document document, Class<?> type) {
|
||||
|
||||
TypeInformation<?> typeInfo = typeMapper.readType(document);
|
||||
Optional<TypeInformation<?>> typeInfo = typeMapper.readType(document);
|
||||
|
||||
if (type != null) {
|
||||
assertThat(typeInfo, is(notNullValue()));
|
||||
assertThat(typeInfo.getType(), is(typeCompatibleWith(type)));
|
||||
assertThat(typeInfo.get().getType(), is(typeCompatibleWith(type)));
|
||||
} else {
|
||||
assertThat(typeInfo, is(nullValue()));
|
||||
assertThat(typeInfo, is(Optional.empty()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.hamcrest.core.Is;
|
||||
@@ -94,7 +95,7 @@ public class QueryMapperUnitTests {
|
||||
public void translatesIdPropertyIntoIdKey() {
|
||||
|
||||
org.bson.Document query = new org.bson.Document("foo", "value");
|
||||
MongoPersistentEntity<?> entity = context.getPersistentEntity(Sample.class);
|
||||
MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(Sample.class);
|
||||
|
||||
org.bson.Document result = mapper.getMappedObject(query, entity);
|
||||
assertThat(result.get("_id"), is(notNullValue()));
|
||||
@@ -142,7 +143,7 @@ public class QueryMapperUnitTests {
|
||||
@Test // DATAMONGO-326
|
||||
public void handlesEnumsCorrectly() {
|
||||
Query query = query(where("foo").is(Enum.INSTANCE));
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), null);
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), Optional.empty());
|
||||
|
||||
Object object = result.get("foo");
|
||||
assertThat(object, is(instanceOf(String.class)));
|
||||
@@ -151,7 +152,7 @@ public class QueryMapperUnitTests {
|
||||
@Test
|
||||
public void handlesEnumsInNotEqualCorrectly() {
|
||||
Query query = query(where("foo").ne(Enum.INSTANCE));
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), null);
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), Optional.empty());
|
||||
|
||||
Object object = result.get("foo");
|
||||
assertThat(object, is(instanceOf(org.bson.Document.class)));
|
||||
@@ -165,7 +166,7 @@ public class QueryMapperUnitTests {
|
||||
public void handlesEnumsIn$InCorrectly() {
|
||||
|
||||
Query query = query(where("foo").in(Enum.INSTANCE));
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), null);
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), Optional.empty());
|
||||
|
||||
Object object = result.get("foo");
|
||||
assertThat(object, is(instanceOf(org.bson.Document.class)));
|
||||
@@ -183,7 +184,7 @@ public class QueryMapperUnitTests {
|
||||
public void handlesNativelyBuiltQueryCorrectly() {
|
||||
|
||||
DBObject query = new QueryBuilder().or(new BasicDBObject("foo", "bar")).get();
|
||||
mapper.getMappedObject(new org.bson.Document(query.toMap()), null);
|
||||
mapper.getMappedObject(new org.bson.Document(query.toMap()), Optional.empty());
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-369
|
||||
@@ -193,7 +194,7 @@ public class QueryMapperUnitTests {
|
||||
query.put("foo", new org.bson.Document("$in", Arrays.asList(1, 2)));
|
||||
query.put("bar", new Person());
|
||||
|
||||
org.bson.Document result = mapper.getMappedObject(query, null);
|
||||
org.bson.Document result = mapper.getMappedObject(query, Optional.empty());
|
||||
assertThat(result.get("bar"), is(notNullValue()));
|
||||
}
|
||||
|
||||
@@ -202,7 +203,7 @@ public class QueryMapperUnitTests {
|
||||
|
||||
Query query = new BasicQuery("{ 'tags' : { '$all' : [ 'green', 'orange']}}");
|
||||
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), null);
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), Optional.empty());
|
||||
assertThat(result.toJson(), is(query.getQueryObject().toJson()));
|
||||
}
|
||||
|
||||
@@ -212,7 +213,7 @@ public class QueryMapperUnitTests {
|
||||
org.bson.Document document = new org.bson.Document("id", new ObjectId().toString());
|
||||
document.put("nested", new org.bson.Document("id", new ObjectId().toString()));
|
||||
|
||||
MongoPersistentEntity<?> entity = context.getPersistentEntity(ClassWithDefaultId.class);
|
||||
MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(ClassWithDefaultId.class);
|
||||
|
||||
org.bson.Document result = mapper.getMappedObject(document, entity);
|
||||
assertThat(result.get("_id"), is(instanceOf(ObjectId.class)));
|
||||
@@ -354,7 +355,7 @@ public class QueryMapperUnitTests {
|
||||
String id = new ObjectId().toString();
|
||||
Query query = query(where("id").is(id));
|
||||
|
||||
org.bson.Document object = mapper.getMappedObject(query.getQueryObject(), null);
|
||||
org.bson.Document object = mapper.getMappedObject(query.getQueryObject(), Optional.empty());
|
||||
|
||||
assertThat(object.containsKey("id"), is(true));
|
||||
assertThat(object.get("id"), is((Object) id));
|
||||
@@ -382,7 +383,7 @@ public class QueryMapperUnitTests {
|
||||
|
||||
org.bson.Document document = new org.bson.Document().append("_id", new ObjectId().toString());
|
||||
|
||||
org.bson.Document mapped = mapper.getMappedObject(document, null);
|
||||
org.bson.Document mapped = mapper.getMappedObject(document, Optional.empty());
|
||||
assertThat(mapped.containsKey("_id"), is(true));
|
||||
assertThat(mapped.get("_id"), is(instanceOf(ObjectId.class)));
|
||||
}
|
||||
@@ -392,7 +393,7 @@ public class QueryMapperUnitTests {
|
||||
|
||||
Query query = query(where("reference").exists(false));
|
||||
|
||||
BasicMongoPersistentEntity<?> entity = context.getPersistentEntity(WithDBRef.class);
|
||||
BasicMongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(WithDBRef.class);
|
||||
org.bson.Document mappedObject = mapper.getMappedObject(query.getQueryObject(), entity);
|
||||
|
||||
org.bson.Document reference = getAsDocument(mappedObject, "reference");
|
||||
@@ -408,7 +409,7 @@ public class QueryMapperUnitTests {
|
||||
|
||||
Query query = query(where("someString").is("foo").andOperator(where("reference").in(reference)));
|
||||
|
||||
BasicMongoPersistentEntity<?> entity = context.getPersistentEntity(WithDBRef.class);
|
||||
BasicMongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(WithDBRef.class);
|
||||
org.bson.Document mappedObject = mapper.getMappedObject(query.getQueryObject(), entity);
|
||||
|
||||
assertThat(mappedObject.get("someString"), is((Object) "foo"));
|
||||
@@ -426,7 +427,7 @@ public class QueryMapperUnitTests {
|
||||
|
||||
Query query = query(where("myvalue").is("$334"));
|
||||
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), null);
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), Optional.empty());
|
||||
|
||||
assertThat(result.keySet(), hasSize(1));
|
||||
assertThat(result.get("myvalue"), is((Object) "$334"));
|
||||
@@ -437,7 +438,7 @@ public class QueryMapperUnitTests {
|
||||
|
||||
Query query = query(where("myvalue").is("$center"));
|
||||
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), null);
|
||||
org.bson.Document result = mapper.getMappedObject(query.getQueryObject(), Optional.empty());
|
||||
|
||||
assertThat(result.keySet(), hasSize(1));
|
||||
assertThat(result.get("myvalue"), is((Object) "$center"));
|
||||
@@ -449,7 +450,7 @@ public class QueryMapperUnitTests {
|
||||
Query query = query(where("someString").is("foo"));
|
||||
query.fields().exclude("reference");
|
||||
|
||||
BasicMongoPersistentEntity<?> entity = context.getPersistentEntity(WithDBRef.class);
|
||||
BasicMongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(WithDBRef.class);
|
||||
org.bson.Document queryResult = mapper.getMappedObject(query.getQueryObject(), entity);
|
||||
org.bson.Document fieldsResult = mapper.getMappedObject(query.getFieldsObject(), entity);
|
||||
|
||||
@@ -460,8 +461,8 @@ public class QueryMapperUnitTests {
|
||||
@Test // DATAMONGO-686
|
||||
public void queryMapperShouldNotChangeStateInGivenQueryObjectWhenIdConstrainedByInList() {
|
||||
|
||||
BasicMongoPersistentEntity<?> persistentEntity = context.getPersistentEntity(Sample.class);
|
||||
String idPropertyName = persistentEntity.getIdProperty().getName();
|
||||
BasicMongoPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(Sample.class);
|
||||
String idPropertyName = persistentEntity.getIdProperty().get().getName();
|
||||
org.bson.Document queryObject = query(where(idPropertyName).in("42")).getQueryObject();
|
||||
|
||||
Object idValuesBefore = getAsDocument(queryObject, idPropertyName).get("$in");
|
||||
@@ -518,7 +519,7 @@ public class QueryMapperUnitTests {
|
||||
@Test // DATAMONGO-773
|
||||
public void queryMapperShouldBeAbleToProcessQueriesThatIncludeDbRefFields() {
|
||||
|
||||
BasicMongoPersistentEntity<?> persistentEntity = context.getPersistentEntity(WithDBRef.class);
|
||||
BasicMongoPersistentEntity<?> persistentEntity = context.getRequiredPersistentEntity(WithDBRef.class);
|
||||
|
||||
Query qry = query(where("someString").is("abc"));
|
||||
qry.fields().include("reference");
|
||||
|
||||
@@ -19,7 +19,6 @@ import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.mongodb.util.MongoClientVersion.*;
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class MongoPersistentEntityIndexCreatorUnitTests {
|
||||
|
||||
MongoPersistentEntityIndexCreator creator = new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
|
||||
|
||||
MongoPersistentEntity<?> entity = personMappingContext.getPersistentEntity(Person.class);
|
||||
MongoPersistentEntity<?> entity = personMappingContext.getRequiredPersistentEntity(Person.class);
|
||||
MappingContextEvent<MongoPersistentEntity<?>, MongoPersistentProperty> event = new MappingContextEvent<MongoPersistentEntity<?>, MongoPersistentProperty>(
|
||||
personMappingContext, entity);
|
||||
|
||||
|
||||
@@ -1178,7 +1178,7 @@ public class MongoPersistentEntityIndexResolverUnitTests {
|
||||
|
||||
MongoMappingContext mappingContext = prepareMappingContext(type);
|
||||
MongoPersistentEntityIndexResolver resolver = new MongoPersistentEntityIndexResolver(mappingContext);
|
||||
return resolver.resolveIndexForEntity(mappingContext.getPersistentEntity(type));
|
||||
return resolver.resolveIndexForEntity(mappingContext.getRequiredPersistentEntity(type));
|
||||
}
|
||||
|
||||
private static MongoMappingContext prepareMappingContext(Class<?> type) {
|
||||
|
||||
@@ -86,8 +86,8 @@ public class MongoMappingContextUnitTests {
|
||||
}
|
||||
});
|
||||
|
||||
MongoPersistentEntity<?> entity = context.getPersistentEntity(Person.class);
|
||||
assertThat(entity.getPersistentProperty("firstname").getFieldName(), is("FIRSTNAME"));
|
||||
MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(Person.class);
|
||||
assertThat(entity.getRequiredPersistentProperty("firstname").getFieldName(), is("FIRSTNAME"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-607
|
||||
@@ -116,27 +116,27 @@ public class MongoMappingContextUnitTests {
|
||||
public void mappingContextShouldAcceptClassWithImplicitIdProperty() {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
BasicMongoPersistentEntity<?> pe = context.getPersistentEntity(ClassWithImplicitId.class);
|
||||
BasicMongoPersistentEntity<?> pe = context.getRequiredPersistentEntity(ClassWithImplicitId.class);
|
||||
|
||||
assertThat(pe, is(not(nullValue())));
|
||||
assertThat(pe.isIdProperty(pe.getPersistentProperty("id")), is(true));
|
||||
assertThat(pe.isIdProperty(pe.getRequiredPersistentProperty("id")), is(true));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-688
|
||||
public void mappingContextShouldAcceptClassWithExplicitIdProperty() {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
BasicMongoPersistentEntity<?> pe = context.getPersistentEntity(ClassWithExplicitId.class);
|
||||
BasicMongoPersistentEntity<?> pe = context.getRequiredPersistentEntity(ClassWithExplicitId.class);
|
||||
|
||||
assertThat(pe, is(not(nullValue())));
|
||||
assertThat(pe.isIdProperty(pe.getPersistentProperty("myId")), is(true));
|
||||
assertThat(pe.isIdProperty(pe.getRequiredPersistentProperty("myId")), is(true));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-688
|
||||
public void mappingContextShouldAcceptClassWithExplicitAndImplicitIdPropertyByGivingPrecedenceToExplicitIdProperty() {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
BasicMongoPersistentEntity<?> pe = context.getPersistentEntity(ClassWithExplicitIdAndImplicitId.class);
|
||||
BasicMongoPersistentEntity<?> pe = context.getRequiredPersistentEntity(ClassWithExplicitIdAndImplicitId.class);
|
||||
assertThat(pe, is(not(nullValue())));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -56,8 +57,8 @@ public class AuditingEventListenerUnitTests {
|
||||
mappingContext.getPersistentEntity(Sample.class);
|
||||
|
||||
handler = spy(new IsNewAwareAuditingHandler(new PersistentEntities(Arrays.asList(mappingContext))));
|
||||
doNothing().when(handler).markCreated(Mockito.any(Object.class));
|
||||
doNothing().when(handler).markModified(Mockito.any(Object.class));
|
||||
doNothing().when(handler).markCreated(Mockito.any(Optional.class));
|
||||
doNothing().when(handler).markModified(Mockito.any(Optional.class));
|
||||
|
||||
listener = new AuditingEventListener(new ObjectFactory<IsNewAwareAuditingHandler>() {
|
||||
|
||||
@@ -79,8 +80,8 @@ public class AuditingEventListenerUnitTests {
|
||||
Sample sample = new Sample();
|
||||
listener.onApplicationEvent(new BeforeConvertEvent<Object>(sample, "collection-1"));
|
||||
|
||||
verify(handler, times(1)).markCreated(sample);
|
||||
verify(handler, times(0)).markModified(Mockito.any(Sample.class));
|
||||
verify(handler, times(1)).markCreated(Optional.of(sample));
|
||||
verify(handler, times(0)).markModified(Mockito.any(Optional.class));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-577
|
||||
@@ -90,8 +91,8 @@ public class AuditingEventListenerUnitTests {
|
||||
sample.id = "id";
|
||||
listener.onApplicationEvent(new BeforeConvertEvent<Object>(sample, "collection-1"));
|
||||
|
||||
verify(handler, times(0)).markCreated(Mockito.any(Sample.class));
|
||||
verify(handler, times(1)).markModified(sample);
|
||||
verify(handler, times(0)).markCreated(Mockito.any(Optional.class));
|
||||
verify(handler, times(1)).markModified(Optional.of(sample));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -106,9 +107,9 @@ public class ReactivePerformanceTests {
|
||||
|
||||
converter = new MappingMongoConverter(new DbRefResolver() {
|
||||
@Override
|
||||
public Object resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback,
|
||||
DbRefProxyHandler proxyHandler) {
|
||||
return null;
|
||||
public Optional<Object> resolveDbRef(MongoPersistentProperty property, DBRef dbref, DbRefResolverCallback callback,
|
||||
DbRefProxyHandler proxyHandler) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ContactRepositoryIntegrationTests {
|
||||
Person person = new Person("Oliver", "Gierke");
|
||||
Contact result = repository.save(person);
|
||||
|
||||
assertTrue(repository.findOne(result.getId().toString()) instanceof Person);
|
||||
assertTrue(repository.findOne(result.getId().toString()).get() instanceof Person);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1245
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.data.geo.GeoResults;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.data.geo.Polygon;
|
||||
import org.springframework.data.mongodb.repository.Person.Sex;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ import org.springframework.data.repository.query.Param;
|
||||
* @author Fırat KÜÇÜK
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public interface PersonRepository extends MongoRepository<Person, String>, QueryDslPredicateExecutor<Person> {
|
||||
public interface PersonRepository extends MongoRepository<Person, String>, QuerydslPredicateExecutor<Person> {
|
||||
|
||||
/**
|
||||
* Returns all {@link Person}s with the given lastname.
|
||||
|
||||
@@ -64,7 +64,7 @@ public class PersonRepositoryLazyLoadingIntegrationTests {
|
||||
person.setRealFans(new ArrayList<User>(Arrays.asList(thomas)));
|
||||
repository.save(person);
|
||||
|
||||
Person oliver = repository.findOne(person.id);
|
||||
Person oliver = repository.findOne(person.id).get();
|
||||
List<User> fans = oliver.getFans();
|
||||
|
||||
assertProxyIsResolved(fans, false);
|
||||
@@ -87,7 +87,7 @@ public class PersonRepositoryLazyLoadingIntegrationTests {
|
||||
person.setRealFans(new ArrayList<User>(Arrays.asList(thomas)));
|
||||
repository.save(person);
|
||||
|
||||
Person oliver = repository.findOne(person.id);
|
||||
Person oliver = repository.findOne(person.id).get();
|
||||
List<User> realFans = oliver.getRealFans();
|
||||
|
||||
assertProxyIsResolved(realFans, false);
|
||||
@@ -114,7 +114,7 @@ public class PersonRepositoryLazyLoadingIntegrationTests {
|
||||
person.setCoworker(thomas);
|
||||
repository.save(person);
|
||||
|
||||
Person oliver = repository.findOne(person.id);
|
||||
Person oliver = repository.findOne(person.id).get();
|
||||
|
||||
User coworker = oliver.getCoworker();
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -126,8 +126,8 @@ public class ConvertingParameterAccessorUnitTests {
|
||||
MongoParameterAccessor delegate = new StubParameterAccessor(parameters);
|
||||
PotentiallyConvertingIterator iterator = new ConvertingParameterAccessor(converter, delegate).iterator();
|
||||
|
||||
MongoPersistentEntity<?> entity = context.getPersistentEntity(Entity.class);
|
||||
MongoPersistentProperty property = entity.getPersistentProperty("property");
|
||||
MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(Entity.class);
|
||||
MongoPersistentProperty property = entity.getRequiredPersistentProperty("property");
|
||||
|
||||
return iterator.nextConverted(property);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.OPCode;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Range;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -144,7 +146,7 @@ class StubParameterAccessor implements MongoParameterAccessor {
|
||||
* @see org.springframework.data.repository.query.ParameterAccessor#getDynamicProjection()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getDynamicProjection() {
|
||||
return null;
|
||||
public Optional<Class<?>> getDynamicProjection() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -67,7 +68,7 @@ public class MongoRepositoryFactoryUnitTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void usesMappingMongoEntityInformationIfMappingContextSet() {
|
||||
|
||||
when(mappingContext.getPersistentEntity(Person.class)).thenReturn(entity);
|
||||
when(mappingContext.getPersistentEntity(Person.class)).thenReturn(Optional.of(entity));
|
||||
when(entity.getType()).thenReturn(Person.class);
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
|
||||
@@ -79,7 +80,7 @@ public class MongoRepositoryFactoryUnitTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void createsRepositoryWithIdTypeLong() {
|
||||
|
||||
when(mappingContext.getPersistentEntity(Person.class)).thenReturn(entity);
|
||||
when(mappingContext.getPersistentEntity(Person.class)).thenReturn(Optional.of(entity));
|
||||
when(entity.getType()).thenReturn(Person.class);
|
||||
|
||||
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -91,7 +92,7 @@ public class SimpleMongoRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void findOneFromCustomCollectionName() {
|
||||
Person result = repository.findOne(dave.getId());
|
||||
Person result = repository.findOne(dave.getId()).get();
|
||||
assertThat(result, is(dave));
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ public class SimpleMongoRepositoryTests {
|
||||
Person person1 = new Person("First1" + randomId, "Last2" + randomId, 42);
|
||||
person1 = repository.insert(person1);
|
||||
|
||||
Person saved = repository.findOne(person1.getId());
|
||||
Person saved = repository.findOne(person1.getId()).get();
|
||||
|
||||
assertThat(saved, is(equalTo(person1)));
|
||||
}
|
||||
@@ -428,8 +429,8 @@ public class SimpleMongoRepositoryTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(Person entity) {
|
||||
return entity.getId();
|
||||
public Optional<String> getId(Person entity) {
|
||||
return Optional.ofNullable(entity.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.test.util;
|
||||
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
Reference in New Issue
Block a user