public static <T> void commitWriter(Box<T> box, Cursor<T> writer) { box.commitWriter(writer); }
/** * Due to type erasure collision, we cannot simply use "remove" as a method name here. */ public void removeByKeys(@Nullable Collection<Long> ids) { if (ids == null || ids.isEmpty()) { return; } Cursor<T> cursor = getWriter(); try { for (long key : ids) { cursor.deleteEntity(key); } commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * 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. */ public void put(@Nullable Collection<T> entities) { if (entities == null || entities.isEmpty()) { return; } Cursor<T> cursor = getWriter(); try { for (T entity : entities) { cursor.put(entity); } commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * Puts the given entities in a box using a single transaction. */ public void put(@Nullable T... entities) { if (entities == null || entities.length == 0) { return; } Cursor<T> cursor = getWriter(); try { for (T entity : entities) { cursor.put(entity); } commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * Removes (deletes) Objects by their ID in a single transaction. */ public void remove(@Nullable long... ids) { if (ids == null || ids.length == 0) { return; } Cursor<T> cursor = getWriter(); try { for (long key : ids) { cursor.deleteEntity(key); } commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * Removes (deletes) ALL Objects in a single transaction. */ public void removeAll() { Cursor<T> cursor = getWriter(); try { cursor.deleteAll(); commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * Removes (deletes) the Object by its ID. */ public void remove(long id) { Cursor<T> cursor = getWriter(); try { cursor.deleteEntity(id); commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * Removes (deletes) the given Objects in a single transaction. */ @SuppressWarnings("Duplicates") // Detected duplicate has different type public void remove(@Nullable Collection<T> objects) { if (objects == null || objects.isEmpty()) { return; } Cursor<T> cursor = getWriter(); try { for (T entity : objects) { long key = cursor.getId(entity); cursor.deleteEntity(key); } commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * Puts the given object in the box (aka persisting it). If this is a new entity (its ID property is 0), a new ID * will be assigned to the entity (and returned). If the entity was already put in the box before, it will be * overwritten. * <p> * Performance note: if you want to put several entities, consider {@link #put(Collection)}, * {@link #put(Object[])}, {@link BoxStore#runInTx(Runnable)}, etc. instead. */ public long put(T entity) { Cursor<T> cursor = getWriter(); try { long key = cursor.put(entity); commitWriter(cursor); return key; } finally { releaseWriter(cursor); } }
/** * Removes (deletes) the given Objects in a single transaction. */ @SuppressWarnings("Duplicates") // Detected duplicate has different type public void remove(@Nullable T... objects) { if (objects == null || objects.length == 0) { return; } Cursor<T> cursor = getWriter(); try { for (T entity : objects) { long key = cursor.getId(entity); cursor.deleteEntity(key); } commitWriter(cursor); } finally { releaseWriter(cursor); } }
/** * Removes (deletes) the given Object. */ public void remove(T object) { Cursor<T> cursor = getWriter(); try { long key = cursor.getId(object); cursor.deleteEntity(key); commitWriter(cursor); } finally { releaseWriter(cursor); } }
@Internal public <RESULT> RESULT internalCallWithWriterHandle(CallWithHandle<RESULT> task) { Cursor<T> writer = getWriter(); RESULT result; try { result = task.call(writer.internalHandle()); commitWriter(writer); } finally { releaseWriter(writer); } return result; }