@ -17,12 +17,16 @@ package org.springframework.data.mongodb.repository.support;
@@ -17,12 +17,16 @@ package org.springframework.data.mongodb.repository.support;
import static org.springframework.data.mongodb.core.query.Criteria.* ;
import reactor.core.publisher.Flux ;
import reactor.core.publisher.Mono ;
import java.io.Serializable ;
import java.util.Collection ;
import java.util.List ;
import java.util.stream.Collectors ;
import org.reactivestreams.Publisher ;
import org.springframework.dao.IncorrectResultSizeDataAccessException ;
import org.springframework.dao.OptimisticLockingFailureException ;
import org.springframework.data.domain.Example ;
@ -38,9 +42,6 @@ import org.springframework.util.Assert;
@@ -38,9 +42,6 @@ import org.springframework.util.Assert;
import com.mongodb.client.result.DeleteResult ;
import reactor.core.publisher.Flux ;
import reactor.core.publisher.Mono ;
/ * *
* Reactive repository base implementation for Mongo .
*
@ -66,52 +67,79 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
@@ -66,52 +67,79 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
this . mongoOperations = mongoOperations ;
}
// -------------------------------------------------------------------------
// Methods from ReactiveCrudRepository
// -------------------------------------------------------------------------
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # findById ( java . lang . Object )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # save ( java . lang . Object )
* /
@Override
public Mono < T > findById ( ID id ) {
public < S extends T > Mono < S > save ( S entity ) {
Assert . notNull ( id , "The given id must not be null!") ;
Assert . notNull ( entity , "Entity must not be null!") ;
return mongoOperations . findById ( id , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) ;
if ( entityInformation . isNew ( entity ) ) {
return mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) ;
}
return mongoOperations . save ( entity , entityInformation . getCollectionName ( ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # findById ( org . reactivestreams . Publisher )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # saveAll ( java . lang . Iterable )
* /
@Override
public Mono < T > findById ( Publisher < ID > publisher ) {
public < S extends T > Flux < S > saveAll ( Iterable < S > entities ) {
Assert . notNull ( publisher , "The given id must not be null!") ;
Assert . notNull ( entities , "The given Iterable of entities must not be null!") ;
return Mono . from ( publisher ) . flatMap (
id - > mongoOperations . findById ( id , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) ) ;
Streamable < S > source = Streamable . of ( entities ) ;
return source . stream ( ) . allMatch ( entityInformation : : isNew ) ? //
mongoOperations . insert ( source . stream ( ) . collect ( Collectors . toList ( ) ) , entityInformation . getCollectionName ( ) ) : //
Flux . fromIterable ( entities ) . flatMap ( this : : save ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . query . ReactiveQueryByExampleExecutor # findOne ( org . springframework . data . domain . Example )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # saveAll ( org . reactivestreams . Publisher )
* /
@Override
public < S extends T > Mono < S > findOne ( Example < S > example ) {
public < S extends T > Flux < S > saveAll ( Publisher < S > entityStream ) {
Assert . notNull ( example , "Sample must not be null!" ) ;
Assert . notNull ( entityStream , "The given Publisher of entities must not be null!" ) ;
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) //
. limit ( 2 ) ;
return Flux . from ( entityStream ) . flatMap ( entity - > entityInformation . isNew ( entity ) ? //
mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) . then ( Mono . just ( entity ) ) : //
mongoOperations . save ( entity , entityInformation . getCollectionName ( ) ) . then ( Mono . just ( entity ) ) ) ;
}
return mongoOperations . find ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) . buffer ( 2 )
. map ( vals - > {
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # findById ( java . lang . Object )
* /
@Override
public Mono < T > findById ( ID id ) {
if ( vals . size ( ) > 1 ) {
throw new IncorrectResultSizeDataAccessException ( 1 ) ;
}
return vals . iterator ( ) . next ( ) ;
} ) . next ( ) ;
Assert . notNull ( id , "The given id must not be null!" ) ;
return mongoOperations . findById ( id , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # findById ( org . reactivestreams . Publisher )
* /
@Override
public Mono < T > findById ( Publisher < ID > publisher ) {
Assert . notNull ( publisher , "The given id must not be null!" ) ;
return Mono . from ( publisher ) . flatMap (
id - > mongoOperations . findById ( id , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) ) ;
}
/ *
@ -138,22 +166,6 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
@@ -138,22 +166,6 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
return Mono . from ( publisher ) . flatMap ( id - > mongoOperations . exists ( getIdQuery ( id ) , entityInformation . getJavaType ( ) ,
entityInformation . getCollectionName ( ) ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . query . ReactiveQueryByExampleExecutor # exists ( org . springframework . data . domain . Example )
* /
@Override
public < S extends T > Mono < Boolean > exists ( Example < S > example ) {
Assert . notNull ( example , "Sample must not be null!" ) ;
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) ;
return mongoOperations . exists ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) ;
}
/ *
@ -174,8 +186,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
@@ -174,8 +186,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
Assert . notNull ( ids , "The given Iterable of Id's must not be null!" ) ;
return findAll ( new Query ( new Criteria ( entityInformation . getIdAttribute ( ) )
. in ( Streamable . of ( ids ) . stream ( ) . collect ( StreamUtils . toUnmodifiableList ( ) ) ) ) ) ;
return findAll ( getIdQuery ( ids ) ) ;
}
/ *
@ -192,265 +203,270 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
@@ -192,265 +203,270 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveSortingRepository # findAll ( org . springframework . data . domain . Sort )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # count ( )
* /
@Override
public Flux < T > findAll ( Sort sort ) {
Assert . notNull ( sort , "Sort must not be null!" ) ;
return findAll ( new Query ( ) . with ( sort ) ) ;
public Mono < Long > count ( ) {
return mongoOperations . count ( new Query ( ) , entityInformation . getCollectionName ( ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # findAll ( org . springframework . data . domain . Example , org . springframework . data . domain . Sor t)
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteById ( java . lang . Objec t)
* /
@Override
public < S extends T > Flux < S > findAll ( Example < S > example , Sort sort ) {
Assert . notNull ( example , "Sample must not be null!" ) ;
Assert . notNull ( sort , "Sort must not be null!" ) ;
public Mono < Void > deleteById ( ID id ) {
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) //
. with ( sort ) ;
Assert . notNull ( id , "The given id must not be null!" ) ;
return mongoOperations . find ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) ;
return mongoOperations
. remove ( getIdQuery ( id ) , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) . then ( ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # findAll ( org . springframework . data . domain . Example )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteById ( org . reactivestreams . Publisher )
* /
@Override
public < S extends T > Flux < S > findAll ( Example < S > exam ple) {
public Mono < Void > deleteById ( Publisher < ID > pub lish er ) {
Assert . notNull ( exam ple, "Example must not be null!" ) ;
Assert . notNull ( pub lish er , "Id must not be null!" ) ;
return findAll ( example , Sort . unsorted ( ) ) ;
return Mono . from ( publisher ) . flatMap ( id - > mongoOperations . remove ( getIdQuery ( id ) , entityInformation . getJavaType ( ) ,
entityInformation . getCollectionName ( ) ) ) . then ( ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # count ( )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # delete ( java . lang . Object )
* /
@Override
public Mono < Long > count ( ) {
return mongoOperations . count ( new Query ( ) , entityInformation . getCollectionName ( ) ) ;
}
public Mono < Void > delete ( T entity ) {
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . query . ReactiveQueryByExampleExecutor # count ( org . springframework . data . domain . Example )
* /
@Override
public < S extends T > Mono < Long > count ( Example < S > example ) {
Assert . notNull ( entity , "The given entity must not be null!" ) ;
Assert . notNull ( example , "Sample must not be null!" ) ;
Mono < DeleteResult > remove = mongoOperations . remove ( entity , entityInformation . getCollectionName ( ) ) ;
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) ;
if ( entityInformation . isVersioned ( ) ) {
return mongoOperations . count ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) ;
remove = remove . handle ( ( deleteResult , sink ) - > {
if ( deleteResult . wasAcknowledged ( ) & & deleteResult . getDeletedCount ( ) = = 0 ) {
sink . error ( new OptimisticLockingFailureException ( String . format (
"The entity with id %s with version %s in %s cannot be deleted! Was it modified or deleted in the meantime?" ,
entityInformation . getId ( entity ) , entityInformation . getVersion ( entity ) ,
entityInformation . getCollectionName ( ) ) ) ) ;
} else {
sink . next ( deleteResult ) ;
}
} ) ;
}
return remove . then ( ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # insert ( java . lang . Object )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteAllById ( java . lang . Iterable )
* /
@Override
public < S extends T > Mono < S > insert ( S entity ) {
public Mono < Void > deleteAllById ( Iterable < ? extends ID > ids ) {
Assert . notNull ( entity , "Entity must not be null!" ) ;
Assert . notNull ( ids , "The given Iterable of Id's must not be null!") ;
return mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) ;
return mongoOperations
. remove ( getIdQuery ( ids ) , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) . then ( ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # insert ( java . lang . Iterable )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteAll ( java . lang . Iterable )
* /
@Override
public < S extends T > Flux < S > insert ( Iterable < S > entities ) {
public Mono < Void > deleteAll ( Iterable < ? extends T > entities ) {
Assert . notNull ( entities , "The given Iterable of entities must not be null!" ) ;
List < S > source = Streamable . of ( entities ) . stream ( ) . collect ( StreamUtils . toUnmodifiableList ( ) ) ;
Collection < ? > idCollection = StreamUtils . createStreamFromIterator ( entities . iterator ( ) ) . map ( entityInformation : : getId )
. collect ( Collectors . toList ( ) ) ;
return source . isEmpty ( ) ? Flux . empty ( ) : Flux . from ( mongoOperations . insertAll ( source ) ) ;
Criteria idsInCriteria = where ( entityInformation . getIdAttribute ( ) ) . in ( idCollection ) ;
return mongoOperations
. remove ( new Query ( idsInCriteria ) , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) )
. then ( ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # insert ( org . reactivestreams . Publisher )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteAll ( org . reactivestreams . Publisher )
* /
@Override
public < S extends T > Flux < S > insert ( Publisher < S > entities ) {
public Mono < Void > deleteAll ( Publisher < ? extends T > entityStream ) {
Assert . notNull ( entities , "The given Publisher of entities must not be null!" ) ;
Assert . notNull ( entityStream , "The given Publisher of entities must not be null!" ) ;
return Flux . from ( entities ) . flatMap ( entity - > mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) ) ;
return Flux . from ( entityStream ) //
. map ( entityInformation : : getRequiredId ) //
. flatMap ( this : : deleteById ) //
. then ( ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # save ( java . lang . Object )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteAll ( )
* /
@Override
public < S extends T > Mono < S > save ( S entity ) {
Assert . notNull ( entity , "Entity must not be null!" ) ;
if ( entityInformation . isNew ( entity ) ) {
return mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) ;
}
return mongoOperations . save ( entity , entityInformation . getCollectionName ( ) ) ;
public Mono < Void > deleteAll ( ) {
return mongoOperations . remove ( new Query ( ) , entityInformation . getCollectionName ( ) ) . then ( Mono . empty ( ) ) ;
}
// -------------------------------------------------------------------------
// Methods from ReactiveSortingRepository
// -------------------------------------------------------------------------
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # saveAll ( java . lang . Iterable )
* @see org . springframework . data . repository . reactive . ReactiveSortingRepository # findAll ( org . springframework . data . domain . Sort )
* /
@Override
public < S extends T > Flux < S > saveAll ( Iterable < S > entities ) {
Assert . notNull ( entities , "The given Iterable of entities must not be null!" ) ;
public Flux < T > findAll ( Sort sort ) {
Streamable < S > source = Streamable . of ( entities ) ;
Assert . notNull ( sort , "Sort must not be null!" ) ;
return source . stream ( ) . allMatch ( entityInformation : : isNew ) ? //
mongoOperations . insert ( source . stream ( ) . collect ( Collectors . toList ( ) ) , entityInformation . getCollectionName ( ) ) : //
Flux . fromIterable ( entities ) . flatMap ( this : : save ) ;
return findAll ( new Query ( ) . with ( sort ) ) ;
}
// -------------------------------------------------------------------------
// Methods from ReactiveMongoRepository
// -------------------------------------------------------------------------
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # saveAll ( org . reactivestreams . Publisher )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # insert ( java . lang . Object )
* /
@Override
public < S extends T > Flux < S > saveAll ( Publisher < S > entityStream ) {
public < S extends T > Mono < S > insert ( S entity ) {
Assert . notNull ( entityStream , "The given Publisher of entities must not be null!" ) ;
Assert . notNull ( entity , "Entity must not be null!" ) ;
return Flux . from ( entityStream ) . flatMap ( entity - > entityInformation . isNew ( entity ) ? //
mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) . then ( Mono . just ( entity ) ) : //
mongoOperations . save ( entity , entityInformation . getCollectionName ( ) ) . then ( Mono . just ( entity ) ) ) ;
return mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteById ( java . lang . Object )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # insert ( java . lang . Iterable )
* /
@Override
public Mono < Void > deleteById ( ID id ) {
public < S extends T > Flux < S > insert ( Iterable < S > entities ) {
Assert . notNull ( id , "The given id must not be null!") ;
Assert . notNull ( entities , "The given Iterable of entities must not be null!") ;
return mongoOperations
. remove ( getIdQuery ( id ) , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) . then ( ) ;
List < S > source = Streamable . of ( entities ) . stream ( ) . collect ( StreamUtils . toUnmodifiableList ( ) ) ;
return source . isEmpty ( ) ? Flux . empty ( ) : Flux . from ( mongoOperations . insertAll ( source ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteById ( org . reactivestreams . Publisher )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # insert ( org . reactivestreams . Publisher )
* /
@Override
public Mono < Void > deleteById ( Publisher < ID > publisher ) {
public < S extends T > Flux < S > insert ( Publisher < S > entities ) {
Assert . notNull ( publisher , "Id must not be null!") ;
Assert . notNull ( entities , "The given Publisher of entities must not be null!") ;
return Mono . from ( publisher ) . flatMap ( id - > mongoOperations . remove ( getIdQuery ( id ) , entityInformation . getJavaType ( ) ,
entityInformation . getCollectionName ( ) ) ) . then ( ) ;
return Flux . from ( entities ) . flatMap ( entity - > mongoOperations . insert ( entity , entityInformation . getCollectionName ( ) ) ) ;
}
// -------------------------------------------------------------------------
// Methods from ReactiveMongoRepository
// -------------------------------------------------------------------------
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # delete ( java . lang . Object )
* @see org . springframework . data . repository . query . ReactiveQueryByExampleExecutor # findOne ( org . springframework . data . domain . Example )
* /
@Override
public Mono < Void > delete ( T entity ) {
Assert . notNull ( entity , "The given entity must not be null!" ) ;
Mono < DeleteResult > remove = mongoOperations . remove ( entity , entityInformation . getCollectionName ( ) ) ;
public < S extends T > Mono < S > findOne ( Example < S > example ) {
if ( entityInformation . isVersioned ( ) ) {
Assert . notNull ( example , "Sample must not be null!" ) ;
remove = remove . handle ( ( deleteResult , sink ) - > {
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) //
. limit ( 2 ) ;
if ( deleteResult . wasAcknowledged ( ) & & deleteResult . getDeletedCount ( ) = = 0 ) {
sink . error ( new OptimisticLockingFailureException ( String . format (
"The entity with id %s with version %s in %s cannot be deleted! Was it modified or deleted in the meantime?" ,
entityInformation . getId ( entity ) , entityInformation . getVersion ( entity ) ,
entityInformation . getCollectionName ( ) ) ) ) ;
} else {
sink . next ( deleteResult ) ;
}
} ) ;
}
return mongoOperations . find ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) . buffer ( 2 )
. map ( vals - > {
return remove . then ( ) ;
if ( vals . size ( ) > 1 ) {
throw new IncorrectResultSizeDataAccessException ( 1 ) ;
}
return vals . iterator ( ) . next ( ) ;
} ) . next ( ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrud Repository# delete All ( java . lang . Iterab le)
* @see org . springframework . data . mongodb . repository . ReactiveMongo Repository# fin dAll( org . springframework . data . domain . Examp le)
* /
@Override
public Mono < Void > deleteAll ( Iterable < ? extends T > entities ) {
Assert . notNull ( entities , "The given Iterable of entities must not be null!" ) ;
Collection < ? > idCollection = StreamUtils . createStreamFromIterator ( entities . iterator ( ) )
. map ( entityInformation : : getId )
. collect ( Collectors . toList ( ) ) ;
public < S extends T > Flux < S > findAll ( Example < S > example ) {
Criteria idsInCriteria = where ( entityInformation . getIdAttribute ( ) ) . in ( idCollection ) ;
Assert . notNull ( example , "Example must not be null!" ) ;
return mongoOperations
. remove ( new Query ( idsInCriteria ) , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) )
. then ( ) ;
return findAll ( example , Sort . unsorted ( ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . mongodb . repository . ReactiveMongoRepository # findAll ( org . springframework . data . domain . Example , org . springframework . data . domain . Sort )
* /
@Override
public Mono < Void > deleteAllById ( Iterable < ? extends ID > ids ) {
public < S extends T > Flux < S > findAll ( Example < S > example , Sort sort ) {
Assert . notNull ( ids , "The given Iterable of ids must not be null!" ) ;
Assert . notNull ( example , "Sample must not be null!" ) ;
Assert . notNull ( sort , "Sort must not be null!" ) ;
Collection < ? > idCollection = StreamUtils . createStreamFromIterator ( ids . iterator ( ) ) . collect ( Collectors . toList ( ) ) ;
Criteria idsInCriteria = where ( entityInformation . getIdAttribute ( ) ) . in ( idCollection ) ;
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) //
. with ( sort ) ;
return mongoOperations
. remove ( new Query ( idsInCriteria ) , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) )
. then ( ) ;
return mongoOperations . find ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteAll ( org . reactivestreams . Publisher )
* @see org . springframework . data . repository . query . ReactiveQueryByExampleExecutor # count ( org . springframework . data . domain . Example )
* /
@Override
public Mono < Void > deleteAll ( Publisher < ? extends T > entityStream ) {
public < S extends T > Mono < Long > count ( Example < S > example ) {
Assert . notNull ( entityStream , "The given Publisher of entities must not be null!" ) ;
Assert . notNull ( example , "Sample must not be null!" ) ;
return Flux . from ( entityStream ) //
. map ( entityInformation : : getRequiredId ) //
. flatMap ( this : : deleteById ) //
. then ( ) ;
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) ;
return mongoOperations . count ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) ;
}
/ *
* ( non - Javadoc )
* @see org . springframework . data . repository . reactive . ReactiveCrudRepository # deleteAll ( )
* @see org . springframework . data . repository . query . ReactiveQueryByExampleExecutor # exists ( org . springframework . data . domain . Example )
* /
@Override
public Mono < Void > deleteAll ( ) {
return mongoOperations . remove ( new Query ( ) , entityInformation . getCollectionName ( ) ) . then ( Mono . empty ( ) ) ;
public < S extends T > Mono < Boolean > exists ( Example < S > example ) {
Assert . notNull ( example , "Sample must not be null!" ) ;
Query query = new Query ( new Criteria ( ) . alike ( example ) ) //
. collation ( entityInformation . getCollation ( ) ) ;
return mongoOperations . exists ( query , example . getProbeType ( ) , entityInformation . getCollectionName ( ) ) ;
}
private Query getIdQuery ( Object id ) {
return new Query ( getIdCriteria ( id ) ) ;
}
@ -459,6 +475,13 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
@@ -459,6 +475,13 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
return where ( entityInformation . getIdAttribute ( ) ) . is ( id ) ;
}
private Query getIdQuery ( Iterable < ? extends ID > ids ) {
Collection < ? > idCollection = StreamUtils . createStreamFromIterator ( ids . iterator ( ) ) . collect ( Collectors . toList ( ) ) ;
Criteria idsInCriteria = where ( entityInformation . getIdAttribute ( ) ) . in ( idCollection ) ;
return new Query ( idsInCriteria ) ;
}
private Flux < T > findAll ( Query query ) {
return mongoOperations . find ( query , entityInformation . getJavaType ( ) , entityInformation . getCollectionName ( ) ) ;