Package io.objectbox.relation
Class ToOne<TARGET>
- java.lang.Object
-
- io.objectbox.relation.ToOne<TARGET>
-
- All Implemented Interfaces:
java.io.Serializable
public class ToOne<TARGET> extends java.lang.Object implements java.io.Serializable
Manages a to-one relation: resolves the target object, keeps the target Id in sync, etc. A to-relation is unidirectional: it points from the source entity to the target entity. The target is referenced by its ID, which is persisted in the source entity.If there is a
ToMany
relation linking back to this to-one relation (@Backlink), the ToMany object will not be notified/updated about persisted changes here. CallToMany.reset()
so it will update when next accessed.- 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()
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)
Sets or clears the target entity and ID in the source entity.void
setTargetId(long targetId)
Sets or clears the target ID in the source entity.
-
-
-
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 entity of the to-one relation.
-
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)
Sets or clears the target ID in the source entity. Pass 0 to clear.Put the source entity to persist changes. If the ID is not 0 creates a relation to the target entity with this ID, otherwise dissolves it.
- See Also:
setTarget(TARGET)
-
setTarget
public void setTarget(@Nullable TARGET target)
Sets or clears the target entity and ID in the source entity. Pass null to clear.Put the source entity to persist changes. If the target entity was not put yet (its ID is 0), it will be stored when the source entity is put.
- 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
-
-