Package io.objectbox.relation
Class RelationInfo<SOURCE,TARGET>
java.lang.Object
io.objectbox.relation.RelationInfo<SOURCE,TARGET>
- All Implemented Interfaces:
Serializable
@Internal
@Immutable
public class RelationInfo<SOURCE,TARGET>
extends Object
implements Serializable
Meta info describing a relation including source and target entity.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionFor ToMany relations based on ToMany backlinks (null otherwise).For ToMany relations based on ToOne backlinks (null otherwise).final int
For stand-alone to-many relations (0 otherwise).final EntityInfo<SOURCE>
final Property<?>
For relations based on a target ID property (null otherwise).final EntityInfo<TARGET>
final int
For ToMany relations based on ToMany backlinks (0 otherwise).Only set for ToMany relationsOnly set for ToOne relations -
Constructor Summary
ConstructorsConstructorDescriptionRelationInfo
(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, io.objectbox.internal.ToManyGetter<SOURCE, TARGET> toManyGetter, int relationId) Stand-alone ToMany.RelationInfo
(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, io.objectbox.internal.ToManyGetter<SOURCE, TARGET> toManyGetter, io.objectbox.internal.ToManyGetter<TARGET, SOURCE> backlinkToManyGetter, int targetRelationId) ToMany as a ToMany backlinkRelationInfo
(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, io.objectbox.internal.ToManyGetter<SOURCE, TARGET> toManyGetter, Property<TARGET> targetIdProperty, io.objectbox.internal.ToOneGetter<TARGET, SOURCE> backlinkToOneGetter) ToMany as a ToOne backlinkRelationInfo
(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, Property<SOURCE> targetIdProperty, io.objectbox.internal.ToOneGetter<SOURCE, TARGET> toOneGetter) ToOne -
Method Summary
Modifier and TypeMethodDescriptionboolean
relationCount
(int relationCount) Creates a condition to match objects that haverelationCount
related objects pointing to them.toString()
-
Field Details
-
sourceInfo
-
targetInfo
-
targetIdProperty
For relations based on a target ID property (null otherwise). -
targetRelationId
public final int targetRelationIdFor ToMany relations based on ToMany backlinks (0 otherwise). -
toOneGetter
Only set for ToOne relations -
toManyGetter
Only set for ToMany relations -
backlinkToOneGetter
For ToMany relations based on ToOne backlinks (null otherwise). -
backlinkToManyGetter
For ToMany relations based on ToMany backlinks (null otherwise). -
relationId
public final int relationIdFor stand-alone to-many relations (0 otherwise).
-
-
Constructor Details
-
RelationInfo
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, Property<SOURCE> targetIdProperty, io.objectbox.internal.ToOneGetter<SOURCE, TARGET> toOneGetter) ToOne -
RelationInfo
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, io.objectbox.internal.ToManyGetter<SOURCE, TARGET> toManyGetter, Property<TARGET> targetIdProperty, io.objectbox.internal.ToOneGetter<TARGET, SOURCE> backlinkToOneGetter) ToMany as a ToOne backlink -
RelationInfo
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, io.objectbox.internal.ToManyGetter<SOURCE, TARGET> toManyGetter, io.objectbox.internal.ToManyGetter<TARGET, SOURCE> backlinkToManyGetter, int targetRelationId) ToMany as a ToMany backlink -
RelationInfo
public RelationInfo(EntityInfo<SOURCE> sourceInfo, EntityInfo<TARGET> targetInfo, io.objectbox.internal.ToManyGetter<SOURCE, TARGET> toManyGetter, int relationId) Stand-alone ToMany.
-
-
Method Details
-
isBacklink
public boolean isBacklink() -
toString
-
relationCount
Creates a condition to match objects that haverelationCount
related objects pointing to them.try (Query<Customer> query = customerBox .query(Customer_.orders.relationCount(2)) .build()) { List<Customer> customersWithTwoOrders = query.find(); }
relationCount
may be 0 to match objects that do not have related objects. It typically should be a low number.This condition has some limitations:
- only 1:N (ToMany using @Backlink) relations are supported,
- the complexity is
O(n * (relationCount + 1))
and cannot be improved via indexes, - the relation count cannot be changed with setParameter once the query is built.
-