Skip to content

Commit 5e9c816

Browse files
committed
feat: java
1 parent fa8460c commit 5e9c816

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

templates/java/api_helpers.mustache

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,24 @@ String indexName,
641641
Iterable<T> objects,
642642
RequestOptions requestOptions
643643
) {
644-
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, false, 1000, requestOptions);
644+
return saveObjects(indexName, objects, false, requestOptions);
645+
}
646+
647+
/**
648+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
649+
*
650+
* @param indexName The `indexName` to replace `objects` in.
651+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
652+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
653+
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
654+
*/
655+
public <T> List<BatchResponse> saveObjects(
656+
String indexName,
657+
Iterable<T> objects,
658+
boolean waitForTasks,
659+
RequestOptions requestOptions
660+
) {
661+
return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, 1000, requestOptions);
645662
}
646663
647664
/**
@@ -654,7 +671,7 @@ public List<BatchResponse> deleteObjects(
654671
String indexName,
655672
List<String> objectIDs
656673
) {
657-
return deleteObjects(indexName, objectIDs, null);
674+
return deleteObjects(indexName, objectIDs, false, null);
658675
}
659676
660677
/**
@@ -669,6 +686,23 @@ String indexName,
669686
List<String> objectIDs,
670687
RequestOptions requestOptions
671688
) {
689+
return deleteObjects(indexName, objectIDs, false, null);
690+
}
691+
692+
/**
693+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
694+
*
695+
* @param indexName The `indexName` to delete `objectIDs` from.
696+
* @param objectIDs The array of `objectIDs` to delete from the `indexName`.
697+
* @param waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable.
698+
* @param requestOptions The requestOptions to send along with the query, they will be merged with the transporter requestOptions. (optional)
699+
*/
700+
public List<BatchResponse> deleteObjects(
701+
String indexName,
702+
List<String> objectIDs,
703+
boolean waitForTasks,
704+
RequestOptions requestOptions
705+
) {
672706
List<Map<String, String>> objects = new ArrayList<>();
673707
674708
for (String id : objectIDs) {
@@ -677,7 +711,7 @@ for (String id : objectIDs) {
677711
objects.add(obj);
678712
}
679713
680-
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, false, 1000, requestOptions);
714+
return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, 1000, requestOptions);
681715
}
682716
683717
/**

0 commit comments

Comments
 (0)