Java Code Examples for org.springframework.data.mongodb.core.ReactiveMongoTemplate

The following examples show how to use org.springframework.data.mongodb.core.ReactiveMongoTemplate. These examples are extracted from open source projects. 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
@Bean
CommandLineRunner initData(ReactiveMongoTemplate reactiveMongoTemplate, BlogPostRepository blogPostRepository, ProjectRepository projectRepository) {
	return (p) -> {
		reactiveMongoTemplate.dropCollection(BlogPost.class).then(reactiveMongoTemplate.createCollection(
				BlogPost.class, CollectionOptions.empty().capped(104857600).size(104857600))).block();
		
		//blogPostRepository.deleteAll().block();
		blogPostRepository.save(new BlogPost("authorId1", "title1", "content1", "tagString1")).block();
		blogPostRepository.save(new BlogPost("authorId2", "title2", "content2", "tagString2")).block();
		blogPostRepository.save(new BlogPost("authorId3", "title3", "content3", "tagString3")).block();
		blogPostRepository.save(new BlogPost("authorId4", "title4", "content4", "tagString4")).block();

		projectRepository.deleteAll().block();
		projectRepository.save(new Project("name1", "repoUrl1", "siteUrl1", "category1", "description1")).block();
		projectRepository.save(new Project("name2", "repoUrl2", "siteUrl2", "category2", "description2")).block();
		projectRepository.save(new Project("name3", "repoUrl3", "siteUrl3", "category3", "description3")).block();
		projectRepository.save(new Project("name4", "repoUrl4", "siteUrl4", "category4", "description4")).block();
	};
}
 
Example 2
Source Project: FEBS-Cloud   Source File: PageableExecutionUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <FEBS> Flux<FEBS> getPages(Query query, QueryRequest request, Class<FEBS> clazz,
                                         ReactiveMongoTemplate template) {
    Sort sort = Sort.by("id").descending();
    if (StringUtils.isNotBlank(request.getField()) && StringUtils.isNotBlank(request.getOrder())) {
        sort = FebsConstant.ORDER_ASC.equals(request.getOrder()) ?
                Sort.by(request.getField()).ascending() :
                Sort.by(request.getField()).descending();
    }
    Pageable pageable = PageRequest.of(request.getPageNum(), request.getPageSize(), sort);
    return template.find(query.with(pageable), clazz);
}
 
Example 3
public HmlHandler(RsvpsKafkaProducer rsvpsKafkaProducer,
        ReactiveMongoTemplate mongoTemplate,
        DummyBusinessLogic dummyBusinessLogic) {
    this.rsvpsKafkaProducer = rsvpsKafkaProducer;
    this.mongoTemplate = mongoTemplate;
    this.dummyBusinessLogic = dummyBusinessLogic;
}
 
Example 4
Source Project: spring-fu   Source File: MongoReactiveDataInitializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(GenericApplicationContext context) {
	MongoReactiveDataAutoConfiguration configuration = new MongoReactiveDataAutoConfiguration();
	context.registerBean(MappingMongoConverter.class, () -> configuration.mappingMongoConverter(context.getBean(MongoMappingContext.class), context.getBean(MongoCustomConversions.class)));
	context.registerBean(SimpleReactiveMongoDatabaseFactory.class, () -> configuration.reactiveMongoDatabaseFactory(this.properties, context.getBean(MongoClient.class)));
	context.registerBean(ReactiveMongoTemplate.class, () -> configuration.reactiveMongoTemplate(context.getBean(ReactiveMongoDatabaseFactory.class), context.getBean(MongoConverter.class)));
}
 
Example 5
public TransactionalWalletService(
   ReactiveMongoTemplate mongoTemplate,
   WalletRepository walletRepository
) {
   super(walletRepository);
   this.mongoTemplate = mongoTemplate;
}
 
Example 6
@DisplayName("Reactive transactions for data transfer")
@Test
public void testReactiveTransactionalApproach(
   @Autowired WalletRepository walletRepository,
   @Autowired ReactiveMongoTemplate mongoTemplate
) {
   WalletService walletService = new TransactionalWalletService(mongoTemplate, walletRepository);
   Tuple2<Long, Long> expectedActual = simulateOperations(walletService);

   // Whe know that balance should be the same with transactions
   Assert.assertEquals(expectedActual.getT1(), expectedActual.getT2());
}
 
Example 7
Source Project: reactive-matchday   Source File: MatchDayWebApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationRunner initialize(final ReactiveMongoTemplate mongoTemplate) {
	return args -> {

		/*
		 * INSERT ALL THE NEEDED TEST DATA (will block)
		 */
		Data.initializeAllData(mongoTemplate);

		/*
		 * INITIALIZATION OF THE MATCH EVENT STREAM
		 */
		final MatchEventAgent matchEventAgent = new MatchEventAgent(mongoTemplate);
		final Flux<MatchEvent> matchEventStream = matchEventAgent.createAgentStream();
		// Subscribe and just let it run (forever)
		matchEventStream.subscribe();

		/*
		 * INITIALIZATION OF THE MATCH COMMENT STREAM
		 */
		final MatchCommentAgent matchCommentAgent = new MatchCommentAgent(mongoTemplate);
		final Flux<MatchComment> matchCommentStream = matchCommentAgent.createAgentStream();
		// Subscribe and just let it run (forever)
		matchCommentStream.subscribe();

	};
}
 
Example 8
public MatchEventInfoRepository(
        final PlayerInfoRepository playerInfoRepository,
        final ReactiveMongoTemplate mongoTemplate) {
    super();
    this.playerInfoRepository = playerInfoRepository;
    this.mongoTemplate = mongoTemplate;
}
 
Example 9
Source Project: tutorials   Source File: InfoLogsCounterManualTest.java    License: MIT License 5 votes vote down vote up
private void createCappedCollectionUsingReactiveMongoTemplate(ReactiveMongoTemplate reactiveMongoTemplate) {
    reactiveMongoTemplate.dropCollection(Log.class).block();
    reactiveMongoTemplate.createCollection(Log.class, CollectionOptions.empty()
      .maxDocuments(5)
      .size(1024 * 1024L)
      .capped()).block();
}
 
Example 10
Source Project: tutorials   Source File: WarnLogsCounterManualTest.java    License: MIT License 5 votes vote down vote up
private void createCappedCollectionUsingReactiveMongoTemplate(ReactiveMongoTemplate reactiveMongoTemplate) {
    reactiveMongoTemplate.dropCollection(Log.class).block();
    reactiveMongoTemplate.createCollection(Log.class, CollectionOptions.empty()
      .maxDocuments(5)
      .size(1024 * 1024L)
      .capped()).block();
}
 
Example 11
Source Project: FEBS-Cloud   Source File: BlackListServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example 12
Source Project: FEBS-Cloud   Source File: RateLimitLogServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example 13
Source Project: FEBS-Cloud   Source File: RouteUserServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example 14
Source Project: FEBS-Cloud   Source File: RouteLogServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example 15
Source Project: FEBS-Cloud   Source File: RateLimitRuleServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example 16
Source Project: FEBS-Cloud   Source File: BlockLogServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example 17
public RsvpController(ReactiveMongoTemplate mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
}
 
Example 18
Source Project: Spring-5.0-Cookbook   Source File: MongoConfig.java    License: MIT License 4 votes vote down vote up
@Bean		 
public ReactiveMongoTemplate reactiveMongoTemplate() {		    
	return new ReactiveMongoTemplate(mongoClient(), getDatabaseName());		 
}
 
Example 19
Source Project: ClusterDeviceControlPlatform   Source File: KyMongoConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
    return new ReactiveMongoTemplate(reactiveMongoClient(), getDatabaseName());
}
 
Example 20
@Bean
public ReactiveMongoOperations reactiveMongoOperations(MongoClient mongoClient, String dbName) {
  return new ReactiveMongoTemplate(mongoClient, dbName);
}
 
Example 21
Source Project: reactive-matchday   Source File: Data.java    License: Apache License 2.0 4 votes vote down vote up
public static void initializeAllData(final ReactiveMongoTemplate mongoTemplate) {
    
    /*
     *  Drop collections, then create them again
     */
    final Mono<Void> initializeCollections =
            mongoTemplate
                    .dropCollection(Team.class)
                    .then(mongoTemplate.dropCollection(Match.class))
                    .then(mongoTemplate.dropCollection(Player.class))
                    .then(mongoTemplate.dropCollection(MatchEvent.class))
                    .then(mongoTemplate.dropCollection(MatchComment.class))
                    .then(mongoTemplate.createCollection(Team.class))
                    .then(mongoTemplate.createCollection(Match.class))
                    .then(mongoTemplate.createCollection(Player.class))
                    .then(mongoTemplate.createCollection(
                            MatchEvent.class, CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
                    .then(mongoTemplate.createCollection(
                            MatchComment.class, CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
                    .then();

    /*
     * Add some test data to the collections: teams and players will come from the
     * utility Data class, but we will generate matches between teams randomly each
     * time the application starts (for the fun of it)
     */
    final Mono<Void> initializeData =
            mongoTemplate
                    // Insert all the teams into the corresponding collection and log
                    .insert(Data.TEAMS, Team.class)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    // Collect all inserted team codes and randomly shuffle the list
                    .map(Team::getCode).collectList().doOnNext(Collections::shuffle)
                    .flatMapMany(list -> Flux.fromIterable(list))
                    // Create groups of two teams and insert a new Match for them
                    .buffer(2).map(twoTeams -> new Match(twoTeams.get(0), twoTeams.get(1)))
                    .flatMap(mongoTemplate::insert)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    .concatMap(match -> mongoTemplate.insert(new MatchEvent(match.getId(), MatchEvent.Type.MATCH_START, null, null)))
                    // Finally insert the players into their corresponding collection
                    .thenMany(Flux.fromIterable(Data.PLAYERS))
                    .flatMap(mongoTemplate::insert)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    .then();


    /*
     * Perform the initialization, blocking (that's OK, we are bootstrapping a testing app)
     */
    initializeCollections.then(initializeData).block();
    
}
 
Example 22
Source Project: reactive-matchday   Source File: PlayerInfoRepository.java    License: Apache License 2.0 4 votes vote down vote up
public PlayerInfoRepository(final ReactiveMongoTemplate mongoTemplate) {
    super();
    this.mongoTemplate = mongoTemplate;
}
 
Example 23
Source Project: reactive-matchday   Source File: MatchInfoRepository.java    License: Apache License 2.0 4 votes vote down vote up
public MatchInfoRepository(final ReactiveMongoTemplate mongoTemplate) {
    super();
    this.mongoTemplate = mongoTemplate;
}
 
Example 24
Source Project: reactive-matchday   Source File: MatchEventAgent.java    License: Apache License 2.0 4 votes vote down vote up
public MatchEventAgent(final ReactiveMongoTemplate mongoTemplate) {
	super();
	this.random = new Random(System.currentTimeMillis());
	this.mongoTemplate = mongoTemplate;
}
 
Example 25
Source Project: reactive-matchday   Source File: MatchCommentAgent.java    License: Apache License 2.0 4 votes vote down vote up
public MatchCommentAgent(final ReactiveMongoTemplate mongoTemplate) {
	super();
	this.random = new Random(System.currentTimeMillis());
	this.mongoTemplate = mongoTemplate;
}
 
Example 26
public MongoDbRepository(ReactiveMongoTemplate mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
}
 
Example 27
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
    return new ReactiveMongoTemplate(reactiveMongoClient(), getDatabaseName());
}
 
Example 28
Source Project: tutorials   Source File: Spring5ReactiveApplication.java    License: MIT License 4 votes vote down vote up
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
    return new ReactiveMongoTemplate(mongoClient, "test");
}