16
16
17
17
package com .jmethods .catatumbo ;
18
18
19
+ import java .lang .reflect .Type ;
19
20
import java .util .List ;
20
21
21
22
/**
@@ -31,7 +32,7 @@ public interface DatastoreBatch {
31
32
* Adds the given entity to this batch for insertion. If the entity does not have an identifier
32
33
* set, ID may be automatically generated. If the same entity was added to this batch for
33
34
* deletion, the insert request is changed into an upsert request.
34
- *
35
+ *
35
36
* @param entity
36
37
* the entity to insert.
37
38
* @return the inserted entity. The inserted entity may not be same as the passed in entity. For
@@ -41,6 +42,22 @@ public interface DatastoreBatch {
41
42
*/
42
43
<E > E insert (E entity );
43
44
45
+ /**
46
+ * Adds the given entity to this batch for insertion. If the entity does not have an identifier
47
+ * set, ID may be automatically generated. If the same entity was added to this batch for
48
+ * deletion, the insert request is changed into an upsert request.
49
+ *
50
+ * @param entity
51
+ * the entity to insert.
52
+ * @param entityType
53
+ * the entity type
54
+ * @return the inserted entity. The inserted entity may not be same as the passed in entity. For
55
+ * example, the inserted entity may contain any generated ID, key, parent key, etc.
56
+ * @throws EntityManagerException
57
+ * if any error occurs while inserting.
58
+ */
59
+ <E > E insert (E entity , Type entityType );
60
+
44
61
/**
45
62
* Adds the given entities to this batch for insertion. If any of the entities do not have an
46
63
* identifier set, ID may be generated automatically. If any of entities were added to this batch
@@ -55,6 +72,22 @@ public interface DatastoreBatch {
55
72
*/
56
73
<E > List <E > insert (List <E > entities );
57
74
75
+ /**
76
+ * Adds the given entities to this batch for insertion. If any of the entities do not have an
77
+ * identifier set, ID may be generated automatically. If any of entities were added to this batch
78
+ * for deletion, the insert request is changed to an upsert request.
79
+ *
80
+ * @param entities
81
+ * the entities to insert.
82
+ * @param entityType
83
+ * the entity type
84
+ * @return the inserted entities. The inserted entities may not be same as the passed in entities.
85
+ * For example, the inserted entities may contain generated ID, key, parent key, etc.
86
+ * @throws EntityManagerException
87
+ * if any error occurs while inserting.
88
+ */
89
+ <E > List <E > insert (List <E > entities , Type entityType );
90
+
58
91
/**
59
92
* Adds the given entity to this batch for insertion. The ID allocation is deferred to the submit
60
93
* time of this batch. Generated keys can be retrieved using
@@ -70,6 +103,23 @@ public interface DatastoreBatch {
70
103
*/
71
104
<E > void insertWithDeferredIdAllocation (E entity );
72
105
106
+ /**
107
+ * Adds the given entity to this batch for insertion. The ID allocation is deferred to the submit
108
+ * time of this batch. Generated keys can be retrieved using
109
+ * {@link DatastoreBatch.Response#getGeneratedKeys()}.This method throws
110
+ * {@link EntityManagerException} if the entity is using a String identifier. String identifiers
111
+ * are allocated at add time, instead of submit time. For entities with String identifiers, use
112
+ * the {@link DatastoreBatch#insert(Object)} method.
113
+ *
114
+ * @param entity
115
+ * the entity to insert
116
+ * @param entityType
117
+ * the entity type
118
+ * @throws EntityManagerException
119
+ * if the entity has a String identifier or if any error occurs
120
+ */
121
+ <E > void insertWithDeferredIdAllocation (E entity , Type entityType );
122
+
73
123
/**
74
124
* Adds the given entities to this batch for insertion. The ID allocation is deferred to the
75
125
* submit time of this batch. Generated keys can be retrieved using
@@ -85,6 +135,23 @@ public interface DatastoreBatch {
85
135
*/
86
136
<E > void insertWithDeferredIdAllocation (List <E > entities );
87
137
138
+ /**
139
+ * Adds the given entities to this batch for insertion. The ID allocation is deferred to the
140
+ * submit time of this batch. Generated keys can be retrieved using
141
+ * {@link DatastoreBatch.Response#getGeneratedKeys()}.This method throws
142
+ * {@link EntityManagerException} if the entity is using a String identifier. String identifiers
143
+ * are allocated at add time, instead of submit time. For entities with String identifiers, use
144
+ * the {@link DatastoreBatch#insert(List)} method.
145
+ *
146
+ * @param entities
147
+ * the entities to insert
148
+ * @param entityType
149
+ * the entity type
150
+ * @throws EntityManagerException
151
+ * if the entity have a String identifier any error occurs
152
+ */
153
+ <E > void insertWithDeferredIdAllocation (List <E > entities , Type entityType );
154
+
88
155
/**
89
156
* Adds the given entity to this batch for update. The operation will fail if the entity with the
90
157
* same key does not exist in the underlying Datastore. This method does not use optimistic
@@ -98,6 +165,21 @@ public interface DatastoreBatch {
98
165
*/
99
166
<E > E update (E entity );
100
167
168
+ /**
169
+ * Adds the given entity to this batch for update. The operation will fail if the entity with the
170
+ * same key does not exist in the underlying Datastore. This method does not use optimistic
171
+ * locking even if the given entity has a field with {@link Version} annotation.
172
+ *
173
+ * @param entity
174
+ * the entity to update
175
+ * @param entityType
176
+ * the entity type
177
+ * @return the updated entity.
178
+ * @throws EntityManagerException
179
+ * if any error occurs while updating.
180
+ */
181
+ <E > E update (E entity , Type entityType );
182
+
101
183
/**
102
184
* Adds the given entities to this batch for update. The operation will fail if the entities with
103
185
* the same key do not already exist in the underlying datastore. This method does not use
@@ -112,6 +194,22 @@ public interface DatastoreBatch {
112
194
*/
113
195
<E > List <E > update (List <E > entities );
114
196
197
+ /**
198
+ * Adds the given entities to this batch for update. The operation will fail if the entities with
199
+ * the same key do not already exist in the underlying datastore. This method does not use
200
+ * optimistic locking even if the given entity has a field with {@link Version} annotation.
201
+ *
202
+ *
203
+ * @param entities
204
+ * the entities to update.
205
+ * @param entityType
206
+ * the entity type
207
+ * @return the updated entities
208
+ * @throws EntityManagerException
209
+ * if any error occurs while inserting.
210
+ */
211
+ <E > List <E > update (List <E > entities , Type entityType );
212
+
115
213
/**
116
214
* Adds the given entity to this batch for update or insert. Any prior writes to this entity in
117
215
* this batch will be removed from this batch. If the entity does not have an ID set, ID may be
@@ -125,6 +223,21 @@ public interface DatastoreBatch {
125
223
*/
126
224
<E > E upsert (E entity );
127
225
226
+ /**
227
+ * Adds the given entity to this batch for update or insert. Any prior writes to this entity in
228
+ * this batch will be removed from this batch. If the entity does not have an ID set, ID may be
229
+ * generated automatically.
230
+ *
231
+ * @param entity
232
+ * the entity to update or insert
233
+ * @param entityType
234
+ * the entity type
235
+ * @return the updated/inserted entity.
236
+ * @throws EntityManagerException
237
+ * if any error occurs while saving.
238
+ */
239
+ <E > E upsert (E entity , Type entityType );
240
+
128
241
/**
129
242
* Adds the given entities to this batch for update or insert. Any prior writes of any of the
130
243
* entities will be removed from this batch. If any of the entities do not have their IDs set, IDs
@@ -138,6 +251,21 @@ public interface DatastoreBatch {
138
251
*/
139
252
<E > List <E > upsert (List <E > entities );
140
253
254
+ /**
255
+ * Adds the given entities to this batch for update or insert. Any prior writes of any of the
256
+ * entities will be removed from this batch. If any of the entities do not have their IDs set, IDs
257
+ * may be generated automatically.
258
+ *
259
+ * @param entities
260
+ * the entities to update/or insert.
261
+ * @param entityType
262
+ * the entity type
263
+ * @return the updated or inserted entities
264
+ * @throws EntityManagerException
265
+ * if any error occurs while saving.
266
+ */
267
+ <E > List <E > upsert (List <E > entities , Type entityType );
268
+
141
269
/**
142
270
* Adds the given entity to this batch for insert or update. The ID (for numeric ID) allocation
143
271
* will be deferred to the submit time of this batch. This method throws an
@@ -152,6 +280,22 @@ public interface DatastoreBatch {
152
280
*/
153
281
<E > void upsertWithDeferredIdAllocation (E entity );
154
282
283
+ /**
284
+ * Adds the given entity to this batch for insert or update. The ID (for numeric ID) allocation
285
+ * will be deferred to the submit time of this batch. This method throws an
286
+ * {@link EntityManagerException} if the entity is using a String ID. Entity with String ID should
287
+ * use {@link DatastoreBatch#upsert(Object)} method.
288
+ *
289
+ * @param entity
290
+ * the entity to update or insert
291
+ * @param entityType
292
+ * the entity type
293
+ * @throws EntityManagerException
294
+ * if the entity has a String ID or any other error occurs while accessing the
295
+ * underlying datastore.
296
+ */
297
+ <E > void upsertWithDeferredIdAllocation (E entity , Type entityType );
298
+
155
299
/**
156
300
* Adds the given entities to this batch for update or insert. The ID (for numeric ID) allocation
157
301
* will be deferred to the submit time of this batch. This method throws an
@@ -166,6 +310,22 @@ public interface DatastoreBatch {
166
310
*/
167
311
<E > void upsertWithDeferredIdAllocation (List <E > entities );
168
312
313
+ /**
314
+ * Adds the given entities to this batch for update or insert. The ID (for numeric ID) allocation
315
+ * will be deferred to the submit time of this batch. This method throws an
316
+ * {@link EntityManagerException} if the entities have String identifiers. Entities with String
317
+ * identifiers should use {@link DatastoreBatch#upsert(List)} method.
318
+ *
319
+ * @param entities
320
+ * the entities to update or insert
321
+ * @param entityType
322
+ * the entity type
323
+ * @throws EntityManagerException
324
+ * if the entities have String identifiers or any other error occurs while accessing the
325
+ * underlying datastore.
326
+ */
327
+ <E > void upsertWithDeferredIdAllocation (List <E > entities , Type entityType );
328
+
169
329
/**
170
330
* Adds the given entity to this batch for deletion.
171
331
*
@@ -176,6 +336,18 @@ public interface DatastoreBatch {
176
336
*/
177
337
void delete (Object entity );
178
338
339
+ /**
340
+ * Adds the given entity to this batch for deletion.
341
+ *
342
+ * @param entity
343
+ * the entity to delete.
344
+ * @param entityType
345
+ * the entity type
346
+ * @throws EntityManagerException
347
+ * if any error occurs while deleting.
348
+ */
349
+ void delete (Object entity , Type entityType );
350
+
179
351
/**
180
352
* Adds the given entities to this batch for deletion.
181
353
*
@@ -186,57 +358,69 @@ public interface DatastoreBatch {
186
358
*/
187
359
void delete (List <?> entities );
188
360
361
+ /**
362
+ * Adds the given entities to this batch for deletion.
363
+ *
364
+ * @param entities
365
+ * the entities to delete.
366
+ * @param entityType
367
+ * the entity type
368
+ * @throws EntityManagerException
369
+ * if any error occurs while deleting.
370
+ */
371
+ void delete (List <?> entities , Type entityType );
372
+
189
373
/**
190
374
* Adds the given ID and entity type to this batch for deletion.
191
375
*
192
- * @param entityClass
193
- * the entity class .
376
+ * @param entityType
377
+ * the entity type .
194
378
* @param id
195
379
* the ID of the entity.
196
380
* @throws EntityManagerException
197
381
* if any error occurs while inserting.
198
382
*/
199
- <E > void delete (Class < E > entityClass , long id );
383
+ <E > void delete (Type entityType , long id );
200
384
201
385
/**
202
386
* Adds the given ID and entity type to this batch for deletion.
203
387
*
204
- * @param entityClass
205
- * the entity class .
388
+ * @param entityType
389
+ * the entity type .
206
390
* @param id
207
391
* the ID of the entity.
208
392
* @throws EntityManagerException
209
393
* if any error occurs while inserting.
210
394
*/
211
- <E > void delete (Class < E > entityClass , String id );
395
+ <E > void delete (Type entityType , String id );
212
396
213
397
/**
214
398
* Adds the given entity type, parent key and ID to this batch for deletion.
215
399
*
216
- * @param entityClass
217
- * the entity class .
400
+ * @param entityType
401
+ * the entity type .
218
402
* @param parentKey
219
403
* the parent key
220
404
* @param id
221
405
* the ID of the entity.
222
406
* @throws EntityManagerException
223
407
* if any error occurs while inserting.
224
408
*/
225
- <E > void delete (Class < E > entityClass , DatastoreKey parentKey , long id );
409
+ <E > void delete (Type entityType , DatastoreKey parentKey , long id );
226
410
227
411
/**
228
412
* Adds the given entity type, parent key and ID to this batch for deletion.
229
413
*
230
- * @param entityClass
231
- * the entity class .
414
+ * @param entityType
415
+ * the entity type .
232
416
* @param parentKey
233
417
* the parent key
234
418
* @param id
235
419
* the ID of the entity.
236
420
* @throws EntityManagerException
237
421
* if any error occurs while inserting.
238
422
*/
239
- <E > void delete (Class < E > entityClass , DatastoreKey parentKey , String id );
423
+ <E > void delete (Type entityType , DatastoreKey parentKey , String id );
240
424
241
425
/**
242
426
* Adds the given key to this batch for deletion.
@@ -250,7 +434,7 @@ public interface DatastoreBatch {
250
434
251
435
/**
252
436
* Adds the given keys to this batch for deletion.
253
- *
437
+ *
254
438
* @param keys
255
439
* the keys to delete
256
440
* @throws EntityManagerException
0 commit comments