0
votes

In the below code, the save to retrivedPrev and retrivedNext marked as //1 and //2 are not getting saved using Mongo reactive and control is only saving retrievedPortCall marked as //3. Pls suggest how can I achieve the same using Spring Webflux. If I use block(), I get Exception - block() is blocking which is not supported by thread reactor http-nio-2

public Mono<PortCall> updateByFindById(String gsisKey, PortCall portCall) {
    
    PortCall nextPort = portCallRepository.findById(portCall.getNextPortCall().getNextScheduleEntryKey()).toProcessor().block();

    PortCall prevPort = portCallRepository.findById(portCall.getPreviousPortCall().getPreviousScheduleEntryKey()).toProcessor().block();

    Mono<PortCall> prev = portCallRepository.findById(portCall.getPreviousPortCall()
            .getPreviousScheduleEntryKey()).flatMap(retrivedPrev -> {
                                    
                retrivedPrev.getNextPortCall().setNextScheduleEntryKey(nextPort.getGsisKey());
                retrivedPrev.getNextPortCall().setTerminalCode(nextPort.getSiteRkstCode());
                return portCallRepository.save(retrivedPrev);   //1
            });
    
     Mono<PortCall> next = portCallRepository.findById(portCall.getNextPortCall()
              .getNextScheduleEntryKey()).flatMap(retrivedNext->{
                
                 retrivedNext.getPreviousPortCall().setPreviousScheduleEntryKey(prevPort.getGsisKey());
                 retrivedNext.getPreviousPortCall().setTerminalCode(prevPort.getSiteRkstCode());
                return portCallRepository.save(retrivedNext);  //2
              });   
     
    return portCallRepository.findById(gsisKey)
            .flatMap(retrivedPortCall -> {
                    retrivedPortCall.setSiteCallStatus(SiteCallStatus.DELETED);
                    return portCallRepository.save(retrivedPortCall)  //3
                });
}
1
I can't see if you are using @Transactional annotation.Rafael Guillen
This is mongo Db , in mongo we dont use @Transactional, also one object is getting saved only other 2 are not getting savedPuneet
I think you are not subscribing to those reactive objects, son that's why they aren't doing anything. You could chain them all in the return statement.Rafael Guillen
@RafaelGuillen : how can I do that, can you please help?Puneet
This answer should help you...stackoverflow.com/questions/60836450/…Rafael Guillen

1 Answers

0
votes

Based on my last comment your code should look like this:

public Mono<PortCall> updateByFindById(String gsisKey, PortCall portCall) {
    
    PortCall nextPort = portCallRepository.findById(portCall.getNextPortCall().getNextScheduleEntryKey()).toProcessor().block();

    PortCall prevPort = portCallRepository.findById(portCall.getPreviousPortCall().getPreviousScheduleEntryKey()).toProcessor().block();

    Mono<PortCall> prev = portCallRepository.findById(portCall.getPreviousPortCall()
            .getPreviousScheduleEntryKey()).flatMap(retrivedPrev -> {
                                    
                retrivedPrev.getNextPortCall().setNextScheduleEntryKey(nextPort.getGsisKey());
                retrivedPrev.getNextPortCall().setTerminalCode(nextPort.getSiteRkstCode());
                return portCallRepository.save(retrivedPrev);   //1
            });
    
     Mono<PortCall> next = portCallRepository.findById(portCall.getNextPortCall()
              .getNextScheduleEntryKey()).flatMap(retrivedNext->{
                
                 retrivedNext.getPreviousPortCall().setPreviousScheduleEntryKey(prevPort.getGsisKey());
                 retrivedNext.getPreviousPortCall().setTerminalCode(prevPort.getSiteRkstCode());
                return portCallRepository.save(retrivedNext);  //2
              });   
     
    Mono<PortCall> gsis = portCallRepository.findById(gsisKey)
            .flatMap(retrivedPortCall -> {
                    retrivedPortCall.setSiteCallStatus(SiteCallStatus.DELETED);
                    return portCallRepository.save(retrivedPortCall)  //3
                });
    return Mono.zip(prev, next, gsis).map(value -> tuple.getT3());
}