Package io.objectbox.relation
Class ToOne<TARGET>
- java.lang.Object
-
- io.objectbox.relation.ToOne<TARGET>
-
- Type Parameters:
TARGET
- target object type (@Entity
class).
- All Implemented Interfaces:
java.io.Serializable
public class ToOne<TARGET> extends java.lang.Object implements java.io.Serializable
A to-one relation of an entity that references one object of aToOne
entity.Example:
{@code // Java
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ToOne(java.lang.Object sourceEntity, RelationInfo<?,TARGET> relationInfo)
In Java, the constructor call is generated by the ObjectBox plugin.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
TARGET
getCachedTarget()
TARGET
getTarget()
Returns the target object ornull
if there is none.TARGET
getTarget(long targetId)
If property backed, entities can pass the target ID to avoid reflection.long
getTargetId()
int
hashCode()
void
internalPutTarget(io.objectbox.Cursor<TARGET> targetCursor)
boolean
internalRequiresPutTarget()
boolean
isNull()
boolean
isResolved()
boolean
isResolvedAndNotNull()
void
setAndPutTarget(TARGET target)
Sets or clears the target entity and ID in the source entity, then puts the source entity to persist changes.void
setAndPutTargetAlways(TARGET target)
Sets or clears the target entity and ID in the source entity, then puts the target (if not null) and source entity to persist changes.void
setTarget(TARGET target)
Prepares to set the target object of this relation.void
setTargetId(long targetId)
Prepares to set the target of this relation to the object with the given ID.
-
-
-
Constructor Detail
-
ToOne
public ToOne(java.lang.Object sourceEntity, RelationInfo<?,TARGET> relationInfo)
In Java, the constructor call is generated by the ObjectBox plugin.- Parameters:
sourceEntity
- The source entity that owns the to-one relation.relationInfo
- Meta info as generated in the Entity_ (entity name plus underscore) classes.
-
-
Method Detail
-
getTarget
public TARGET getTarget()
Returns the target object ornull
if there is none.ToOne
uses lazy initialization, so on first access this will read the target object from the database.
-
getTarget
@Internal public TARGET getTarget(long targetId)
If property backed, entities can pass the target ID to avoid reflection.
-
getCachedTarget
public TARGET getCachedTarget()
-
isResolved
public boolean isResolved()
-
isResolvedAndNotNull
public boolean isResolvedAndNotNull()
-
isNull
public boolean isNull()
-
setTargetId
public void setTargetId(long targetId)
Prepares to set the target of this relation to the object with the given ID. Pass0
to remove an existing one.To apply changes, put the object with the ToOne. For important details, see the notes about relations of
Box.put(Object)
.- See Also:
setTarget(TARGET)
-
setTarget
public void setTarget(@Nullable TARGET target)
Prepares to set the target object of this relation. Passnull
to remove an existing one.To apply changes, put the object with the ToOne. For important details, see the notes about relations of
Box.put(Object)
.- See Also:
setTargetId(long)
-
setAndPutTarget
public void setAndPutTarget(@Nullable TARGET target)
Sets or clears the target entity and ID in the source entity, then puts the source entity to persist changes. Pass null to clear.If the target entity was not put yet (its ID is 0), it will be put before the source entity.
-
setAndPutTargetAlways
public void setAndPutTargetAlways(@Nullable TARGET target)
Sets or clears the target entity and ID in the source entity, then puts the target (if not null) and source entity to persist changes. Pass null to clear.When clearing the target entity, this does not remove it from its box. This only dissolves the relation.
-
getTargetId
public long getTargetId()
-
internalRequiresPutTarget
@Internal public boolean internalRequiresPutTarget()
-
internalPutTarget
@Internal public void internalPutTarget(io.objectbox.Cursor<TARGET> targetCursor)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-