Skip to content

Commit f61eb8b

Browse files
ToMany: update add, remove and get methods, note important details
1 parent 9886e98 commit f61eb8b

File tree

1 file changed

+19
-6
lines changed
  • objectbox-java/src/main/java/io/objectbox/relation

1 file changed

+19
-6
lines changed

objectbox-java/src/main/java/io/objectbox/relation/ToMany.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ private void ensureEntities() {
264264
}
265265

266266
/**
267-
* Adds the given entity to the list and tracks the addition so it can be later applied to the database
268-
* (e.g. via {@link Box#put(Object)} of the entity owning the ToMany, or via {@link #applyChangesToDb()}).
269-
* Note that the given entity will remain unchanged at this point (e.g. to-ones are not updated).
267+
* Prepares to add the given target object to this relation.
268+
* <p>
269+
* To apply changes, call {@link #applyChangesToDb()} or put the object with the ToMany. For important details, see
270+
* the notes about relations of {@link Box#put(Object)}.
270271
*/
271272
@Override
272273
public synchronized boolean add(TARGET object) {
@@ -367,8 +368,9 @@ public boolean containsAll(Collection<?> collection) {
367368
}
368369

369370
/**
370-
* @return An object for the given ID, or null if the object was already removed from its box
371-
* (and was not cached before).
371+
* Gets the target object at the given index.
372+
* <p>
373+
* {@link ToMany} uses lazy initialization, so on first access this will read the target objects from the database.
372374
*/
373375
@Override
374376
public TARGET get(int location) {
@@ -419,6 +421,9 @@ public ListIterator<TARGET> listIterator(int location) {
419421
return entities.listIterator(location);
420422
}
421423

424+
/**
425+
* Like {@link #remove(Object)}, but using the location of the target object.
426+
*/
422427
@Override
423428
public synchronized TARGET remove(int location) {
424429
ensureEntitiesWithTrackingLists();
@@ -427,6 +432,12 @@ public synchronized TARGET remove(int location) {
427432
return removed;
428433
}
429434

435+
/**
436+
* Prepares to remove the target object from this relation.
437+
* <p>
438+
* To apply changes, call {@link #applyChangesToDb()} or put the object with the ToMany. For important details, see
439+
* the notes about relations of {@link Box#put(Object)}.
440+
*/
430441
@SuppressWarnings("unchecked") // Cast to TARGET: If removed, must be of type TARGET.
431442
@Override
432443
public synchronized boolean remove(Object object) {
@@ -438,7 +449,9 @@ public synchronized boolean remove(Object object) {
438449
return removed;
439450
}
440451

441-
/** Removes an object by its entity ID. */
452+
/**
453+
* Like {@link #remove(Object)}, but using just the ID of the target object.
454+
*/
442455
public synchronized TARGET removeById(long id) {
443456
ensureEntities();
444457
int size = entities.size();

0 commit comments

Comments
 (0)