Package io.objectbox.relation
Class ToOne<TARGET>
java.lang.Object
io.objectbox.relation.ToOne<TARGET>
- All Implemented Interfaces:
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.
Call ToMany.reset()
so it will update when next accessed.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionToOne
(Object sourceEntity, RelationInfo<?, TARGET> relationInfo) In Java, the constructor call is generated by the ObjectBox plugin. -
Method Summary
Modifier and TypeMethodDescriptionboolean
getTarget
(long targetId) If property backed, entities can pass the target ID to avoid reflection.long
int
hashCode()
void
internalPutTarget
(io.objectbox.Cursor<TARGET> targetCursor) boolean
boolean
isNull()
boolean
boolean
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
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 Details
-
ToOne
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 Details
-
getTarget
- Returns:
- The target entity of the to-one relation.
-
getTarget
If property backed, entities can pass the target ID to avoid reflection. -
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
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:
-
setAndPutTarget
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
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
-
equals
-
hashCode
public int hashCode()
-