Class RelationInfo<SOURCE,​TARGET>

  • All Implemented Interfaces:
    java.io.Serializable

    @Internal
    @Immutable
    public class RelationInfo<SOURCE,​TARGET>
    extends java.lang.Object
    implements java.io.Serializable
    Meta info describing a relation including source and target entity.
    See Also:
    Serialized Form
    • Field Detail

      • targetIdProperty

        public final Property<?> targetIdProperty
        For relations based on a target ID property (null otherwise).
      • targetRelationId

        public final int targetRelationId
        For ToMany relations based on ToMany backlinks (0 otherwise).
      • toOneGetter

        public final io.objectbox.internal.ToOneGetter<SOURCE,​TARGET> toOneGetter
        Only set for ToOne relations
      • toManyGetter

        public final io.objectbox.internal.ToManyGetter<SOURCE,​TARGET> toManyGetter
        Only set for ToMany relations
      • backlinkToOneGetter

        public final io.objectbox.internal.ToOneGetter<TARGET,​SOURCE> backlinkToOneGetter
        For ToMany relations based on ToOne backlinks (null otherwise).
      • backlinkToManyGetter

        public final io.objectbox.internal.ToManyGetter<TARGET,​SOURCE> backlinkToManyGetter
        For ToMany relations based on ToMany backlinks (null otherwise).
      • relationId

        public final int relationId
        For stand-alone to-many relations (0 otherwise).
    • Method Detail

      • isBacklink

        public boolean isBacklink()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • relationCount

        public QueryCondition<SOURCE> relationCount​(int relationCount)
        Creates a condition to match objects that have relationCount 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.