1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| package com.example.r2dbc;
import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.r2dbc.convert.R2dbcConverter; import org.springframework.data.r2dbc.core.R2dbcEntityOperations; import org.springframework.data.r2dbc.repository.support.SimpleR2dbcRepository; import org.springframework.data.relational.core.query.Criteria; import org.springframework.data.relational.core.query.Query; import org.springframework.data.relational.repository.query.RelationalEntityInformation; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono;
import java.io.Serializable;
@Slf4j public class SimpleBaseR2dbcRepository<T, ID extends Serializable> extends SimpleR2dbcRepository<T, ID> implements BaseR2dbcRepository<T, ID> {
private final R2dbcEntityOperations r2dbcEntityOperations;
private final RelationalEntityInformation<T, ID> entity;
public SimpleBaseR2dbcRepository(RelationalEntityInformation<T, ID> entity, R2dbcEntityOperations entityOperations, R2dbcConverter converter) { super(entity, entityOperations, converter); this.r2dbcEntityOperations = entityOperations; this.entity = entity; log.info("SimpleBaseR2dbcRepository"); }
@Override public R2dbcEntityOperations getR2dbcEntityOperations() { return r2dbcEntityOperations; }
@Override public Mono<Page<T>> pageByQuery(Criteria criteria, Pageable pageable) { final Query query = Query.query(criteria); return r2dbcEntityOperations.count(query, entity.getJavaType()).flatMap(total -> r2dbcEntityOperations.select(query.with(pageable), entity.getJavaType()) .collectList() .map(list -> new PageImpl<>(list, pageable, total))); }
@Override public Mono<Long> countByQuery(Criteria criteria) { final Query query = Query.query(criteria); return r2dbcEntityOperations.count(query, entity.getJavaType()); }
@Override public Flux<T> findByQuery(Criteria criteria) { final Query query = Query.query(criteria); return r2dbcEntityOperations.select(query, entity.getJavaType()); }
@Override public Flux<T> findByQuery(Criteria criteria, Sort sort) { final Query query = Query.query(criteria).sort(sort); return r2dbcEntityOperations.select(query, entity.getJavaType()); }
@Override public Flux<T> findByQuery(Criteria criteria, int limit) { final Query query = Query.query(criteria).limit(limit); return r2dbcEntityOperations.select(query, entity.getJavaType()); }
@Override public Flux<T> findByQuery(Criteria criteria, Sort sort, int limit) { final Query query = Query.query(criteria).sort(sort).limit(limit); return r2dbcEntityOperations.select(query, entity.getJavaType()); }
@Override public Flux<T> findByQuery(Query query) { return r2dbcEntityOperations.select(query, entity.getJavaType()); }
@Override public Mono<T> findOneByQuery(Query query) { return r2dbcEntityOperations.selectOne(query, entity.getJavaType()); }
@Override public Mono<T> findOneByQuery(Criteria criteria) { final Query query = Query.query(criteria); return r2dbcEntityOperations.selectOne(query, entity.getJavaType()); } }
|