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 Details

    • sourceInfo

      public final EntityInfo<SOURCE> sourceInfo
    • targetInfo

      public final EntityInfo<TARGET> targetInfo
    • 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).
  • Constructor Details

  • Method Details

    • isBacklink

      public boolean isBacklink()
    • toString

      public String toString()
      Overrides:
      toString in class 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.