org.springframework.data.mongodb.core.ReactiveMongoOperations Java Examples

The following examples show how to use org.springframework.data.mongodb.core.ReactiveMongoOperations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebfluxDemo.java    From spring-five-functional-reactive with Apache License 2.0 6 votes vote down vote up
/**
 * Application runner to initialize a capped collection for {@link Event}s and insert a new {@link Event} every two
 * seconds.
 * 
 * @param operations
 * @param reactiveOperations
 * @return
 */
@Bean
ApplicationRunner onStart(MongoOperations operations, ReactiveMongoOperations reactiveOperations) {

	return args -> {

		CollectionOptions options = CollectionOptions.empty() //
				.capped() //
				.size(2048) //
				.maxDocuments(1000);

		operations.dropCollection(Event.class);
		operations.createCollection(Event.class, options);

		Flux.interval(Duration.ofSeconds(2)) //
				.map(counter -> new Event(LocalDateTime.now())) //
				.flatMap(reactiveOperations::save) //
				.log() //
				.subscribe();
	};
}
 
Example #2
Source File: WarnLogsCounter.java    From tutorials with MIT License 5 votes vote down vote up
public WarnLogsCounter(ReactiveMongoOperations template) {
    Flux<Log> stream = template.tail(query(where(LEVEL_FIELD_NAME).is(LogLevel.WARN)), Log.class);
    subscription = stream.subscribe(logEntity -> {
      log.warn("WARN log received: " + logEntity);
      counter.incrementAndGet();
    });
}
 
Example #3
Source File: ReactiveAggregateMongoQuery.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link AbstractMongoQuery} from the given {@link MongoQueryMethod} and {@link MongoOperations}.
 *
 * @param method must not be {@literal null}.
 * @param projectionFactory - the projection factory
 */
@Autowired
public ReactiveAggregateMongoQuery(Method method, RepositoryMetadata metadata, ReactiveMongoOperations mongoOperations,
                                   ProjectionFactory projectionFactory, MongoQueryExecutor queryExecutor) {
  super(new ReactiveMongoQueryMethod(method, metadata, projectionFactory,
                                     mongoOperations.getConverter().getMappingContext()),
        mongoOperations,
        new SpelExpressionParser(),
        CONTEXT_PROVIDER);
  this.mongoOperations = mongoOperations;
  this.method = method;
  this.queryExecutor = queryExecutor;
}
 
Example #4
Source File: MongodbProcessorConfiguration.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
public MongodbProcessorConfiguration(
	MongodbProcessorProperties properties,
	ReactiveMongoOperations mongoTemplate,
	BeanFactory beanFactory
) {
	this.properties = properties;
	this.mongoTemplate = mongoTemplate;
	this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(beanFactory);
}
 
Example #5
Source File: ReactiveAggregateQuerySupportingRepositoryFactory.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link MongoRepositoryFactory} with the given {@link MongoOperations}.
 *
 * @param mongoOperations must not be {@literal null}
 * @param queryExecutor - the query executor
 */
public ReactiveAggregateQuerySupportingRepositoryFactory(ReactiveMongoOperations mongoOperations,
                                                         MongoQueryExecutor queryExecutor) {
  super(mongoOperations);
  this.mongoOperations = mongoOperations;
  this.queryExecutor = queryExecutor;
}
 
Example #6
Source File: ReactiveAggregateQuerySupportingRepositoryFactoryBean.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
@Override
protected RepositoryFactorySupport getFactoryInstance(ReactiveMongoOperations operations) {
  Assert.notNull(queryExecutor, "Query executor cannot be null");
  return new ReactiveAggregateQuerySupportingRepositoryFactory(operations, queryExecutor);
}
 
Example #7
Source File: ReactiveTransitionService.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
Mono<Process> start(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.ACTIVE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}
 
Example #8
Source File: ReactiveTransitionService.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
private Mono<Process> finish(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.DONE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}
 
Example #9
Source File: ReactiveManagedTransitionService.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
Mono<Process> start(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.ACTIVE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}
 
Example #10
Source File: ReactiveManagedTransitionService.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
private Mono<Process> finish(ReactiveMongoOperations operations, Process process) {

		return operations.update(Process.class).matching(Query.query(Criteria.where("id").is(process.getId())))
				.apply(Update.update("state", State.DONE).inc("transitionCount", 1)).first() //
				.then(Mono.just(process));
	}
 
Example #11
Source File: ReactiveMongoDbTestConfiguration.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
@Bean
public MongoQueryExecutor queryExecutor(ReactiveMongoOperations mongoOperations) {
  return new ReactiveMongoNativeJavaDriverQueryExecutor(mongoOperations);
}
 
Example #12
Source File: ReactiveMongoDbTestConfiguration.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
@Bean
public ReactiveMongoOperations reactiveMongoOperations(MongoClient mongoClient, String dbName) {
  return new ReactiveMongoTemplate(mongoClient, dbName);
}
 
Example #13
Source File: ReactiveMongoNativeJavaDriverQueryExecutor.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
private void initialize(ReactiveMongoOperations mongoOperations) {
  Document result = mongoOperations.executeCommand("{buildinfo:1}").block();
  this.isMongo360OrLater = ((String)result.get("version")).startsWith(MONGO_V3_6_VERSION);
}
 
Example #14
Source File: ReactiveMongoNativeJavaDriverQueryExecutor.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
public ReactiveMongoNativeJavaDriverQueryExecutor(ReactiveMongoOperations mongoOperations, ObjectMapper objectMapper) {
  super(mongoOperations, objectMapper);
  initialize(mongoOperations);
}
 
Example #15
Source File: ReactiveMongoNativeJavaDriverQueryExecutor.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
public ReactiveMongoNativeJavaDriverQueryExecutor(ReactiveMongoOperations mongoOperations) {
  super(mongoOperations);
  initialize(mongoOperations);
}
 
Example #16
Source File: DataInitializer.java    From spring-reactive-sample with GNU General Public License v3.0 4 votes vote down vote up
public DataInitializer(ReactiveMongoOperations mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
}
 
Example #17
Source File: DefaultUserRepository.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 4 votes vote down vote up
@Autowired
DefaultUserRepository(ReactiveMongoOperations mongoOperations) {
    this.mongoOperations = mongoOperations;
}