final TextIndexIncludeOptions includeOptions, final CycleGuard guard) { entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
/** * Recursively resolve and inspect properties of given {@literal type} for indexes to be created. * * @param type * @param dotPath The {@literal "dot} path. * @param path {@link PersistentProperty} path for cycle detection. * @param collection * @param guard * @return List of {@link IndexDefinitionHolder} representing indexes for given type and its referenced property * types. Will never be {@code null}. */ private List<IndexDefinitionHolder> resolveIndexForClass(final TypeInformation<?> type, final String dotPath, final Path path, final String collection, final CycleGuard guard) { MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type); final List<IndexDefinitionHolder> indexInformation = new ArrayList<>(); indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions(dotPath, collection, entity)); entity.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> this .guradAndPotentiallyAddIndexForProperty(property, dotPath, path, collection, indexInformation, guard)); indexInformation.addAll(resolveIndexesForDbrefs(dotPath, collection, entity)); return indexInformation; }
private String getMappedPropertyPath(String path, Class<?> probeType) { MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(probeType); Iterator<String> parts = Arrays.asList(path.split("\\.")).iterator(); final Stack<MongoPersistentProperty> stack = new Stack<>(); List<String> resultParts = new ArrayList<>(); while (parts.hasNext()) { String part = parts.next(); MongoPersistentProperty prop = entity.getPersistentProperty(part); if (prop == null) { entity.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> { if (property.getFieldName().equals(part)) { stack.push(property); } }); if (stack.isEmpty()) { return ""; } prop = stack.pop(); } resultParts.add(prop.getName()); if (prop.isEntity() && mappingContext.hasPersistentEntityFor(prop.getActualType())) { entity = mappingContext.getRequiredPersistentEntity(prop.getActualType()); } else { break; } } return StringUtils.collectionToDelimitedString(resultParts, "."); }
/** * Resolve the {@link IndexDefinition}s for given {@literal root} entity by traversing {@link MongoPersistentProperty} * scanning for index annotations {@link Indexed}, {@link CompoundIndex} and {@link GeospatialIndex}. The given * {@literal root} has therefore to be annotated with {@link Document}. * * @param root must not be null. * @return List of {@link IndexDefinitionHolder}. Will never be {@code null}. * @throws IllegalArgumentException in case of missing {@link Document} annotation marking root entities. */ public List<IndexDefinitionHolder> resolveIndexForEntity(final MongoPersistentEntity<?> root) { Assert.notNull(root, "Index cannot be resolved for given 'null' entity."); Document document = root.findAnnotation(Document.class); Assert.notNull(document, "Given entity is not collection root."); final List<IndexDefinitionHolder> indexInformation = new ArrayList<>(); indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions("", root.getCollection(), root)); indexInformation.addAll(potentiallyCreateTextIndexDefinition(root)); root.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> this .potentiallyAddIndexForProperty(root, property, indexInformation, new CycleGuard())); indexInformation.addAll(resolveIndexesForDbrefs("", root.getCollection(), root)); return indexInformation; }
mappingContext.getRequiredPersistentEntity(targetType).doWithProperties( (SimplePropertyHandler) persistentProperty -> projectedFields.append(persistentProperty.getName(), 1));
final TextIndexIncludeOptions includeOptions, final CycleGuard guard) { entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
/** * Recursively resolve and inspect properties of given {@literal type} for indexes to be created. * * @param type * @param dotPath The {@literal "dot} path. * @param path {@link PersistentProperty} path for cycle detection. * @param collection * @param guard * @return List of {@link IndexDefinitionHolder} representing indexes for given type and its referenced property * types. Will never be {@code null}. */ private List<IndexDefinitionHolder> resolveIndexForClass(final TypeInformation<?> type, final String dotPath, final Path path, final String collection, final CycleGuard guard) { MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(type); final List<IndexDefinitionHolder> indexInformation = new ArrayList<>(); indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions(dotPath, collection, entity)); entity.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> this .guradAndPotentiallyAddIndexForProperty(property, dotPath, path, collection, indexInformation, guard)); indexInformation.addAll(resolveIndexesForDbrefs(dotPath, collection, entity)); return indexInformation; }
private String getMappedPropertyPath(String path, Class<?> probeType) { MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(probeType); Iterator<String> parts = Arrays.asList(path.split("\\.")).iterator(); final Stack<MongoPersistentProperty> stack = new Stack<>(); List<String> resultParts = new ArrayList<>(); while (parts.hasNext()) { String part = parts.next(); MongoPersistentProperty prop = entity.getPersistentProperty(part); if (prop == null) { entity.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> { if (property.getFieldName().equals(part)) { stack.push(property); } }); if (stack.isEmpty()) { return ""; } prop = stack.pop(); } resultParts.add(prop.getName()); if (prop.isEntity() && mappingContext.hasPersistentEntityFor(prop.getActualType())) { entity = mappingContext.getRequiredPersistentEntity(prop.getActualType()); } else { break; } } return StringUtils.collectionToDelimitedString(resultParts, "."); }
/** * Resolve the {@link IndexDefinition}s for given {@literal root} entity by traversing {@link MongoPersistentProperty} * scanning for index annotations {@link Indexed}, {@link CompoundIndex} and {@link GeospatialIndex}. The given * {@literal root} has therefore to be annotated with {@link Document}. * * @param root must not be null. * @return List of {@link IndexDefinitionHolder}. Will never be {@code null}. * @throws IllegalArgumentException in case of missing {@link Document} annotation marking root entities. */ public List<IndexDefinitionHolder> resolveIndexForEntity(final MongoPersistentEntity<?> root) { Assert.notNull(root, "Index cannot be resolved for given 'null' entity."); Document document = root.findAnnotation(Document.class); Assert.notNull(document, "Given entity is not collection root."); final List<IndexDefinitionHolder> indexInformation = new ArrayList<>(); indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions("", root.getCollection(), root)); indexInformation.addAll(potentiallyCreateTextIndexDefinition(root)); root.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> this .potentiallyAddIndexForProperty(root, property, indexInformation, new CycleGuard())); indexInformation.addAll(resolveIndexesForDbrefs("", root.getCollection(), root)); return indexInformation; }
mappingContext.getRequiredPersistentEntity(targetType).doWithProperties( (SimplePropertyHandler) persistentProperty -> projectedFields.append(persistentProperty.getName(), 1));
public void doWithProperties(SimplePropertyHandler handler) { delegate.doWithProperties(handler); }
public void doWithProperties(PropertyHandler<MongoPersistentProperty> handler) { delegate.doWithProperties(handler); }
@Override public void partialUpdate(T t) { ID id = getEntityInformation().getId(t); if (null == id) { throw new IllegalArgumentException("ID property should not be null"); } Update update = new Update(); final MongoPersistentEntity<?> persistentEntity = mongoOperations .getConverter().getMappingContext().getPersistentEntity(getEntityInformation().getJavaType()); persistentEntity.doWithProperties((PropertyHandler<MongoPersistentProperty>) persistentProperty -> { if (!persistentEntity.isIdProperty(persistentProperty)) { Object value = Accessible.on(t).field(persistentProperty.getField()).getValue(); if (null != value) { update.set(persistentProperty.getFieldName(), value); } } }); WriteResult writeResult = mongoOperations .updateFirst(query(where(persistentEntity.getIdProperty().getFieldName()).is(id)), update, getEntityInformation().getCollectionName()); if (1 != writeResult.getN()) { throw new IncorrectResultSizeDataAccessException(1, writeResult.getN()); } }