public String getCollectionName() { return customCollectionName == null ? entityMetadata.getCollection() : customCollectionName; }
public String getCollectionName() { return collectionEntity.getCollection(); } }
/** * Returns a copy of the {@link ObjectPath} with the given {@link Object} as current object. * * @param object must not be {@literal null}. * @param entity must not be {@literal null}. * @param id must not be {@literal null}. * @return new instance of {@link ObjectPath}. */ ObjectPath push(Object object, MongoPersistentEntity<?> entity, @Nullable Object id) { Assert.notNull(object, "Object must not be null!"); Assert.notNull(entity, "MongoPersistentEntity must not be null!"); return new ObjectPath(this, object, id, entity.getCollection()); }
@Nullable private MongoPersistentEntity<?> lookupPersistentEntity(String collection) { Collection<? extends MongoPersistentEntity<?>> entities = queryMapper.getMappingContext().getPersistentEntities(); return entities.stream() // .filter(entity -> entity.getCollection().equals(collection)) // .findFirst() // .orElse(null); }
protected <T> Flux<T> doInsertAll(Collection<? extends T> listToSave, MongoWriter<Object> writer) { Map<String, List<T>> elementsByCollection = new HashMap<>(); listToSave.forEach(element -> { MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(element.getClass()); String collection = entity.getCollection(); List<T> collectionElements = elementsByCollection.computeIfAbsent(collection, k -> new ArrayList<>()); collectionElements.add(element); }); return Flux.fromIterable(elementsByCollection.keySet()) .flatMap(collectionName -> doInsertBatch(collectionName, elementsByCollection.get(collectionName), writer)); }
String determineCollectionName(@Nullable Class<?> entityClass) { if (entityClass == null) { throw new InvalidDataAccessApiUsageException( "No class parameter provided, entity collection can't be determined!"); } return mappingContext.getRequiredPersistentEntity(entityClass).getCollection(); }
public String determineCollectionName(@Nullable Class<?> entityClass) { if (entityClass == null) { throw new InvalidDataAccessApiUsageException( "No class parameter provided, entity collection can't be determined!"); } return context.getRequiredPersistentEntity(entityClass).getCollection(); }
@SuppressWarnings("unchecked") protected <T> Collection<T> doInsertAll(Collection<? extends T> listToSave, MongoWriter<T> writer) { Map<String, List<T>> elementsByCollection = new HashMap<>(); List<T> savedObjects = new ArrayList<>(listToSave.size()); for (T element : listToSave) { if (element == null) { continue; } MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(element.getClass()); String collection = entity.getCollection(); List<T> collectionElements = elementsByCollection.get(collection); if (null == collectionElements) { collectionElements = new ArrayList<>(); elementsByCollection.put(collection, collectionElements); } collectionElements.add(element); } for (Map.Entry<String, List<T>> entry : elementsByCollection.entrySet()) { savedObjects.addAll((Collection<T>) doInsertBatch(entry.getKey(), entry.getValue(), this.mongoConverter)); } return savedObjects; }
/** * Creates a {@link DBRef} instance for the given {@link org.springframework.data.mongodb.core.mapping.DBRef} * annotation, {@link MongoPersistentEntity} and id. * * @param annotation will never be {@literal null}. * @param entity will never be {@literal null}. * @param id will never be {@literal null}. * @return */ default DBRef createDbRef(@Nullable org.springframework.data.mongodb.core.mapping.DBRef annotation, MongoPersistentEntity<?> entity, Object id) { if (annotation != null && StringUtils.hasText(annotation.db())) { return new DBRef(annotation.db(), entity.getCollection(), id); } return new DBRef(entity.getCollection(), id); }
/** * Returns a {@link SpringDataMongodbQuery} for the given {@link EntityPath}. The collection being queried is derived from the * entity metadata. * * @param path * @return */ protected <T> SpringDataMongodbQuery<T> from(final EntityPath<T> path) { Assert.notNull(path, "EntityPath must not be null!"); MongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(path.getType()); return from(path, entity.getCollection()); }
@Nullable private MongoPersistentEntity<?> lookupPersistentEntity(@Nullable Class<?> entityType, String collection) { if (entityType != null) { return mapper.getMappingContext().getRequiredPersistentEntity(entityType); } Collection<? extends MongoPersistentEntity<?>> entities = mapper.getMappingContext().getPersistentEntities(); for (MongoPersistentEntity<?> entity : entities) { if (entity.getCollection().equals(collection)) { return entity; } } return null; }
private Mono<Void> checkForAndCreateIndexes(MongoPersistentEntity<?> entity) { List<Mono<?>> publishers = new ArrayList<>(); if (entity.isAnnotationPresent(Document.class)) { for (IndexDefinition indexDefinition : indexResolver.resolveIndexFor(entity.getTypeInformation())) { IndexDefinitionHolder indexToCreate = indexDefinition instanceof IndexDefinitionHolder ? (IndexDefinitionHolder) indexDefinition : new IndexDefinitionHolder("", indexDefinition, entity.getCollection()); publishers.add(createIndex(indexToCreate)); } } return publishers.isEmpty() ? Mono.empty() : Flux.merge(publishers).then(); }
/** * 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; }
private void checkForAndCreateIndexes(MongoPersistentEntity<?> entity) { if (entity.isAnnotationPresent(Document.class)) { for (IndexDefinition indexDefinition : indexResolver.resolveIndexFor(entity.getTypeInformation())) { JustOnceLogger.logWarnIndexCreationConfigurationChange(this.getClass().getName()); IndexDefinitionHolder indexToCreate = indexDefinition instanceof IndexDefinitionHolder ? (IndexDefinitionHolder) indexDefinition : new IndexDefinitionHolder("", indexDefinition, entity.getCollection()); createIndex(indexToCreate); } } }
private void potentiallyAddIndexForProperty(MongoPersistentEntity<?> root, MongoPersistentProperty persistentProperty, List<IndexDefinitionHolder> indexes, CycleGuard guard) { try { if (persistentProperty.isEntity()) { indexes.addAll(resolveIndexForClass(persistentProperty.getTypeInformation().getActualType(), persistentProperty.getFieldName(), Path.of(persistentProperty), root.getCollection(), guard)); } IndexDefinitionHolder indexDefinitionHolder = createIndexDefinitionHolderForProperty( persistentProperty.getFieldName(), root.getCollection(), persistentProperty); if (indexDefinitionHolder != null) { indexes.add(indexDefinitionHolder); } } catch (CyclicPropertyReferenceException e) { LOGGER.info(e.getMessage()); } }
IndexDefinitionHolder holder = new IndexDefinitionHolder("", indexDefinition, root.getCollection()); return Collections.singletonList(holder);
public String getCollectionName() { return collectionEntity.getCollection(); } }
String determineCollectionName(@Nullable Class<?> entityClass) { if (entityClass == null) { throw new InvalidDataAccessApiUsageException( "No class parameter provided, entity collection can't be determined!"); } return mappingContext.getRequiredPersistentEntity(entityClass).getCollection(); }
public String determineCollectionName(@Nullable Class<?> entityClass) { if (entityClass == null) { throw new InvalidDataAccessApiUsageException( "No class parameter provided, entity collection can't be determined!"); } return context.getRequiredPersistentEntity(entityClass).getCollection(); }
protected <T> Flux<T> doInsertAll(Collection<? extends T> listToSave, MongoWriter<Object> writer) { Map<String, List<T>> elementsByCollection = new HashMap<>(); listToSave.forEach(element -> { MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(element.getClass()); String collection = entity.getCollection(); List<T> collectionElements = elementsByCollection.computeIfAbsent(collection, k -> new ArrayList<>()); collectionElements.add(element); }); return Flux.fromIterable(elementsByCollection.keySet()) .flatMap(collectionName -> doInsertBatch(collectionName, elementsByCollection.get(collectionName), writer)); }