/** * Creates a {@link Query} instance using the given {@link ConvertingParameterAccessor}. Will delegate to * {@link #createQuery(ConvertingParameterAccessor)} by default but allows customization of the count query to be * triggered. * * @param accessor must not be {@literal null}. * @return */ protected Query createCountQuery(ConvertingParameterAccessor accessor) { return applyQueryMetaAttributesWhenPresent(createQuery(accessor)); }
@SuppressWarnings("unchecked") private Object executeDeferred(Object[] parameters) { ReactiveMongoParameterAccessor parameterAccessor = new ReactiveMongoParameterAccessor(method, parameters); if (getQueryMethod().isCollectionQuery()) { return Flux.defer(() -> (Publisher<Object>) execute(parameterAccessor)); } return Mono.defer(() -> (Mono<Object>) execute(parameterAccessor)); }
public Object execute(Object[] parameters) { return method.hasReactiveWrapperParameter() ? executeDeferred(parameters) : execute(new MongoParametersParameterAccessor(method, parameters)); }
private ReactiveMongoQueryExecution getExecutionToWrap(MongoParameterAccessor accessor, FindWithQuery<?> operation) { if (isDeleteQuery()) { return new DeleteExecution(operations, method); } else if (method.isGeoNearQuery()) { return new GeoNearExecution(operations, accessor, method.getReturnType()); } else if (isTailable(method)) { return (q, t, c) -> operation.matching(q.with(accessor.getPageable())).tail(); } else if (method.isCollectionQuery()) { return (q, t, c) -> operation.matching(q.with(accessor.getPageable())).all(); } else if (isCountQuery()) { return (q, t, c) -> operation.matching(q).count(); } else if (isExistsQuery()) { return (q, t, c) -> operation.matching(q).exists(); } else { return (q, t, c) -> { TerminatingFind<?> find = operation.matching(q); if (isCountQuery()) { return find.count(); } return isLimiting() ? find.first() : find.one(); }; } }
private Object execute(MongoParameterAccessor parameterAccessor) { Query query = createQuery(new ConvertingParameterAccessor(operations.getConverter(), parameterAccessor)); applyQueryMetaAttributesWhenPresent(query); query = applyAnnotatedDefaultSortIfPresent(query); ResultProcessor processor = method.getResultProcessor().withDynamicProjection(parameterAccessor); Class<?> typeToRead = processor.getReturnedType().getTypeToRead(); FindWithQuery<?> find = typeToRead == null // ? findOperationWithProjection // : findOperationWithProjection.as(typeToRead); String collection = method.getEntityInformation().getCollectionName(); ReactiveMongoQueryExecution execution = getExecution(parameterAccessor, new ResultProcessingConverter(processor, operations, instantiators), find); return execution.execute(query, processor.getReturnedType().getDomainType(), collection); }
/** * Returns the execution instance to use. * * @param accessor must not be {@literal null}. * @param resultProcessing must not be {@literal null}. * @return */ private ReactiveMongoQueryExecution getExecution(MongoParameterAccessor accessor, Converter<Object, Object> resultProcessing, FindWithQuery<?> operation) { return new ResultProcessingExecution(getExecutionToWrap(accessor, operation), resultProcessing); }
private ReactiveMongoQueryExecution getExecutionToWrap(MongoParameterAccessor accessor, FindWithQuery<?> operation) { if (isDeleteQuery()) { return new DeleteExecution(operations, method); } else if (method.isGeoNearQuery()) { return new GeoNearExecution(operations, accessor, method.getReturnType()); } else if (isTailable(method)) { return (q, t, c) -> operation.matching(q.with(accessor.getPageable())).tail(); } else if (method.isCollectionQuery()) { return (q, t, c) -> operation.matching(q.with(accessor.getPageable())).all(); } else if (isCountQuery()) { return (q, t, c) -> operation.matching(q).count(); } else if (isExistsQuery()) { return (q, t, c) -> operation.matching(q).exists(); } else { return (q, t, c) -> { TerminatingFind<?> find = operation.matching(q); if (isCountQuery()) { return find.count(); } return isLimiting() ? find.first() : find.one(); }; } }
private Object execute(MongoParameterAccessor parameterAccessor) { Query query = createQuery(new ConvertingParameterAccessor(operations.getConverter(), parameterAccessor)); applyQueryMetaAttributesWhenPresent(query); query = applyAnnotatedDefaultSortIfPresent(query); ResultProcessor processor = method.getResultProcessor().withDynamicProjection(parameterAccessor); Class<?> typeToRead = processor.getReturnedType().getTypeToRead(); FindWithQuery<?> find = typeToRead == null // ? findOperationWithProjection // : findOperationWithProjection.as(typeToRead); String collection = method.getEntityInformation().getCollectionName(); ReactiveMongoQueryExecution execution = getExecution(parameterAccessor, new ResultProcessingConverter(processor, operations, instantiators), find); return execution.execute(query, processor.getReturnedType().getDomainType(), collection); }
/** * Returns the execution instance to use. * * @param accessor must not be {@literal null}. * @param resultProcessing must not be {@literal null}. * @return */ private ReactiveMongoQueryExecution getExecution(MongoParameterAccessor accessor, Converter<Object, Object> resultProcessing, FindWithQuery<?> operation) { return new ResultProcessingExecution(getExecutionToWrap(accessor, operation), resultProcessing); }
/** * Creates a {@link Query} instance using the given {@link ConvertingParameterAccessor}. Will delegate to * {@link #createQuery(ConvertingParameterAccessor)} by default but allows customization of the count query to be * triggered. * * @param accessor must not be {@literal null}. * @return */ protected Query createCountQuery(ConvertingParameterAccessor accessor) { return applyQueryMetaAttributesWhenPresent(createQuery(accessor)); }
@SuppressWarnings("unchecked") private Object executeDeferred(Object[] parameters) { ReactiveMongoParameterAccessor parameterAccessor = new ReactiveMongoParameterAccessor(method, parameters); if (getQueryMethod().isCollectionQuery()) { return Flux.defer(() -> (Publisher<Object>) execute(parameterAccessor)); } return Mono.defer(() -> (Mono<Object>) execute(parameterAccessor)); }
public Object execute(Object[] parameters) { return method.hasReactiveWrapperParameter() ? executeDeferred(parameters) : execute(new MongoParametersParameterAccessor(method, parameters)); }