private Object[] convertScriptArgs(boolean quote, Object... args) { if (ObjectUtils.isEmpty(args)) { return args; } List<Object> convertedValues = new ArrayList<Object>(args.length); for (Object arg : args) { convertedValues.add(arg instanceof String && quote ? String.format("'%s'", arg) : this.mongoOperations.getConverter().convertToMongoType(arg)); } return convertedValues.toArray(); }
/** * Creates a new {@link MongoRepositoryFactory} with the given {@link MongoOperations}. * * @param mongoOperations must not be {@literal null}. */ public MongoRepositoryFactory(MongoOperations mongoOperations) { Assert.notNull(mongoOperations, "MongoOperations must not be null!"); this.operations = mongoOperations; this.mappingContext = mongoOperations.getConverter().getMappingContext(); }
/** * Creates a new {@link SpringDataMongodbQuery} to query the given collection. * * @param operations must not be {@literal null}. * @param type must not be {@literal null}. * @param collectionName must not be {@literal null} or empty. */ public SpringDataMongodbQuery(final MongoOperations operations, final Class<? extends T> type, String collectionName) { super(new SpringDataMongodbSerializer(operations.getConverter()), type, collectionName, operations); } }
/** * Creates a new {@link QuerydslRepositorySupport} for the given {@link MongoOperations}. * * @param operations must not be {@literal null}. */ public QuerydslRepositorySupport(MongoOperations operations) { Assert.notNull(operations, "MongoOperations must not be null!"); this.template = operations; this.context = operations.getConverter().getMappingContext(); }
/** * Creates a new {@link DefaultIndexOperations}. * * @param mongoOperations must not be {@literal null}. * @param collectionName must not be {@literal null} or empty. * @param type can be {@literal null}. * @since 2.1 */ public DefaultIndexOperations(MongoOperations mongoOperations, String collectionName, @Nullable Class<?> type) { Assert.notNull(mongoOperations, "MongoOperations must not be null!"); Assert.hasText(collectionName, "Collection name must not be null or empty!"); this.mongoOperations = mongoOperations; this.mapper = new QueryMapper(mongoOperations.getConverter()); this.collectionName = collectionName; this.type = type; }
@Override public BulkOperations insert(Object document) { Assert.notNull(document, "Document must not be null!"); if (document instanceof Document) { models.add(new InsertOneModel<>((Document) document)); return this; } Document sink = new Document(); mongoOperations.getConverter().write(document, sink); models.add(new InsertOneModel<>(sink)); return this; }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Assert.state(operations != null, "MongoTemplate must not be null!"); if (!mappingContextConfigured) { setMappingContext(operations.getConverter().getMappingContext()); } } }
/** * Creates a new {@link QuerydslMongoPredicateExecutor} for the given {@link MongoEntityInformation}, * {@link MongoOperations} and {@link EntityPathResolver}. * * @param entityInformation must not be {@literal null}. * @param mongoOperations must not be {@literal null}. * @param resolver must not be {@literal null}. */ public QuerydslMongoPredicateExecutor(MongoEntityInformation<T, ?> entityInformation, MongoOperations mongoOperations, EntityPathResolver resolver) { super(mongoOperations.getConverter(), pathBuilderFor(resolver.createPath(entityInformation.getJavaType())), entityInformation); this.mongoOperations = mongoOperations; }
/** * Creates a new {@link PartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}. * * @param method must not be {@literal null}. * @param mongoOperations must not be {@literal null}. */ public PartTreeMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations) { super(method, mongoOperations); this.processor = method.getResultProcessor(); this.tree = new PartTree(method.getName(), processor.getReturnedType().getDomainType()); this.isGeoNearQuery = method.isGeoNearQuery(); this.context = mongoOperations.getConverter().getMappingContext(); }
@Override public Object execute(Object[] parameters) { ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(operations.getConverter(), new MongoParametersParameterAccessor(method, parameters)); Query query = createQuery(accessor); applyQueryMetaAttributesWhenPresent(query); query = applyAnnotatedDefaultSortIfPresent(query); ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor); Class<?> typeToRead = processor.getReturnedType().getTypeToRead(); FindWithQuery<?> find = typeToRead == null // ? executableFind // : executableFind.as(typeToRead); MongoQueryExecution execution = getExecution(accessor, find); return processor.processResult(execution.execute(query)); }
private Object[] convertScriptArgs(boolean quote, Object... args) { if (ObjectUtils.isEmpty(args)) { return args; } List<Object> convertedValues = new ArrayList<Object>(args.length); for (Object arg : args) { convertedValues.add(arg instanceof String && quote ? String.format("'%s'", arg) : this.mongoOperations.getConverter().convertToMongoType(arg)); } return convertedValues.toArray(); }
/** * Creates a new {@link SpringDataMongodbQuery} to query the given collection. * * @param operations must not be {@literal null}. * @param type must not be {@literal null}. * @param collectionName must not be {@literal null} or empty. */ public SpringDataMongodbQuery(final MongoOperations operations, final Class<? extends T> type, String collectionName) { super(new SpringDataMongodbSerializer(operations.getConverter()), type, collectionName, operations); } }
/** * Creates a new {@link QuerydslRepositorySupport} for the given {@link MongoOperations}. * * @param operations must not be {@literal null}. */ public QuerydslRepositorySupport(MongoOperations operations) { Assert.notNull(operations, "MongoOperations must not be null!"); this.template = operations; this.context = operations.getConverter().getMappingContext(); }
/** * Creates a new {@link MongoRepositoryFactory} with the given {@link MongoOperations}. * * @param mongoOperations must not be {@literal null}. */ public MongoRepositoryFactory(MongoOperations mongoOperations) { Assert.notNull(mongoOperations, "MongoOperations must not be null!"); this.operations = mongoOperations; this.mappingContext = mongoOperations.getConverter().getMappingContext(); }
/** * Creates a new {@link DefaultIndexOperations}. * * @param mongoOperations must not be {@literal null}. * @param collectionName must not be {@literal null} or empty. * @param type can be {@literal null}. * @since 2.1 */ public DefaultIndexOperations(MongoOperations mongoOperations, String collectionName, @Nullable Class<?> type) { Assert.notNull(mongoOperations, "MongoOperations must not be null!"); Assert.hasText(collectionName, "Collection name must not be null or empty!"); this.mongoOperations = mongoOperations; this.mapper = new QueryMapper(mongoOperations.getConverter()); this.collectionName = collectionName; this.type = type; }
@Override public BulkOperations insert(Object document) { Assert.notNull(document, "Document must not be null!"); if (document instanceof Document) { models.add(new InsertOneModel<>((Document) document)); return this; } Document sink = new Document(); mongoOperations.getConverter().write(document, sink); models.add(new InsertOneModel<>(sink)); return this; }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Assert.state(operations != null, "MongoTemplate must not be null!"); if (!mappingContextConfigured) { setMappingContext(operations.getConverter().getMappingContext()); } } }
/** * Creates a new {@link PartTreeMongoQuery} from the given {@link QueryMethod} and {@link MongoTemplate}. * * @param method must not be {@literal null}. * @param mongoOperations must not be {@literal null}. */ public PartTreeMongoQuery(MongoQueryMethod method, MongoOperations mongoOperations) { super(method, mongoOperations); this.processor = method.getResultProcessor(); this.tree = new PartTree(method.getName(), processor.getReturnedType().getDomainType()); this.isGeoNearQuery = method.isGeoNearQuery(); this.context = mongoOperations.getConverter().getMappingContext(); }
@Override public Object execute(Object[] parameters) { ConvertingParameterAccessor accessor = new ConvertingParameterAccessor(operations.getConverter(), new MongoParametersParameterAccessor(method, parameters)); Query query = createQuery(accessor); applyQueryMetaAttributesWhenPresent(query); query = applyAnnotatedDefaultSortIfPresent(query); ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor); Class<?> typeToRead = processor.getReturnedType().getTypeToRead(); FindWithQuery<?> find = typeToRead == null // ? executableFind // : executableFind.as(typeToRead); MongoQueryExecution execution = getExecution(accessor, find); return processor.processResult(execution.execute(query)); }
ReportPortalRepositoryImpl(MongoEntityInformation<T, ID> metadata, MongoOperations mongoOperations) { super(metadata, mongoOperations); this.mongoEntityInformation = metadata; this.mongoOperations = mongoOperations; this.queryMapper = new QueryMapper(mongoOperations.getConverter()); }