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() {
317
317
}
318
318
}
319
319
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
+
320
334
/**
321
335
* Puts the given object in the box (aka persisting it). If this is a new entity (its ID property is 0), a new ID
322
336
* 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() {
79
79
assertEquals (value2 , entityRead .getSimpleString ());
80
80
81
81
// and remove it
82
+ assertTrue (box .contains (id ));
82
83
assertTrue (box .remove (id ));
83
84
assertNull (box .get (id ));
84
85
assertFalse (box .remove (id ));
86
+ assertFalse (box .contains (id ));
85
87
}
86
88
87
89
@ Test
You can’t perform that action at this time.
0 commit comments