Skip to content

Commit d317b8a

Browse files
committed
DATACMNS-836 - Extract ReactiveStreams base interfaces.
1 parent f86466b commit d317b8a

File tree

4 files changed

+244
-3
lines changed

4 files changed

+244
-3
lines changed

src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626

2727
/**
2828
* Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
29-
* and uses Project Reactor types.
29+
* and uses Project Reactor types which are built on top of Reactive Streams.
3030
*
3131
* @author Mark Paluch
3232
* @see Mono
3333
* @see Flux
34+
* @see ReactiveStreamsCrudRepository
3435
*/
3536
@NoRepositoryBean
36-
public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repository<T, ID> {
37+
public interface ReactiveCrudRepository<T, ID extends Serializable> extends ReactiveStreamsCrudRepository<T, ID> {
3738

3839
/**
3940
* Saves a given entity. Use the returned instance for further operations as the save operation might have changed the

src/main/java/org/springframework/data/repository/reactive/ReactivePagingAndSortingRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @see Flux
3838
*/
3939
@NoRepositoryBean
40-
public interface ReactivePagingAndSortingRepository<T, ID extends Serializable> extends ReactiveCrudRepository<T, ID> {
40+
public interface ReactivePagingAndSortingRepository<T, ID extends Serializable> extends ReactiveStreamsPagingAndSortingRepository<T, ID> {
4141

4242
/*
4343
* (non-Javadoc)
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.repository.reactive;
17+
18+
import java.io.Serializable;
19+
20+
import org.reactivestreams.Publisher;
21+
import org.springframework.data.repository.NoRepositoryBean;
22+
import org.springframework.data.repository.Repository;
23+
24+
/**
25+
* Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
26+
* and uses Reactive Streams types.
27+
*
28+
* @author Mark Paluch
29+
* @see Publisher
30+
*/
31+
@NoRepositoryBean
32+
public interface ReactiveStreamsCrudRepository<T, ID extends Serializable> extends Repository<T, ID> {
33+
34+
/**
35+
* Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
36+
* entity instance completely.
37+
*
38+
* @param entity
39+
* @return the saved entity
40+
*/
41+
<S extends T> Publisher<S> save(S entity);
42+
43+
/**
44+
* Saves all given entities.
45+
*
46+
* @param entities must not be {@literal null}.
47+
* @return the saved entities
48+
* @throws IllegalArgumentException in case the given entity is {@literal null}.
49+
*/
50+
<S extends T> Publisher<S> save(Iterable<S> entities);
51+
52+
/**
53+
* Saves all given entities.
54+
*
55+
* @param entityStream must not be {@literal null}.
56+
* @return the saved entities
57+
* @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}.
58+
*/
59+
<S extends T> Publisher<S> save(Publisher<S> entityStream);
60+
61+
/**
62+
* Retrieves an entity by its id.
63+
*
64+
* @param id must not be {@literal null}.
65+
* @return the entity with the given id or {@literal null} if none found
66+
* @throws IllegalArgumentException if {@code id} is {@literal null}
67+
*/
68+
Publisher<T> findOne(ID id);
69+
70+
/**
71+
* Retrieves an entity by its id supplied by a {@link Publisher}.
72+
*
73+
* @param id must not be {@literal null}.
74+
* @return the entity with the given id or {@literal null} if none found
75+
* @throws IllegalArgumentException if {@code id} is {@literal null}
76+
*/
77+
Publisher<T> findOne(Publisher<ID> id);
78+
79+
/**
80+
* Returns whether an entity with the given id exists.
81+
*
82+
* @param id must not be {@literal null}.
83+
* @return true if an entity with the given id exists, {@literal false} otherwise
84+
* @throws IllegalArgumentException if {@code id} is {@literal null}
85+
*/
86+
Publisher<Boolean> exists(ID id);
87+
88+
/**
89+
* Returns whether an entity with the given id exists supplied by a {@link Publisher}.
90+
*
91+
* @param id must not be {@literal null}.
92+
* @return true if an entity with the given id exists, {@literal false} otherwise
93+
* @throws IllegalArgumentException if {@code id} is {@literal null}
94+
*/
95+
Publisher<Boolean> exists(Publisher<ID> id);
96+
97+
/**
98+
* Returns all instances of the type.
99+
*
100+
* @return all entities
101+
*/
102+
Publisher<T> findAll();
103+
104+
/**
105+
* Returns all instances of the type with the given IDs.
106+
*
107+
* @param ids
108+
* @return
109+
*/
110+
Publisher<T> findAll(Iterable<ID> ids);
111+
112+
/**
113+
* Returns all instances of the type with the given IDs.
114+
*
115+
* @param idStream
116+
* @return
117+
*/
118+
Publisher<T> findAll(Publisher<ID> idStream);
119+
120+
/**
121+
* Returns the number of entities available.
122+
*
123+
* @return the number of entities
124+
*/
125+
Publisher<Long> count();
126+
127+
/**
128+
* Deletes the entity with the given id.
129+
*
130+
* @param id must not be {@literal null}.
131+
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}
132+
*/
133+
Publisher<Void> delete(ID id);
134+
135+
/**
136+
* Deletes a given entity.
137+
*
138+
* @param entity
139+
* @throws IllegalArgumentException in case the given entity is {@literal null}.
140+
*/
141+
Publisher<Void> delete(T entity);
142+
143+
/**
144+
* Deletes the given entities.
145+
*
146+
* @param entities
147+
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
148+
*/
149+
Publisher<Void> delete(Iterable<? extends T> entities);
150+
151+
/**
152+
* Deletes the given entities.
153+
*
154+
* @param entityStream
155+
* @throws IllegalArgumentException in case the given {@link Publisher} is {@literal null}.
156+
*/
157+
Publisher<Void> delete(Publisher<? extends T> entityStream);
158+
159+
/**
160+
* Deletes all entities managed by the repository.
161+
*/
162+
Publisher<Void> deleteAll();
163+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.repository.reactive;
17+
18+
import java.io.Serializable;
19+
20+
import org.reactivestreams.Publisher;
21+
import org.springframework.data.domain.Page;
22+
import org.springframework.data.domain.Pageable;
23+
import org.springframework.data.domain.Sort;
24+
import org.springframework.data.repository.NoRepositoryBean;
25+
26+
import reactor.core.publisher.Flux;
27+
import reactor.core.publisher.Mono;
28+
29+
/**
30+
* Extension of {@link ReactiveStreamsCrudRepository} to provide additional methods to retrieve entities using the pagination
31+
* and sorting abstraction.
32+
*
33+
* @author Mark Paluch
34+
* @see Sort
35+
* @see Pageable
36+
* @see Publisher
37+
*/
38+
@NoRepositoryBean
39+
public interface ReactiveStreamsPagingAndSortingRepository<T, ID extends Serializable> extends ReactiveStreamsCrudRepository<T, ID> {
40+
41+
/*
42+
* (non-Javadoc)
43+
* @see org.springframework.data.repository.reactive.ReactiveStreamsCrudRepository#findAll()
44+
*/
45+
@Override
46+
Publisher<T> findAll();
47+
48+
/*
49+
* (non-Javadoc)
50+
* @see org.springframework.data.repository.reactive.ReactiveStreamsCrudRepository#findAll(java.lang.Iterable)
51+
*/
52+
@Override
53+
Publisher<T> findAll(Iterable<ID> ids);
54+
55+
/*
56+
* (non-Javadoc)
57+
* @see org.springframework.data.repository.reactive.ReactiveStreamsCrudRepository#findAll(org.reactivestreams.Publisher)
58+
*/
59+
@Override
60+
Publisher<T> findAll(Publisher<ID> idStream);
61+
62+
/**
63+
* Returns all entities sorted by the given options.
64+
*
65+
* @param sort
66+
* @return all entities sorted by the given options
67+
*/
68+
Publisher<T> findAll(Sort sort);
69+
70+
/**
71+
* Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
72+
*
73+
* @param pageable
74+
* @return a page of entities
75+
*/
76+
Publisher<Page<T>> findAll(Pageable pageable);
77+
}

0 commit comments

Comments
 (0)