Skip to content

Commit f86466b

Browse files
committed
DATACMNS-836 - Add Repository interfaces for RxJava.
1 parent 12a65a8 commit f86466b

File tree

5 files changed

+261
-2
lines changed

5 files changed

+261
-2
lines changed

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@
104104
<optional>true</optional>
105105
</dependency>
106106

107+
<!-- RxJava -->
108+
109+
<dependency>
110+
<groupId>io.reactivex</groupId>
111+
<artifactId>rxjava</artifactId>
112+
<version>${rxjava}</version>
113+
<optional>true</optional>
114+
</dependency>
115+
107116
<!-- Querydsl -->
108117

109118
<dependency>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
import reactor.core.publisher.Mono;
2626

2727
/**
28-
* Interface for generic CRUD operations on a repository for a specific type.
28+
* Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
29+
* and uses Project Reactor types.
2930
*
3031
* @author Mark Paluch
32+
* @see Mono
33+
* @see Flux
3134
*/
3235
@NoRepositoryBean
3336
public interface ReactiveCrudRepository<T, ID extends Serializable> extends Repository<T, ID> {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
* @author Mark Paluch
3434
* @see Sort
3535
* @see Pageable
36-
* @see org.springframework.data.domain.reactive.ReactivePage
36+
* @see Mono
37+
* @see Flux
3738
*/
3839
@NoRepositoryBean
3940
public interface ReactivePagingAndSortingRepository<T, ID extends Serializable> extends ReactiveCrudRepository<T, ID> {
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
import rx.Observable;
25+
import rx.Single;
26+
27+
/**
28+
* Interface for generic CRUD operations on a repository for a specific type. This repository follows reactive paradigms
29+
* and uses RxJava types.
30+
*
31+
* @author Mark Paluch
32+
* @see Single
33+
* @see Observable
34+
*/
35+
@NoRepositoryBean
36+
public interface RxJavaCrudRepository<T, ID extends Serializable> extends Repository<T, ID> {
37+
38+
/**
39+
* Saves a given entity. Use the returned instance for further operations as the save operation might have changed the
40+
* entity instance completely.
41+
*
42+
* @param entity
43+
* @return the saved entity
44+
*/
45+
<S extends T> Single<S> save(S entity);
46+
47+
/**
48+
* Saves all given entities.
49+
*
50+
* @param entities must not be {@literal null}.
51+
* @return the saved entities
52+
* @throws IllegalArgumentException in case the given entity is {@literal null}.
53+
*/
54+
<S extends T> Observable<S> save(Iterable<S> entities);
55+
56+
/**
57+
* Saves all given entities.
58+
*
59+
* @param entityStream must not be {@literal null}.
60+
* @return the saved entities
61+
* @throws IllegalArgumentException in case the given {@code Publisher} is {@literal null}.
62+
*/
63+
<S extends T> Observable<S> save(Publisher<S> entityStream);
64+
65+
/**
66+
* Retrieves an entity by its id.
67+
*
68+
* @param id must not be {@literal null}.
69+
* @return the entity with the given id or {@literal null} if none found
70+
* @throws IllegalArgumentException if {@code id} is {@literal null}
71+
*/
72+
Single<T> findOne(ID id);
73+
74+
/**
75+
* Retrieves an entity by its id supplied by a {@link Single}.
76+
*
77+
* @param id must not be {@literal null}.
78+
* @return the entity with the given id or {@literal null} if none found
79+
* @throws IllegalArgumentException if {@code id} is {@literal null}
80+
*/
81+
Single<T> findOne(Single<ID> id);
82+
83+
/**
84+
* Returns whether an entity with the given id exists.
85+
*
86+
* @param id must not be {@literal null}.
87+
* @return true if an entity with the given id exists, {@literal false} otherwise
88+
* @throws IllegalArgumentException if {@code id} is {@literal null}
89+
*/
90+
Single<Boolean> exists(ID id);
91+
92+
/**
93+
* Returns whether an entity with the given id exists supplied by a {@link Single}.
94+
*
95+
* @param id must not be {@literal null}.
96+
* @return true if an entity with the given id exists, {@literal false} otherwise
97+
* @throws IllegalArgumentException if {@code id} is {@literal null}
98+
*/
99+
Single<Boolean> exists(Single<ID> id);
100+
101+
/**
102+
* Returns all instances of the type.
103+
*
104+
* @return all entities
105+
*/
106+
Observable<T> findAll();
107+
108+
/**
109+
* Returns all instances of the type with the given IDs.
110+
*
111+
* @param ids
112+
* @return
113+
*/
114+
Observable<T> findAll(Iterable<ID> ids);
115+
116+
/**
117+
* Returns all instances of the type with the given IDs.
118+
*
119+
* @param idStream
120+
* @return
121+
*/
122+
Observable<T> findAll(Publisher<ID> idStream);
123+
124+
/**
125+
* Returns the number of entities available.
126+
*
127+
* @return the number of entities
128+
*/
129+
Single<Long> count();
130+
131+
/**
132+
* Deletes the entity with the given id.
133+
*
134+
* @param id must not be {@literal null}.
135+
* @throws IllegalArgumentException in case the given {@code id} is {@literal null}
136+
*/
137+
Single<Void> delete(ID id);
138+
139+
/**
140+
* Deletes a given entity.
141+
*
142+
* @param entity
143+
* @throws IllegalArgumentException in case the given entity is {@literal null}.
144+
*/
145+
Single<Void> delete(T entity);
146+
147+
/**
148+
* Deletes the given entities.
149+
*
150+
* @param entities
151+
* @throws IllegalArgumentException in case the given {@link Iterable} is {@literal null}.
152+
*/
153+
Single<Void> delete(Iterable<? extends T> entities);
154+
155+
/**
156+
* Deletes the given entities.
157+
*
158+
* @param entityStream
159+
* @throws IllegalArgumentException in case the given {@link Publisher} is {@literal null}.
160+
*/
161+
Single<Void> delete(Publisher<? extends T> entityStream);
162+
163+
/**
164+
* Deletes all entities managed by the repository.
165+
*/
166+
Single<Void> deleteAll();
167+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 rx.Observable;
27+
import rx.Single;
28+
29+
/**
30+
* Extension of {@link RxJavaCrudRepository} to provide additional methods to retrieve entities using the pagination and sorting
31+
* abstraction.
32+
*
33+
* @author Mark Paluch
34+
* @see Sort
35+
* @see Pageable
36+
* @see Single
37+
* @see Observable
38+
* @see RxJavaCrudRepository
39+
*/
40+
@NoRepositoryBean
41+
public interface RxJavaPagingAndSortingRepository<T, ID extends Serializable> extends RxJavaCrudRepository<T, ID> {
42+
43+
/*
44+
* (non-Javadoc)
45+
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAll()
46+
*/
47+
@Override
48+
Observable<T> findAll();
49+
50+
/*
51+
* (non-Javadoc)
52+
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAll(java.lang.Iterable)
53+
*/
54+
@Override
55+
Observable<T> findAll(Iterable<ID> ids);
56+
57+
/*
58+
* (non-Javadoc)
59+
* @see org.springframework.data.repository.reactive.ReactiveCrudRepository#findAll(org.reactivestreams.Publisher)
60+
*/
61+
@Override
62+
Observable<T> findAll(Publisher<ID> idStream);
63+
64+
/**
65+
* Returns all entities sorted by the given options.
66+
*
67+
* @param sort
68+
* @return all entities sorted by the given options
69+
*/
70+
Observable<T> findAll(Sort sort);
71+
72+
/**
73+
* Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
74+
*
75+
* @param pageable
76+
* @return a page of entities
77+
*/
78+
Single<Page<T>> findAll(Pageable pageable);
79+
}

0 commit comments

Comments
 (0)