/** * Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractMongoQuery(MongoQueryMethod method, MongoOperations operations) { Assert.notNull(operations, "MongoOperations must not be null!"); Assert.notNull(method, "MongoQueryMethod must not be null!"); this.method = method; this.operations = operations; MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.executableFind = operations.query(type); }
@Override public Object execute(Query query) { String collectionName = method.getEntityInformation().getCollectionName(); Class<?> type = method.getEntityInformation().getJavaType(); if (method.isCollectionQuery()) { return operations.findAllAndRemove(query, type, collectionName); } DeleteResult writeResult = operations.remove(query, type, collectionName); return writeResult != null ? writeResult.getDeletedCount() : 0L; } }
public void onCreation(PartTreeMongoQuery query) { PartTree tree = query.getTree(); if (!tree.hasPredicate()) { return; } Index index = new Index(); index.named(query.getQueryMethod().getName()); Sort sort = tree.getSort(); for (Part part : tree.getParts()) { if (GEOSPATIAL_TYPES.contains(part.getType())) { return; } String property = part.getProperty().toDotPath(); Direction order = toDirection(sort, property); index.on(property, order); } // Add fixed sorting criteria to index if (sort.isSorted()) { for (Order order : sort) { index.on(order.getProperty(), order.getDirection()); } } MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation(); indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index); LOG.debug(String.format("Created %s!", index)); }
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); }
@Override public Object execute(Query query) { String collectionName = method.getEntityInformation().getCollectionName(); Class<?> type = method.getEntityInformation().getJavaType(); if (method.isCollectionQuery()) { return operations.findAllAndRemove(query, type, collectionName); } DeleteResult writeResult = operations.remove(query, type, collectionName); return writeResult != null ? writeResult.getDeletedCount() : 0L; } }
/** * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractReactiveMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations operations) { Assert.notNull(method, "MongoQueryMethod must not be null!"); Assert.notNull(operations, "ReactiveMongoOperations must not be null!"); this.method = method; this.operations = operations; this.instantiators = new EntityInstantiators(); MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.findOperationWithProjection = operations.query(type); }
public void onCreation(PartTreeMongoQuery query) { PartTree tree = query.getTree(); if (!tree.hasPredicate()) { return; } Index index = new Index(); index.named(query.getQueryMethod().getName()); Sort sort = tree.getSort(); for (Part part : tree.getParts()) { if (GEOSPATIAL_TYPES.contains(part.getType())) { return; } String property = part.getProperty().toDotPath(); Direction order = toDirection(sort, property); index.on(property, order); } // Add fixed sorting criteria to index if (sort.isSorted()) { for (Order order : sort) { index.on(order.getProperty(), order.getDirection()); } } MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation(); indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index); LOG.debug(String.format("Created %s!", index)); }
/** * Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractMongoQuery(MongoQueryMethod method, MongoOperations operations) { Assert.notNull(operations, "MongoOperations must not be null!"); Assert.notNull(method, "MongoQueryMethod must not be null!"); this.method = method; this.operations = operations; MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.executableFind = operations.query(type); }
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); }
/** * Creates a new {@link AbstractReactiveMongoQuery} from the given {@link MongoQueryMethod} and * {@link MongoOperations}. * * @param method must not be {@literal null}. * @param operations must not be {@literal null}. */ public AbstractReactiveMongoQuery(ReactiveMongoQueryMethod method, ReactiveMongoOperations operations) { Assert.notNull(method, "MongoQueryMethod must not be null!"); Assert.notNull(operations, "ReactiveMongoOperations must not be null!"); this.method = method; this.operations = operations; this.instantiators = new EntityInstantiators(); MongoEntityMetadata<?> metadata = method.getEntityInformation(); Class<?> type = metadata.getCollectionEntity().getType(); this.findOperationWithProjection = operations.query(type); }