Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions objectbox-java/src/main/java/io/objectbox/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,34 @@ public void put(@Nullable Collection<T> entities) {
}
}

/**
* Puts the given entities in a box using a single transaction.
*
* @param entities It is fine to pass null or an empty collection:
* this case is handled efficiently without overhead.
*
* @return list of saved entities ids
*/
public Collection<Long> putAndGetIds(@Nullable Collection<T> entities) {
if (entities == null || entities.isEmpty()) {
return Collections.emptyList();
}

Collection<Long> ids = new ArrayList<>();
Cursor<T> cursor = getWriter();
try {
for (T entity : entities) {
ids.add(cursor.put(entity));
}
commitWriter(cursor);
} catch (Exception e) {
ids = Collections.emptyList();
} finally {
releaseWriter(cursor);
}
return ids;
}

/**
* Removes (deletes) the Object by its ID.
*/
Expand Down