Search in sources :

Example 1 with DotPath

use of org.springframework.data.mongodb.util.DotPath in project spring-data-mongodb by spring-projects.

the class MongoPersistentEntityIndexResolver method resolveAndAddIndexesForAssociation.

private void resolveAndAddIndexesForAssociation(Association<MongoPersistentProperty> association, List<IndexDefinitionHolder> indexes, String path, String collection) {
    MongoPersistentProperty property = association.getInverse();
    DotPath propertyDotPath = DotPath.from(path).append(property.getFieldName());
    if (property.isAnnotationPresent(GeoSpatialIndexed.class) || property.isAnnotationPresent(TextIndexed.class)) {
        throw new MappingException(String.format("Cannot create geospatial-/text- index on DBRef in collection '%s' for path '%s'.", collection, propertyDotPath));
    }
    List<IndexDefinitionHolder> indexDefinitions = createIndexDefinitionHolderForProperty(propertyDotPath.toString(), collection, property);
    if (!indexDefinitions.isEmpty()) {
        indexes.addAll(indexDefinitions);
    }
}
Also used : DotPath(org.springframework.data.mongodb.util.DotPath) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) MappingException(org.springframework.data.mapping.MappingException)

Example 2 with DotPath

use of org.springframework.data.mongodb.util.DotPath in project spring-data-mongodb by spring-projects.

the class MongoPersistentEntityIndexResolver method guardAndPotentiallyAddIndexForProperty.

private void guardAndPotentiallyAddIndexForProperty(MongoPersistentProperty persistentProperty, String dotPath, Path path, String collection, List<IndexDefinitionHolder> indexes, CycleGuard guard) {
    DotPath propertyDotPath = DotPath.from(dotPath);
    if (!persistentProperty.isUnwrapped()) {
        propertyDotPath = propertyDotPath.append(persistentProperty.getFieldName());
    }
    Path propertyPath = path.append(persistentProperty);
    guard.protect(persistentProperty, propertyPath);
    if (isMapWithoutWildcardIndex(persistentProperty)) {
        return;
    }
    if (persistentProperty.isEntity()) {
        try {
            indexes.addAll(resolveIndexForEntity(mappingContext.getPersistentEntity(persistentProperty), propertyDotPath.toString(), propertyPath, collection, guard));
        } catch (CyclicPropertyReferenceException e) {
            LOGGER.info(e.getMessage());
        }
    }
    List<IndexDefinitionHolder> indexDefinitions = createIndexDefinitionHolderForProperty(propertyDotPath.toString(), collection, persistentProperty);
    if (!indexDefinitions.isEmpty()) {
        indexes.addAll(indexDefinitions);
    }
}
Also used : Path(org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.CycleGuard.Path) DotPath(org.springframework.data.mongodb.util.DotPath) DotPath(org.springframework.data.mongodb.util.DotPath)

Example 3 with DotPath

use of org.springframework.data.mongodb.util.DotPath in project spring-data-mongodb by spring-projects.

the class QueryMapper method filterUnwrappedObjects.

private Document filterUnwrappedObjects(Document fieldsObject, @Nullable MongoPersistentEntity<?> entity) {
    if (fieldsObject.isEmpty() || entity == null) {
        return fieldsObject;
    }
    Document target = new Document();
    for (Entry<String, Object> field : fieldsObject.entrySet()) {
        try {
            PropertyPath path = PropertyPath.from(field.getKey(), entity.getTypeInformation());
            PersistentPropertyPath<MongoPersistentProperty> persistentPropertyPath = mappingContext.getPersistentPropertyPath(path);
            MongoPersistentProperty property = mappingContext.getPersistentPropertyPath(path).getRequiredLeafProperty();
            if (property.isUnwrapped() && property.isEntity()) {
                MongoPersistentEntity<?> unwrappedEntity = mappingContext.getRequiredPersistentEntity(property);
                for (MongoPersistentProperty unwrappedProperty : unwrappedEntity) {
                    DotPath dotPath = DotPath.from(persistentPropertyPath.toDotPath()).append(unwrappedProperty.getName());
                    target.put(dotPath.toString(), field.getValue());
                }
            } else {
                target.put(field.getKey(), field.getValue());
            }
        } catch (RuntimeException e) {
            target.put(field.getKey(), field.getValue());
        }
    }
    return target;
}
Also used : DotPath(org.springframework.data.mongodb.util.DotPath) MongoPersistentProperty(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty) InvalidPersistentPropertyPath(org.springframework.data.mapping.context.InvalidPersistentPropertyPath) PersistentPropertyPath(org.springframework.data.mapping.PersistentPropertyPath) PropertyPath(org.springframework.data.mapping.PropertyPath) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Document(org.bson.Document) NestedDocument(org.springframework.data.mongodb.core.convert.MappingMongoConverter.NestedDocument)

Aggregations

DotPath (org.springframework.data.mongodb.util.DotPath)3 MongoPersistentProperty (org.springframework.data.mongodb.core.mapping.MongoPersistentProperty)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 Document (org.bson.Document)1 MappingException (org.springframework.data.mapping.MappingException)1 PersistentPropertyPath (org.springframework.data.mapping.PersistentPropertyPath)1 PropertyPath (org.springframework.data.mapping.PropertyPath)1 InvalidPersistentPropertyPath (org.springframework.data.mapping.context.InvalidPersistentPropertyPath)1 NestedDocument (org.springframework.data.mongodb.core.convert.MappingMongoConverter.NestedDocument)1 Path (org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.CycleGuard.Path)1