File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
objectbox-java/src/main/java/io/objectbox
tests/objectbox-java-test/src/test/java/io/objectbox Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -317,6 +317,20 @@ public List<T> getAll() {
317317 }
318318 }
319319
320+ /**
321+ * Check if an object with the given ID exists in the database.
322+ * @since 2.7
323+ * @return true if a object with the given ID was found, false otherwise
324+ */
325+ public boolean contains (long id ) {
326+ Cursor <T > reader = getReader ();
327+ try {
328+ return reader .seek (id );
329+ } finally {
330+ releaseReader (reader );
331+ }
332+ }
333+
320334 /**
321335 * Puts the given object in the box (aka persisting it). If this is a new entity (its ID property is 0), a new ID
322336 * will be assigned to the entity (and returned). If the entity was already put in the box before, it will be
Original file line number Diff line number Diff line change @@ -79,9 +79,11 @@ public void testPutGetUpdateGetRemove() {
7979 assertEquals (value2 , entityRead .getSimpleString ());
8080
8181 // and remove it
82+ assertTrue (box .contains (id ));
8283 assertTrue (box .remove (id ));
8384 assertNull (box .get (id ));
8485 assertFalse (box .remove (id ));
86+ assertFalse (box .contains (id ));
8587 }
8688
8789 @ Test
You can’t perform that action at this time.
0 commit comments