2828import javax .annotation .Nullable ;
2929import javax .annotation .concurrent .ThreadSafe ;
3030
31+ import io .objectbox .annotation .Id ;
3132import io .objectbox .annotation .apihint .Beta ;
3233import io .objectbox .annotation .apihint .Experimental ;
3334import io .objectbox .annotation .apihint .Internal ;
3839import io .objectbox .query .QueryBuilder ;
3940import io .objectbox .query .QueryCondition ;
4041import io .objectbox .relation .RelationInfo ;
42+ import io .objectbox .relation .ToMany ;
43+ import io .objectbox .relation .ToOne ;
4144
4245/**
4346 * A Box to put and get Objects of a specific Entity class.
@@ -335,11 +338,24 @@ public boolean contains(long id) {
335338 }
336339
337340 /**
338- * Puts the given object in the box (aka persisting it). If this is a new entity (its ID property is 0), a new ID
339- * will be assigned to the entity (and returned). If the entity was already put in the box before, it will be
340- * overwritten.
341+ * Puts the given object and returns its (new) ID.
341342 * <p>
342- * Performance note: if you want to put several entities, consider {@link #put(Collection)},
343+ * This means that if its {@link Id @Id} property is 0 or null, it is inserted as a new object and assigned the next
344+ * available ID. For example, if there is an object with ID 1 and another with ID 100, it will be assigned ID 101.
345+ * The new ID is also set on the given object before this returns.
346+ * <p>
347+ * If instead the object has an assigned ID set, if an object with the same ID exists it will be updated.
348+ * Otherwise, it will be inserted with that ID.
349+ * <p>
350+ * If the ID was not assigned before an {@link IllegalArgumentException} is thrown.
351+ * <p>
352+ * When the object contains {@link ToOne} or {@link ToMany} relations, they are created (or updated) to point to the
353+ * (new) target objects.
354+ * The target objects themselves are not updated or removed. To do so, put or remove them using their box.
355+ * However, for convenience, if a target object is new, it will be inserted and assigned an ID in its box before
356+ * creating or updating the relation.
357+ * <p>
358+ * Performance note: if you want to put several objects, consider {@link #put(Collection)},
343359 * {@link #put(Object[])}, {@link BoxStore#runInTx(Runnable)}, etc. instead.
344360 */
345361 public long put (T entity ) {
@@ -432,9 +448,11 @@ public void putBatched(@Nullable Collection<T> entities, int batchSize) {
432448 }
433449
434450 /**
435- * Removes (deletes) the Object by its ID.
451+ * Removes (deletes) the object with the given ID.
452+ * <p>
453+ * If the object is part of a relation, it will be removed from that relation as well.
436454 *
437- * @return true if an entity was actually removed (false if no entity exists with the given ID)
455+ * @return true if the object did exist and was removed, otherwise false.
438456 */
439457 public boolean remove (long id ) {
440458 Cursor <T > cursor = getWriter ();
@@ -449,7 +467,7 @@ public boolean remove(long id) {
449467 }
450468
451469 /**
452- * Removes (deletes) Objects by their ID in a single transaction.
470+ * Like {@link #remove(long)}, but removes multiple objects in a single transaction.
453471 */
454472 public void remove (@ Nullable long ... ids ) {
455473 if (ids == null || ids .length == 0 ) {
@@ -476,7 +494,7 @@ public void removeByKeys(@Nullable Collection<Long> ids) {
476494 }
477495
478496 /**
479- * Due to type erasure collision, we cannot simply use "remove" as a method name here .
497+ * Like {@link #remove(long)}, but removes multiple objects in a single transaction .
480498 */
481499 public void removeByIds (@ Nullable Collection <Long > ids ) {
482500 if (ids == null || ids .isEmpty ()) {
@@ -494,9 +512,7 @@ public void removeByIds(@Nullable Collection<Long> ids) {
494512 }
495513
496514 /**
497- * Removes (deletes) the given Object.
498- *
499- * @return true if an entity was actually removed (false if no entity exists with the given ID)
515+ * Like {@link #remove(long)}, but obtains the ID from the {@link Id @Id} property of the given object instead.
500516 */
501517 public boolean remove (T object ) {
502518 Cursor <T > cursor = getWriter ();
@@ -512,7 +528,7 @@ public boolean remove(T object) {
512528 }
513529
514530 /**
515- * Removes (deletes) the given Objects in a single transaction.
531+ * Like {@link #remove(Object)}, but removes multiple objects in a single transaction.
516532 */
517533 @ SafeVarargs // Not using T... as Object[], no ClassCastException expected.
518534 @ SuppressWarnings ("Duplicates" ) // Detected duplicate has different type
@@ -533,7 +549,7 @@ public final void remove(@Nullable T... objects) {
533549 }
534550
535551 /**
536- * Removes (deletes) the given Objects in a single transaction.
552+ * Like {@link #remove(Object)}, but removes multiple objects in a single transaction.
537553 */
538554 @ SuppressWarnings ("Duplicates" ) // Detected duplicate has different type
539555 public void remove (@ Nullable Collection <T > objects ) {
@@ -553,7 +569,7 @@ public void remove(@Nullable Collection<T> objects) {
553569 }
554570
555571 /**
556- * Removes (deletes) ALL Objects in a single transaction.
572+ * Like {@link #remove(long)}, but removes <b>all</b> objects in a single transaction.
557573 */
558574 public void removeAll () {
559575 Cursor <T > cursor = getWriter ();
0 commit comments