@ThreadSafe
public class Box<T>
extends java.lang.Object
Thread-safe.
Modifier and Type | Method and Description |
---|---|
void |
attach(T entity) |
void |
closeThreadResources()
Like
BoxStore.closeThreadResources() , but limited to only this Box. |
boolean |
contains(long id)
Check if an object with the given ID exists in the database.
|
long |
count()
Returns the count of all stored objects in this box.
|
long |
count(long maxCount)
Returns the count of all stored objects in this box or the given maxCount, whichever is lower.
|
java.util.List<T> |
get(java.lang.Iterable<java.lang.Long> ids)
Get the stored objects for the given IDs.
|
T |
get(long id)
Get the stored object for the given ID.
|
java.util.List<T> |
get(long[] ids)
Get the stored objects for the given IDs.
|
java.util.List<T> |
getAll()
Returns all stored Objects in this Box.
|
java.lang.Class<T> |
getEntityClass() |
EntityInfo<T> |
getEntityInfo() |
long |
getId(T entity) |
java.util.Map<java.lang.Long,T> |
getMap(java.lang.Iterable<java.lang.Long> ids)
Get the stored objects for the given IDs as a Map with IDs as keys, and entities as values.
|
java.lang.String |
getReaderDebugInfo() |
java.util.List<T> |
getRelationBacklinkEntities(RelationInfo<T,?> relationInfo,
long id)
Given a ToMany relation and the ID of a target entity gets all source entities pointing to this target entity,
for example
customerBox.getRelationEntities(Customer_.orders, order.getId()) . |
long[] |
getRelationBacklinkIds(RelationInfo<T,?> relationInfo,
long id)
Like
getRelationBacklinkEntities(RelationInfo, long) , but only returns the IDs of the source entities. |
java.util.List<T> |
getRelationEntities(RelationInfo<?,T> relationInfo,
long id)
Given a ToMany relation and the ID of a source entity gets the target entities of the relation from their box,
for example
orderBox.getRelationEntities(Customer_.orders, customer.getId()) . |
long[] |
getRelationIds(RelationInfo<?,T> relationInfo,
long id)
Like
getRelationEntities(RelationInfo, long) , but only returns the IDs of the target entities. |
BoxStore |
getStore() |
<RESULT> RESULT |
internalCallWithReaderHandle(io.objectbox.internal.CallWithHandle<RESULT> task) |
<RESULT> RESULT |
internalCallWithWriterHandle(io.objectbox.internal.CallWithHandle<RESULT> task) |
java.util.List<T> |
internalGetBacklinkEntities(int entityId,
Property<?> relationIdProperty,
long key) |
java.util.List<T> |
internalGetRelationEntities(int sourceEntityId,
int relationId,
long key,
boolean backlink) |
long[] |
internalGetRelationIds(int sourceEntityId,
int relationId,
long key,
boolean backlink) |
boolean |
isEmpty()
Returns true if no objects are in this box.
|
long |
panicModeRemoveAll()
WARNING: this method should generally be avoided as it is not transactional and thus may leave the DB in an
inconsistent state.
|
void |
put(java.util.Collection<T> entities)
Puts the given entities in a box using a single transaction.
|
void |
put(T... entities)
Puts the given entities in a box using a single transaction.
|
long |
put(T entity)
Puts the given object in the box (aka persisting it).
|
void |
putBatched(java.util.Collection<T> entities,
int batchSize)
Puts the given entities in a box in batches using a separate transaction for each batch.
|
QueryBuilder<T> |
query()
Returns a builder to create queries for Object matching supplied criteria.
|
void |
remove(java.util.Collection<T> objects)
Removes (deletes) the given Objects in a single transaction.
|
void |
remove(long... ids)
Removes (deletes) Objects by their ID in a single transaction.
|
boolean |
remove(long id)
Removes (deletes) the Object by its ID.
|
void |
remove(T... objects)
Removes (deletes) the given Objects in a single transaction.
|
boolean |
remove(T object)
Removes (deletes) the given Object.
|
void |
removeAll()
Removes (deletes) ALL Objects in a single transaction.
|
void |
removeByIds(java.util.Collection<java.lang.Long> ids)
Due to type erasure collision, we cannot simply use "remove" as a method name here.
|
void |
removeByKeys(java.util.Collection<java.lang.Long> ids)
Deprecated.
use
removeByIds(Collection) instead. |
public void closeThreadResources()
BoxStore.closeThreadResources()
, but limited to only this Box.
Rule of thumb: prefer BoxStore.closeThreadResources()
unless you know that your thread only interacted
with this Box.
@Internal public long getId(T entity)
public T get(long id)
public java.util.List<T> get(java.lang.Iterable<java.lang.Long> ids)
public java.util.List<T> get(long[] ids)
public java.util.Map<java.lang.Long,T> getMap(java.lang.Iterable<java.lang.Long> ids)
public long count()
public long count(long maxCount)
maxCount
- maximum value to count or 0 (zero) to have no maximum limitpublic boolean isEmpty()
public java.util.List<T> getAll()
public boolean contains(long id)
get(long)
and comparing against null.public long put(T entity)
Performance note: if you want to put several entities, consider put(Collection)
,
put(Object[])
, BoxStore.runInTx(Runnable)
, etc. instead.
@SafeVarargs public final void put(@Nullable T... entities)
public void put(@Nullable java.util.Collection<T> entities)
entities
- It is fine to pass null or an empty collection:
this case is handled efficiently without overhead.public void putBatched(@Nullable java.util.Collection<T> entities, int batchSize)
entities
- It is fine to pass null or an empty collection:
this case is handled efficiently without overhead.batchSize
- Number of entities that will be put in one transaction. Must be 1 or greater.public boolean remove(long id)
public void remove(@Nullable long... ids)
@Deprecated public void removeByKeys(@Nullable java.util.Collection<java.lang.Long> ids)
removeByIds(Collection)
instead.public void removeByIds(@Nullable java.util.Collection<java.lang.Long> ids)
public boolean remove(T object)
@SafeVarargs public final void remove(@Nullable T... objects)
public void remove(@Nullable java.util.Collection<T> objects)
public void removeAll()
@Experimental public long panicModeRemoveAll()
public QueryBuilder<T> query()
public BoxStore getStore()
public EntityInfo<T> getEntityInfo()
@Beta public void attach(T entity)
public java.lang.Class<T> getEntityClass()
@Internal public java.util.List<T> internalGetBacklinkEntities(int entityId, Property<?> relationIdProperty, long key)
@Internal public java.util.List<T> internalGetRelationEntities(int sourceEntityId, int relationId, long key, boolean backlink)
@Internal public long[] internalGetRelationIds(int sourceEntityId, int relationId, long key, boolean backlink)
public java.util.List<T> getRelationEntities(RelationInfo<?,T> relationInfo, long id)
orderBox.getRelationEntities(Customer_.orders, customer.getId())
.public java.util.List<T> getRelationBacklinkEntities(RelationInfo<T,?> relationInfo, long id)
customerBox.getRelationEntities(Customer_.orders, order.getId())
.public long[] getRelationIds(RelationInfo<?,T> relationInfo, long id)
getRelationEntities(RelationInfo, long)
, but only returns the IDs of the target entities.public long[] getRelationBacklinkIds(RelationInfo<T,?> relationInfo, long id)
getRelationBacklinkEntities(RelationInfo, long)
, but only returns the IDs of the source entities.@Internal public <RESULT> RESULT internalCallWithReaderHandle(io.objectbox.internal.CallWithHandle<RESULT> task)
@Internal public <RESULT> RESULT internalCallWithWriterHandle(io.objectbox.internal.CallWithHandle<RESULT> task)
public java.lang.String getReaderDebugInfo()