22
22
import java .util .List ;
23
23
import java .util .Optional ;
24
24
25
- import org .jetbrains .annotations .NotNull ;
26
25
import org .springframework .data .cassandra .core .CassandraOperations ;
27
26
import org .springframework .data .cassandra .core .CassandraTemplate ;
28
27
import org .springframework .data .cassandra .core .InsertOptions ;
36
35
import org .springframework .data .mapping .context .AbstractMappingContext ;
37
36
import org .springframework .util .Assert ;
38
37
39
- import com .datastax .oss .driver .api .querybuilder .insert .Insert ;
40
-
41
38
/**
42
39
* Repository base implementation for Cassandra.
43
40
*
@@ -75,6 +72,10 @@ public SimpleCassandraRepository(CassandraEntityInformation<T, ID> metadata, Cas
75
72
this .mappingContext = operations .getConverter ().getMappingContext ();
76
73
}
77
74
75
+ // -------------------------------------------------------------------------
76
+ // Methods from CrudRepository
77
+ // -------------------------------------------------------------------------
78
+
78
79
/* (non-Javadoc)
79
80
* @see org.springframework.data.repository.CrudRepository#save(S)
80
81
*/
@@ -112,34 +113,6 @@ public <S extends T> List<S> saveAll(Iterable<S> entities) {
112
113
return result ;
113
114
}
114
115
115
- /* (non-Javadoc)
116
- * @see org.springframework.data.cassandra.repository.TypedIdCassandraRepository#insert(java.lang.Object)
117
- */
118
- @ Override
119
- public <S extends T > S insert (S entity ) {
120
-
121
- Assert .notNull (entity , "Entity must not be null" );
122
-
123
- return this .operations .insert (entity );
124
- }
125
-
126
- /* (non-Javadoc)
127
- * @see org.springframework.data.cassandra.repository.TypedIdCassandraRepository#insert(java.lang.Iterable)
128
- */
129
- @ Override
130
- public <S extends T > List <S > insert (Iterable <S > entities ) {
131
-
132
- Assert .notNull (entities , "The given Iterable of entities must not be null" );
133
-
134
- List <S > result = new ArrayList <>();
135
-
136
- for (S entity : entities ) {
137
- result .add (this .operations .insert (entity ));
138
- }
139
-
140
- return result ;
141
- }
142
-
143
116
/* (non-Javadoc)
144
117
* @see org.springframework.data.repository.CrudRepository#findById(java.lang.Object)
145
118
*/
@@ -166,14 +139,6 @@ public boolean existsById(ID id) {
166
139
return this .operations .exists (id , this .entityInformation .getJavaType ());
167
140
}
168
141
169
- /* (non-Javadoc)
170
- * @see org.springframework.data.repository.CrudRepository#count()
171
- */
172
- @ Override
173
- public long count () {
174
- return this .operations .count (this .entityInformation .getJavaType ());
175
- }
176
-
177
142
/* (non-Javadoc)
178
143
* @see org.springframework.data.repository.CrudRepository#findAll()
179
144
*/
@@ -198,14 +163,11 @@ public List<T> findAllById(Iterable<ID> ids) {
198
163
}
199
164
200
165
/* (non-Javadoc)
201
- * @see org.springframework.data.cassandra. repository.CassandraRepository#findAll(org.springframework.data.domain.Pageable )
166
+ * @see org.springframework.data.repository.CrudRepository#count( )
202
167
*/
203
168
@ Override
204
- public Slice <T > findAll (Pageable pageable ) {
205
-
206
- Assert .notNull (pageable , "Pageable must not be null" );
207
-
208
- return this .operations .slice (Query .empty ().pageRequest (pageable ), this .entityInformation .getJavaType ());
169
+ public long count () {
170
+ return this .operations .count (this .entityInformation .getJavaType ());
209
171
}
210
172
211
173
/* (non-Javadoc)
@@ -231,16 +193,8 @@ public void delete(T entity) {
231
193
}
232
194
233
195
/* (non-Javadoc)
234
- * @see org.springframework.data.repository.CrudRepository#deleteAll (java.lang.Iterable)
196
+ * @see org.springframework.data.repository.CrudRepository#deleteAllById (java.lang.Iterable)
235
197
*/
236
- @ Override
237
- public void deleteAll (Iterable <? extends T > entities ) {
238
-
239
- Assert .notNull (entities , "The given Iterable of entities must not be null" );
240
-
241
- entities .forEach (this .operations ::delete );
242
- }
243
-
244
198
@ Override
245
199
public void deleteAllById (Iterable <? extends ID > ids ) {
246
200
@@ -253,6 +207,17 @@ public void deleteAllById(Iterable<? extends ID> ids) {
253
207
this .operations .delete (createIdsInQuery (ids ), this .entityInformation .getJavaType ());
254
208
}
255
209
210
+ /* (non-Javadoc)
211
+ * @see org.springframework.data.repository.CrudRepository#deleteAll(java.lang.Iterable)
212
+ */
213
+ @ Override
214
+ public void deleteAll (Iterable <? extends T > entities ) {
215
+
216
+ Assert .notNull (entities , "The given Iterable of entities must not be null" );
217
+
218
+ entities .forEach (this .operations ::delete );
219
+ }
220
+
256
221
/* (non-Javadoc)
257
222
* @see org.springframework.data.repository.CrudRepository#deleteAll()
258
223
*/
@@ -261,7 +226,51 @@ public void deleteAll() {
261
226
this .operations .truncate (this .entityInformation .getJavaType ());
262
227
}
263
228
229
+ // -------------------------------------------------------------------------
230
+ // Methods from CassandraRepository
231
+ // -------------------------------------------------------------------------
232
+
233
+ /* (non-Javadoc)
234
+ * @see org.springframework.data.cassandra.repository.CassandraRepository#findAll(org.springframework.data.domain.Pageable)
235
+ */
236
+ @ Override
237
+ public Slice <T > findAll (Pageable pageable ) {
238
+
239
+ Assert .notNull (pageable , "Pageable must not be null" );
240
+
241
+ return this .operations .slice (Query .empty ().pageRequest (pageable ), this .entityInformation .getJavaType ());
242
+ }
243
+
244
+ /* (non-Javadoc)
245
+ * @see org.springframework.data.cassandra.repository.TypedIdCassandraRepository#insert(java.lang.Object)
246
+ */
247
+ @ Override
248
+ public <S extends T > S insert (S entity ) {
249
+
250
+ Assert .notNull (entity , "Entity must not be null" );
251
+
252
+ return this .operations .insert (entity );
253
+ }
254
+
255
+ /* (non-Javadoc)
256
+ * @see org.springframework.data.cassandra.repository.TypedIdCassandraRepository#insert(java.lang.Iterable)
257
+ */
258
+ @ Override
259
+ public <S extends T > List <S > insert (Iterable <S > entities ) {
260
+
261
+ Assert .notNull (entities , "The given Iterable of entities must not be null" );
262
+
263
+ List <S > result = new ArrayList <>();
264
+
265
+ for (S entity : entities ) {
266
+ result .add (this .operations .insert (entity ));
267
+ }
268
+
269
+ return result ;
270
+ }
271
+
264
272
private Query createIdsInQuery (Iterable <? extends ID > ids ) {
273
+
265
274
FindByIdQuery mapIdQuery = FindByIdQuery .forIds (ids );
266
275
List <Object > idCollection = mapIdQuery .getIdCollection ();
267
276
String idField = mapIdQuery .getIdProperty ();
0 commit comments