forked from jhipster/generator-jhipster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntityRepository_reactive.java.ejs
191 lines (154 loc) · 8.27 KB
/
EntityRepository_reactive.java.ejs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<%#
Copyright 2013-2021 the original author or authors from the JHipster project.
This file is part of the JHipster project, see https://www.jhipster.tech/
for more information.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-%>
package <%= packageName %>.repository;
import <%= packageName %>.domain.<%= persistClass %>;
<%_ if (databaseTypeCassandra) { _%>
import org.springframework.data.cassandra.repository.ReactiveCassandraRepository;
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
import <%= packageName %>.repository.search.SearchCouchbaseRepository;
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
import com.couchbase.client.java.query.QueryScanConsistency;
import org.springframework.data.domain.Sort;
import org.springframework.data.couchbase.repository.Query;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.data.couchbase.repository.ScanConsistency;
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
<%_ } _%>
<%_ if (!paginationNo || relationshipsContainEagerLoad || databaseTypeSql) { _%>
import org.springframework.data.domain.Pageable;
<%_ } _%>
<%_ if (databaseTypeSql) { _%>
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.data.relational.core.query.Criteria;
<%_ } _%>
<%_ if (databaseTypeMongodb) { _%>
<%_ if (relationshipsContainEagerLoad) { _%>
import org.springframework.data.mongodb.repository.Query;
<%_ } _%>
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
<%_ } _%>
import org.springframework.stereotype.Repository;
<%_ if (databaseTypeCouchbase || databaseTypeSql || !paginationNo || relationshipsContainEagerLoad) { _%>
import reactor.core.publisher.Flux;
<%_ } _%>
<%_ if (relationshipsContainEagerLoad || databaseTypeSql) { _%>
import reactor.core.publisher.Mono;
<%_ } _%>
<%_ if (primaryKey.typeUUID) { _%>
import java.util.UUID;
<%_ } _%>
/**
* Spring Data <%= officialDatabaseType %> reactive repository for the <%= persistClass %> entity.
*/
@SuppressWarnings("unused")
@Repository
public interface <%= entityClass %>Repository extends <% if (databaseTypeSql) { %>R2dbc<% } if (databaseTypeMongodb) { %>ReactiveMongo<% } if (databaseTypeCouchbase) { %>ReactiveN1qlCouchbase<% } if (databaseTypeNeo4j) { %>ReactiveNeo4j<% } if (databaseTypeCassandra) { %>ReactiveCassandra<% } %>Repository<<%= persistClass %>, <%= primaryKey.type %>><% if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= persistClass %>, <%= primaryKey.type %>><% } %><% if (databaseTypeSql) { %>, <%= entityClass %>RepositoryInternal<% } %> {
<%_ if (!paginationNo) { _%>
Flux<<%= persistClass %>> findAllBy(Pageable pageable);
<%_ } _%>
<%_ if (relationshipsContainEagerLoad) { _%>
<%_ if (databaseTypeCouchbase || databaseTypeMongodb) { _%>
@Query("<%= (databaseTypeMongodb) ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
<% if (databaseTypeCouchbase) { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Flux<<%= persistClass %>> findAllWithEagerRelationships(Pageable pageable);
@Query("<%= (databaseTypeMongodb) ? '{}' : '#{#n1ql.selectEntity} WHERE #{#n1ql.filter}' %>")
<% if (databaseTypeCouchbase) { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Flux<<%= persistClass %>> findAllWithEagerRelationships();
@Query("<%- (databaseTypeMongodb) ? "{'id': ?0}" : "#{#n1ql.selectEntity} USE KEYS $1 WHERE #{#n1ql.filter}" %>")
<% if (databaseTypeCouchbase) { %>@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)<% } %>
Mono<<%= persistClass %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_ } _%>
<%_ if (databaseTypeNeo4j) { _%>
@Query("MATCH (n:<%= persistClass %>)<-[]-(m) RETURN n,m")
Flux<<%= persistClass %>> findAllWithEagerRelationships(Pageable pageable);
@Query("MATCH (n:<%= persistClass %>)<-[]-(m) RETURN n,m")
Flux<<%= persistClass %>> findAllWithEagerRelationships();
@Query("MATCH (e:<%= persistClass %> {id: $id}) RETURN e")
Mono<<%= persistClass %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
<%_ } _%>
<%_ } _%>
<%_ if (databaseTypeCouchbase) { _%>
// Add ScanConsistency to fix issue with Spring Data Couchbase
// https://github.com/spring-projects/spring-data-couchbase/issues/897
@Override
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Flux<<%= asEntity(entityClass) %>> findAll();
@Override
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Flux<<%= asEntity(entityClass) %>> findAll(Sort sort);
<%_ } _%>
<%_ if (databaseTypeSql) {
if (fieldsContainOwnerManyToMany) { _%>
@Override
Mono<<%= persistClass %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
@Override
Flux<<%= persistClass %>> findAllWithEagerRelationships();
@Override
Flux<<%= persistClass %>> findAllWithEagerRelationships(Pageable page);
@Override
Mono<Void> deleteById(Long id);
<%_ } _%>
<%_
for (const relationship of relationships) {
let relationshipName = relationship.relationshipName;
let ownerSide = relationship.ownerSide;
if (relationship.relationshipManyToOne || (relationship.relationshipOneToOne && ownerSide)) { _%>
@Query("SELECT * FROM <%= entityTableName %> entity WHERE entity.<%= getColumnName(relationshipName) %>_id = :id")
Flux<<%= persistClass %>> findBy<%= relationship.relationshipNameCapitalized %>(<%= primaryKey.type %> id);
@Query("SELECT * FROM <%= entityTableName %> entity WHERE entity.<%= getColumnName(relationshipName) %>_id IS NULL")
Flux<<%= persistClass %>> findAllWhere<%= relationship.relationshipNameCapitalized %>IsNull();
<%_ } else if (relationship.shouldWriteJoinTable) { _%>
@Query("SELECT entity.* FROM <%= entityTableName %> entity JOIN <%= relationship.joinTable.name %> joinTable ON entity.id = joinTable.<%= getColumnName(name) %>_id WHERE joinTable.<%= getColumnName(relationshipName) %>_id = :id")
Flux<<%= persistClass %>> findBy<%= relationship.relationshipNameCapitalized %>(<%= primaryKey.type %> id);
<%_ } else if (relationship.relationshipOneToOne && !ownerSide) {
let otherEntityRelationshipName = relationship.otherEntityRelationshipName;
let otherEntityTableName = relationship.otherEntityTableName;
_%>
@Query("SELECT * FROM <%= entityTableName %> entity WHERE entity.id not in (select <%= getColumnName(otherEntityRelationshipName) %>_id from <%= otherEntityTableName %>)")
Flux<<%= persistClass %>> findAllWhere<%= relationship.relationshipNameCapitalized %>IsNull();
<%_ } _%>
<%_ } _%>
// just to avoid having unambigous methods
@Override
Flux<<%= persistClass %>> findAll();
@Override
Mono<<%= persistClass %>> findById(Long id);
@Override
<S extends <%= persistClass %>> Mono<S> save(S entity);
<%_ } _%>
}
<%_ if (databaseTypeSql) { _%>
interface <%= entityClass %>RepositoryInternal {
<S extends <%= persistClass %>> Mono<S> insert(S entity);
<S extends <%= persistClass %>> Mono<S> save(S entity);
Mono<Integer> update(<%= persistClass %> entity);
Flux<<%= persistClass %>> findAll();
Mono<<%= persistClass %>> findById(<%= primaryKey.type %> id);
Flux<<%= persistClass %>> findAllBy(Pageable pageable);
Flux<<%= persistClass %>> findAllBy(Pageable pageable, Criteria criteria);
<%_ if (fieldsContainOwnerManyToMany) { _%>
Mono<<%= persistClass %>> findOneWithEagerRelationships(<%= primaryKey.type %> id);
Flux<<%= persistClass %>> findAllWithEagerRelationships();
Flux<<%= persistClass %>> findAllWithEagerRelationships(Pageable page);
Mono<Void> deleteById(Long id);
<%_ } _%>
}
<%_ } _%>