15
15
*/
16
16
package org .springframework .data .jdbc .core ;
17
17
18
+ import java .util .Collections ;
18
19
import java .util .Optional ;
19
20
20
21
import org .springframework .context .ApplicationEventPublisher ;
@@ -122,6 +123,9 @@ public <T> T save(T instance) {
122
123
*/
123
124
@ Override
124
125
public long count (Class <?> domainType ) {
126
+
127
+ Assert .notNull (domainType , "Domain type must not be null" );
128
+
125
129
return accessStrategy .count (domainType );
126
130
}
127
131
@@ -132,6 +136,9 @@ public long count(Class<?> domainType) {
132
136
@ Override
133
137
public <T > T findById (Object id , Class <T > domainType ) {
134
138
139
+ Assert .notNull (id , "Id must not be null" );
140
+ Assert .notNull (domainType , "Domain type must not be null" );
141
+
135
142
T entity = accessStrategy .findById (id , domainType );
136
143
if (entity != null ) {
137
144
publishAfterLoad (id , entity );
@@ -145,6 +152,10 @@ public <T> T findById(Object id, Class<T> domainType) {
145
152
*/
146
153
@ Override
147
154
public <T > boolean existsById (Object id , Class <T > domainType ) {
155
+
156
+ Assert .notNull (id , "Id must not be null" );
157
+ Assert .notNull (domainType , "Domain type must not be null" );
158
+
148
159
return accessStrategy .existsById (id , domainType );
149
160
}
150
161
@@ -155,6 +166,8 @@ public <T> boolean existsById(Object id, Class<T> domainType) {
155
166
@ Override
156
167
public <T > Iterable <T > findAll (Class <T > domainType ) {
157
168
169
+ Assert .notNull (domainType , "Domain type must not be null" );
170
+
158
171
Iterable <T > all = accessStrategy .findAll (domainType );
159
172
publishAfterLoad (all );
160
173
return all ;
@@ -167,6 +180,13 @@ public <T> Iterable<T> findAll(Class<T> domainType) {
167
180
@ Override
168
181
public <T > Iterable <T > findAllById (Iterable <?> ids , Class <T > domainType ) {
169
182
183
+ Assert .notNull (ids , "Ids must not be null" );
184
+ Assert .notNull (domainType , "Domain type must not be null" );
185
+
186
+ if (!ids .iterator ().hasNext ()) {
187
+ return Collections .emptyList ();
188
+ }
189
+
170
190
Iterable <T > allById = accessStrategy .findAllById (ids , domainType );
171
191
publishAfterLoad (allById );
172
192
return allById ;
@@ -179,6 +199,9 @@ public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType) {
179
199
@ Override
180
200
public <S > void delete (S aggregateRoot , Class <S > domainType ) {
181
201
202
+ Assert .notNull (aggregateRoot , "Aggregate root must not be null" );
203
+ Assert .notNull (domainType , "Domain type must not be null" );
204
+
182
205
IdentifierAccessor identifierAccessor = context .getRequiredPersistentEntity (domainType )
183
206
.getIdentifierAccessor (aggregateRoot );
184
207
@@ -191,6 +214,10 @@ public <S> void delete(S aggregateRoot, Class<S> domainType) {
191
214
*/
192
215
@ Override
193
216
public <S > void deleteById (Object id , Class <S > domainType ) {
217
+
218
+ Assert .notNull (id , "Id must not be null" );
219
+ Assert .notNull (domainType , "Domain type must not be null" );
220
+
194
221
deleteTree (id , null , domainType );
195
222
}
196
223
@@ -201,6 +228,8 @@ public <S> void deleteById(Object id, Class<S> domainType) {
201
228
@ Override
202
229
public void deleteAll (Class <?> domainType ) {
203
230
231
+ Assert .notNull (domainType , "Domain type must not be null" );
232
+
204
233
AggregateChange <?> change = createDeletingChange (domainType );
205
234
change .executeWith (interpreter , context , converter );
206
235
}
0 commit comments